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