Coverage for cc_modules/cc_baseconstants.py: 89%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_baseconstants.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28**Constants required during package creation, which therefore can't rely on
29anything except the Python standard library.**
31By simple extension, also directory/filename definitions within the server
32tree.
34Also, for visibility, environment variable names.
35"""
37import os
38from os import pardir
39from os.path import abspath, dirname, join
40import sys
43# =============================================================================
44# Environment variable names
45# =============================================================================
47ENVVAR_CONFIG_FILE = "CAMCOPS_CONFIG_FILE" # external or internal
48ENVVAR_GENERATING_CAMCOPS_DOCS = "GENERATING_CAMCOPS_DOCS"
51# =============================================================================
52# Third-party package settings
53# =============================================================================
55DEFORM_SUPPORTS_CSP_NONCE = False
58# =============================================================================
59# Directories and filenames
60# =============================================================================
62_this_directory = dirname(abspath(__file__)) # cc_modules
63CAMCOPS_SERVER_DIRECTORY = abspath(
64 join(_this_directory, pardir)
65) # camcops_server
67if ENVVAR_GENERATING_CAMCOPS_DOCS in os.environ:
68 CAMCOPS_SERVER_DIRECTORY = "/path/to/camcops/server"
70ALEMBIC_BASE_DIR = CAMCOPS_SERVER_DIRECTORY
72DEFAULT_EXTRA_STRINGS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "extra_strings")
74LINUX_DEFAULT_CAMCOPS_CONFIG_DIR = "/etc/camcops"
75LINUX_DEFAULT_CAMCOPS_DIR = "/usr/share/camcops"
76# Lintian dislikes files/subdirectories in: /usr/bin/X, /usr/local/X, /opt/X
77# It dislikes images in /usr/lib
78LINUX_DEFAULT_LOCK_DIR = "/var/lock/camcops"
79LINUX_DEFAULT_MATPLOTLIB_CACHE_DIR = "/var/cache/camcops/matplotlib"
80# ... Lintian dislikes using /var/local
81LINUX_DEFAULT_USER_DOWNLOAD_DIR = "/var/tmp/camcops"
83PROHIBITED_PASSWORDS_FILE = join(
84 CAMCOPS_SERVER_DIRECTORY,
85 "prohibited_passwords",
86 "PwnedPasswordsTop100k.txt",
87)
89STATIC_ROOT_DIR = join(CAMCOPS_SERVER_DIRECTORY, "static")
90# ... mostly but not entirely superseded by STATIC_CAMCOPS_PACKAGE_PATH
91TEMPLATE_DIR = join(CAMCOPS_SERVER_DIRECTORY, "templates")
92TRANSLATIONS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "translations")
95# =============================================================================
96# Filenames
97# =============================================================================
99if hasattr(sys, "real_prefix"):
100 # We're running in a virtual environment.
101 # https://stackoverflow.com/questions/1871549/python-determine-if-running-inside-virtualenv
102 _venv = sys.prefix
103 _venv_bin = join(_venv, "bin")
104 CAMCOPS_EXECUTABLE = join(_venv_bin, "camcops")
105else:
106 CAMCOPS_EXECUTABLE = "camcops" # fallback; may not work
108ALEMBIC_CONFIG_FILENAME = join(ALEMBIC_BASE_DIR, "alembic.ini")
111# =============================================================================
112# Significant table names
113# =============================================================================
115ALEMBIC_VERSION_TABLE = "_alembic_version"
118# =============================================================================
119# URLs
120# =============================================================================
122DOCUMENTATION_URL = "https://camcops.readthedocs.io/"
125# =============================================================================
126# Special environment detection
127# =============================================================================
129# Is this program running on readthedocs.org?
130ON_READTHEDOCS = os.environ.get("READTHEDOCS") == "True"
131ENVVARS_PROHIBITED_DURING_DOC_BUILD = (
132 "LCONVERT", # for build_client_translations.py
133 "LRELEASE", # for build_client_translations.py
134 "LUPDATE", # for build_client_translations.py
135)
138# =============================================================================
139# Exit codes
140# =============================================================================
142EXIT_SUCCESS = 0
143EXIT_FAILURE = 1