Hide keyboard shortcuts

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 

2 

3""" 

4camcops_server/cc_modules/cc_baseconstants.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com). 

9 

10 This file is part of CamCOPS. 

11 

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. 

16 

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. 

21 

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

24 

25=============================================================================== 

26 

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

28anything except the Python standard library.** 

29 

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

31tree. 

32 

33Also, for visibility, environment variable names. 

34""" 

35 

36import os 

37from os import pardir 

38from os.path import abspath, dirname, join 

39import sys 

40 

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

42# Environment variable names 

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

44 

45ENVVAR_CONFIG_FILE = "CAMCOPS_CONFIG_FILE" # external or internal 

46 

47 

48# ============================================================================= 

49# Third-party package settings 

50# ============================================================================= 

51 

52DEFORM_SUPPORTS_CSP_NONCE = False 

53 

54 

55# ============================================================================= 

56# Directories and filenames 

57# ============================================================================= 

58 

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

60CAMCOPS_SERVER_DIRECTORY = abspath(join(_this_directory, pardir)) # camcops_server # noqa 

61 

62if "GENERATING_CAMCOPS_DOCS" in os.environ: 

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

64 

65ALEMBIC_BASE_DIR = CAMCOPS_SERVER_DIRECTORY 

66 

67DEFAULT_EXTRA_STRINGS_DIR = join(CAMCOPS_SERVER_DIRECTORY, "extra_strings") 

68 

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" 

77 

78PROHIBITED_PASSWORDS_FILE = join( 

79 CAMCOPS_SERVER_DIRECTORY, 

80 "prohibited_passwords", "PwnedPasswordsTop100k.txt" 

81) 

82 

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

87 

88 

89# ============================================================================= 

90# Filenames 

91# ============================================================================= 

92 

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 

101 

102ALEMBIC_CONFIG_FILENAME = join(ALEMBIC_BASE_DIR, 'alembic.ini') 

103 

104 

105# ============================================================================= 

106# Significant table names 

107# ============================================================================= 

108 

109ALEMBIC_VERSION_TABLE = "_alembic_version" 

110 

111 

112# ============================================================================= 

113# URLs 

114# ============================================================================= 

115 

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

117 

118 

119# ============================================================================= 

120# Special environment detection 

121# ============================================================================= 

122 

123# Is this program running on readthedocs.org? 

124ON_READTHEDOCS = os.environ.get('READTHEDOCS') == 'True' 

125 

126 

127# ============================================================================= 

128# Exit codes 

129# ============================================================================= 

130 

131EXIT_SUCCESS = 0 

132EXIT_FAILURE = 1