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

1""" 

2camcops_server/cc_modules/cc_baseconstants.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CamCOPS. 

10 

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. 

15 

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. 

20 

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/>. 

23 

24=============================================================================== 

25 

26**Constants required during package creation, which therefore can't rely on 

27anything except the Python standard library.** 

28 

29By simple extension, also directory/filename definitions within the server 

30tree. 

31 

32Also, for visibility, environment variable names. 

33""" 

34 

35import os 

36from os import pardir 

37from os.path import abspath, dirname, join 

38import sys 

39 

40 

41# ============================================================================= 

42# Environment variable names 

43# ============================================================================= 

44 

45ENVVAR_CONFIG_FILE = "CAMCOPS_CONFIG_FILE" # external or internal 

46ENVVAR_GENERATING_CAMCOPS_DOCS = "GENERATING_CAMCOPS_DOCS" 

47 

48 

49# ============================================================================= 

50# Third-party package settings 

51# ============================================================================= 

52 

53DEFORM_SUPPORTS_CSP_NONCE = False 

54 

55 

56# ============================================================================= 

57# Directories and filenames 

58# ============================================================================= 

59 

60_this_directory = dirname(abspath(__file__)) # cc_modules 

61CAMCOPS_SERVER_DIRECTORY = abspath( 

62 join(_this_directory, pardir) 

63) # camcops_server 

64 

65if ENVVAR_GENERATING_CAMCOPS_DOCS in os.environ: 

66 CAMCOPS_SERVER_DIRECTORY = "/path/to/camcops/server" 

67 

68ALEMBIC_BASE_DIR = CAMCOPS_SERVER_DIRECTORY 

69 

70DEFAULT_EXTRA_STRINGS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "extra_strings") 

71 

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" 

80 

81PROHIBITED_PASSWORDS_FILE = join( 

82 CAMCOPS_SERVER_DIRECTORY, 

83 "prohibited_passwords", 

84 "PwnedPasswordsTop100k.txt", 

85) 

86 

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") 

91 

92 

93# ============================================================================= 

94# Filenames 

95# ============================================================================= 

96 

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 

105 

106ALEMBIC_CONFIG_FILENAME = join(ALEMBIC_BASE_DIR, "alembic.ini") 

107 

108 

109# ============================================================================= 

110# Significant table names 

111# ============================================================================= 

112 

113ALEMBIC_VERSION_TABLE = "_alembic_version" 

114 

115 

116# ============================================================================= 

117# URLs 

118# ============================================================================= 

119 

120DOCUMENTATION_URL = "https://camcops.readthedocs.io/" 

121 

122 

123# ============================================================================= 

124# Special environment detection 

125# ============================================================================= 

126 

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) 

134 

135 

136# ============================================================================= 

137# Exit codes 

138# ============================================================================= 

139 

140EXIT_SUCCESS = 0 

141EXIT_FAILURE = 1