Coverage for cc_modules/cc_baseconstants.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_baseconstants.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
27**Constants required during package creation, which therefore can't rely on
28anything except the Python standard library.**
30By simple extension, also directory/filename definitions within the server
31tree.
33Also, for visibility, environment variable names.
34"""
36import os
37from os import pardir
38from os.path import abspath, dirname, join
39import sys
41# =============================================================================
42# Environment variable names
43# =============================================================================
45ENVVAR_CONFIG_FILE = "CAMCOPS_CONFIG_FILE" # external or internal
48# =============================================================================
49# Third-party package settings
50# =============================================================================
52DEFORM_SUPPORTS_CSP_NONCE = False
55# =============================================================================
56# Directories and filenames
57# =============================================================================
59_this_directory = dirname(abspath(__file__)) # cc_modules
60CAMCOPS_SERVER_DIRECTORY = abspath(join(_this_directory, pardir)) # camcops_server # noqa
62if "GENERATING_CAMCOPS_DOCS" in os.environ:
63 CAMCOPS_SERVER_DIRECTORY = "/path/to/camcops/server"
65ALEMBIC_BASE_DIR = CAMCOPS_SERVER_DIRECTORY
67DEFAULT_EXTRA_STRINGS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "extra_strings")
69LINUX_DEFAULT_CAMCOPS_CONFIG_DIR = "/etc/camcops"
70LINUX_DEFAULT_CAMCOPS_DIR = "/usr/share/camcops"
71# Lintian dislikes files/subdirectories in: /usr/bin/X, /usr/local/X, /opt/X
72# It dislikes images in /usr/lib
73LINUX_DEFAULT_LOCK_DIR = "/var/lock/camcops"
74LINUX_DEFAULT_MATPLOTLIB_CACHE_DIR = "/var/cache/camcops/matplotlib"
75# ... Lintian dislikes using /var/local
76LINUX_DEFAULT_USER_DOWNLOAD_DIR = "/var/tmp/camcops"
78PROHIBITED_PASSWORDS_FILE = join(
79 CAMCOPS_SERVER_DIRECTORY,
80 "prohibited_passwords", "PwnedPasswordsTop100k.txt"
81)
83STATIC_ROOT_DIR = join(CAMCOPS_SERVER_DIRECTORY, "static")
84# ... mostly but not entirely superseded by STATIC_CAMCOPS_PACKAGE_PATH
85TEMPLATE_DIR = join(CAMCOPS_SERVER_DIRECTORY, "templates")
86TRANSLATIONS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "translations")
89# =============================================================================
90# Filenames
91# =============================================================================
93if hasattr(sys, 'real_prefix'):
94 # We're running in a virtual environment.
95 # https://stackoverflow.com/questions/1871549/python-determine-if-running-inside-virtualenv
96 _venv = sys.prefix
97 _venv_bin = join(_venv, 'bin')
98 CAMCOPS_EXECUTABLE = join(_venv_bin, "camcops")
99else:
100 CAMCOPS_EXECUTABLE = "camcops" # fallback; may not work
102ALEMBIC_CONFIG_FILENAME = join(ALEMBIC_BASE_DIR, 'alembic.ini')
105# =============================================================================
106# Significant table names
107# =============================================================================
109ALEMBIC_VERSION_TABLE = "_alembic_version"
112# =============================================================================
113# URLs
114# =============================================================================
116DOCUMENTATION_URL = "https://camcops.readthedocs.io/"
119# =============================================================================
120# Special environment detection
121# =============================================================================
123# Is this program running on readthedocs.org?
124ON_READTHEDOCS = os.environ.get('READTHEDOCS') == 'True'
127# =============================================================================
128# Exit codes
129# =============================================================================
131EXIT_SUCCESS = 0
132EXIT_FAILURE = 1