This repository contains the Python Flask application supporting the Usint Website.
For information related to the web server backend, support, and development of this application, consult the Flask/Usint folder in the MTA shared drive.
This is the server process startup command, running under Syshelp control, using the usint.py entrypoint. https://flask.palletsprojects.com/en/stable/deploying/gunicorn/#running
gunicorn -c <server_config_name>.conf.py usint:application
The gunicorn server configuration file handles settings to allow the cxc web servers to send requests to the application server. Flask application specific settings, such as database connections and email settings, exists as flask config files, and thus within MTA file ownership.
In this context, installation is a loose term in which the USINT admin updates/edits the application root directory so that it contains the application source code.
An application root directory should contain the following files from the Github Repo.
The file copies can also be performed by using the install.sh bash script using predetermined application roots.
- cli
- cus_app
- __create_tables.py
- baseconfig.py
- cli.py
- README.md
- setup_logging.py
- usint.py
Then, following the copy of the application source code files, a few additional setup tasks should be done to ensure that the particular installation is ready.
-
Create the
instancesubdirectory for containing files pertaining to the installation. In this instance subdirectory, you should consider creating the following files and subdirectoriesconfig.py(Configuration values which override the baseconfig.py file. This is good for changing the default dev behavior to official testing or production behavior.)- SQLALCHEMY_DATABASE_URI
- HTTP_ADDRESS
- MAIL_SUPPRESS_SEND
- TEST_DATABASE
- SECRET_KEY
- log subdirectories (For containing the rotating log files)
log/accesslog/errorlog/operation
-
Activate the conda environment supporting the app installation (
/proj/sot/mta/envs) and run the __create_tables.py script to ensure data tables and flask session tables are instantiated in the database configured for this install.
Using the CLI, we also run a set of support scripts and commands to performs tasks such as database backups, maintenance, and retaining legacy data files. The Cronjobs to run these supplemental tasks are written in the cronjobs.md file
Syshelp uses a separate setup for processing logs which relate to their Apache web server operations. For Flask Usint on the Gunicorn sever,
this differs to provided more direct access to compartmentalized logs for each application installation.
Starting at the root folder of the application, /proj/web-cxc/wsgi-scripts/cus for example, there is an instance/logs directory which contains three types of logs
- access: This contains a log of the HTTP requests made to the server. Here you can see what URL's are requested by which user and other HTTP request header information
- error: This contains runtime errors for both the gunicorn server running the flask application, and runtime errors within the flask application.
- operation: This is a log for normal operational messages, such as a revision being submitted, or a signoff being performed.
The top level of this project is the application root, containing the server entrypoint modules, base configuration settings, the instance directory containing file relevant to this application installation's specific runtime, and the cus_app package containing our source code.
-
usint.py
Python module entrypoint for the gunicorn server which determine application creation and configuration. By acting as an entrypoint, MTA can perform file edits to the application configuration and creation without necessarily requiring a gunicorn server restart. Conceptually, the application could still run if gunicorn called the cus_app package create_app() function directly. -
baseconfig.py
Configuration file. -
instance/
Instance folder for storing application-specific files such as logs and theusint.dbdatabase. -
cus_app/
Main Flask application folder containing relevant page generation scripts:__init__.py— Application instantiation scriptemailing.py— Email-related functions for notificationsmodels.py— SQLAlchemy ORM models for interfacing with the Usint Revision databaseextensions.py- Module for instantiating the Flask Extension class instances.
chkupdata/— Parameter check page scriptserrors/— Error handler scriptsexpress/— Express sign-off page scriptsocatdatapage/— Ocat data page scriptsorupdate/— Parameter status page scriptsscheduler/— TOO duty scheduler page scriptssupple/— Supplemental Python scripts
color.json— Maps color names to RGB valueslabels.json— Maps Ocat parameters to visual labelsparameter_selections.json— Parameter group mappings used across the applicationusint.js— javascript library for the Ocat data pageocat_style.css— CSS stylesocatdatapage/— Static files for the Ocat data pageorupdate/— Static files for the parameter status pagescheduler/— Static files for the scheduler page
base.html- Base template block for general web pages.app_base.html— Base template for application pages (mainly CSS differences)index.html— Main index page- Additional page-specific templates (see sections below)
Displays original, requested, and current parameter values for a given <obsid>.<rev>.
routes.py— Main logicforms.py— WTForms definitions__init__.py— Module setup
index.html— Main pageprovide_obsidrev.html— Shown when<obsid>.<rev>is not foundmacros.html— Template macros
Application error handling.
handlers.py— Main error handling logic__init__.py— Module setup
404.html— Not found page500.html— Server error page
Express sign-off / approval workflow.
routes.py— Main logicforms.py— WTForms definitions__init__.py— Module setup
index.html— Main pageconfirm.html— Confirmation pagemacros.html— Template macros
Ocat data page used for updating parameter values.
routes.py— Main logicforms.py— WTForms definitionsformat_ocat_data.py— Data formatting utilities__init__.py— Module setup
<obs_ss>/mp_long_term— Planned roll angle from MP site<obs_ss>/scheduled_obs_list— Scheduled observations
index.html— Main update pagemacros.html— Template macrosconfirm.html— Update confirmation pagefinalize.html— Job completion pageprovide_obsid.html— Shown when<obsid>is not found
Target parameter status page.
routes.py— Main logicforms.py— WTForms definitions__init__.py— Module setup
index.html— Main pagemacros.html— Template macros
Note:
This page refreshes every 3 minutes to display the latest data. This ensures consistency when multiple users are updating the database simultaneously.
Remove accidental submissions.
routes.py— Main logicforms.py— WTForms definitions__init__.py— Module setup
index.html— Main pagemacros.html— Template macros
POC duty sign-up sheet.
routes.py— Main logicforms.py— WTForms definitions__init__.py— Module setup
index.html— Main pagemacros.html— Template macros
Supplemental scripts used across the application.
database_interface.py— SQLAlchemy interface for the Usint Revision SQLite databasehelper_functions.py— General helper utilitiesread_ocat_data.py— Fetches and formats Ocat Sybase data via theska_dbi SQSHinterface
- CXC Ocat Sybase database (via
read_ocat_data.py) - Usint Revision SQLite database (via
database_interface.py)