Coverage for cc_modules/cc_baseconstants.py: 88%

1"""

2 camcops_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

27 anything except the Python standard library.**

28

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

30 tree.

31

32 Also, for visibility, environment variable names.

33"""

34

35 import os

36 from os import pardir

37 from os.path import abspath, dirname, join

38 import sys

39

40

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

42# Environment variable names

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

44

45 ENVVAR_CONFIG_FILE = "CAMCOPS_CONFIG_FILE" # external or internal

46 ENVVAR_GENERATING_CAMCOPS_DOCS = "GENERATING_CAMCOPS_DOCS"

47

48

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

50# Third-party package settings

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

52

53 DEFORM_SUPPORTS_CSP_NONCE = False

54

55

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

57# Directories and filenames

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

59

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

61 CAMCOPS_SERVER_DIRECTORY = abspath(

62 join(_this_directory, pardir)

63) # camcops_server

64

65 if ENVVAR_GENERATING_CAMCOPS_DOCS in os.environ:

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

67

68 ALEMBIC_BASE_DIR = CAMCOPS_SERVER_DIRECTORY

69

70 DEFAULT_EXTRA_STRINGS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "extra_strings")

71

72 LINUX_DEFAULT_CAMCOPS_CONFIG_DIR = "/etc/camcops"

73 LINUX_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

76 LINUX_DEFAULT_LOCK_DIR = "/var/lock/camcops"

77 LINUX_DEFAULT_MATPLOTLIB_CACHE_DIR = "/var/cache/camcops/matplotlib"

78# ... Lintian dislikes using /var/local

79 LINUX_DEFAULT_USER_DOWNLOAD_DIR = "/var/tmp/camcops"

80

81 PROHIBITED_PASSWORDS_FILE = join(

82 CAMCOPS_SERVER_DIRECTORY,

83 "prohibited_passwords",

84 "PwnedPasswordsTop100k.txt",

85)

86

87 STATIC_ROOT_DIR = join(CAMCOPS_SERVER_DIRECTORY, "static")

88# ... mostly but not entirely superseded by STATIC_CAMCOPS_PACKAGE_PATH

89 TEMPLATE_DIR = join(CAMCOPS_SERVER_DIRECTORY, "templates")

90 TRANSLATIONS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "translations")

91

92

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

94# Filenames

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

96

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

103 else:

104 CAMCOPS_EXECUTABLE = "camcops" # fallback; may not work

105

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

107

108

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

110# Significant table names

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

112

113 ALEMBIC_VERSION_TABLE = "_alembic_version"

114

115

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

117# URLs

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

119

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

121

122

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

124# Special environment detection

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

126

127# Is this program running on readthedocs.org?

128 ON_READTHEDOCS = os.environ.get("READTHEDOCS") == "True"

129 ENVVARS_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

140 EXIT_SUCCESS = 0

141 EXIT_FAILURE = 1