autowisp.browser_interface.django_project.db_config module

Resolve which database the browser interface should use.

By default this is an SQLite file in the user data directory, which is what every existing installation has and what a fresh one gets with no configuration at all. Pointing it at a server instead means giving a URL, spelled the way the project database spells its own so the two read alike:

mysql+pymysql://user:password@host:3306/autowisp_bui
mariadb+pymysql://user:password@host:3306/autowisp_bui

taken from $AUTOWISP_BUI_DB_URL or, failing that, a bui_db.url file in the user data directory – the same two-step the project database uses, except global rather than per project, since the browser interface has no project home to hang a URL off.

One database per host. A server-hosted database is for keeping the installation’s state somewhere backed up and administered centrally, not for sharing between hosts. Sharing would need more than a URL: Project records a local filesystem path, so a project list written on one host is only meaningful on another if the project directories are mounted identically, and schema upgrades would stop being the single-process event that lets the browser interface migrate itself on launch.

autowisp.browser_interface.django_project.db_config._ensure_mysql_driver()[source]

Make Django’s MySQL backend work with whichever driver is installed.

Django’s backend imports MySQLdb, supplied by mysqlclient. AutoWISP does not depend on either driver – the project database documents mysql+pymysql and leaves installing it to the user – so accept pymysql as well rather than insisting on Django’s default.

The imports are deliberately not at module level: neither driver is a dependency, so importing one on the way in would make this module – and therefore settings – unimportable on every SQLite install, which is all of them by default.

autowisp.browser_interface.django_project.db_config.get_database_url(data_dir)[source]

Return the configured database URL, or None if there is none.

Parameters:

data_dir – The user data directory to look for the URL file in.

Returns:

The URL, stripped, or None to use the default

SQLite database.

Return type:

str or None

autowisp.browser_interface.django_project.db_config.get_databases(data_dir)[source]

Return Django’s DATABASES setting for the browser interface.

Parameters:

data_dir – The user data directory, holding the default SQLite database and, optionally, the URL file naming another.

Returns:

Suitable for assigning to DATABASES.

Return type:

dict

Raises:

ValueError – If the configured URL names a backend whose modified trigger is not implemented.

autowisp.browser_interface.django_project.db_config.sqlite_fname = 'bui_db.sqlite3'

The database used when nothing is configured.

autowisp.browser_interface.django_project.db_config.url_env_var = 'AUTOWISP_BUI_DB_URL'

Environment variable holding the URL, for deployments that would rather not leave a password on disk. Takes precedence over the file.

autowisp.browser_interface.django_project.db_config.url_fname = 'bui_db.url'

File in the user data directory holding the URL, when the environment does not. Named to match the project database’s autowisp_db.url.