MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / create_app_data_directory

Function create_app_data_directory

web/pgadmin/setup/data_directory.py:27–180  ·  view source on GitHub ↗

Create the required directories (if not present).

(config)

Source from the content-addressed store, hash-verified

25
26
27def create_app_data_directory(config):
28 """
29 Create the required directories (if not present).
30 """
31 # Create the directory containing the configuration file (if not present).
32 is_directory_created = False
33 try:
34 is_directory_created = _create_directory_if_not_exists(
35 os.path.dirname(config.SQLITE_PATH))
36 except PermissionError as e:
37 print(FAILED_CREATE_DIR.format(os.path.dirname(config.SQLITE_PATH), e))
38 print(
39 "HINT : Create the directory {}, ensure it is writeable by\n"
40 " '{}', and try again, or, create a config_local.py file\n"
41 " and override the SQLITE_PATH setting per\n"
42 " https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
43 format(
44 os.path.dirname(config.SQLITE_PATH),
45 getpass.getuser(),
46 config.APP_VERSION))
47 sys.exit(1)
48
49 # Try to set the permissions on the directory, but don't complain
50 # if we can't. This may be the case on a mounted directory, e.g. in
51 # OpenShift. We'll still secure the config database anyway.
52 if os.name != 'nt' and is_directory_created:
53 try:
54 os.chmod(os.path.dirname(config.SQLITE_PATH), 0o700)
55 except Exception as e:
56 # The flask app isn't setup yet, so we can't use the logger
57 print('WARNING: Failed to set ACL on the directory containing the '
58 'configuration database:\n {}'.format(e))
59 print("HINT : You may need to manually set the permissions on\n"
60 " {} to allow {} to write to it.".
61 format(os.path.dirname(config.SQLITE_PATH),
62 getpass.getuser()))
63
64 # Create the directory containing the log file (if not present).
65 log_dir_created = False
66 try:
67 log_dir_created = _create_directory_if_not_exists(
68 os.path.dirname(config.LOG_FILE))
69 except PermissionError as e:
70 print(FAILED_CREATE_DIR.format(os.path.dirname(config.LOG_FILE), e))
71 print(
72 "HINT : Create the directory {}, ensure it is writeable by\n"
73 " '{}', and try again, or, create a config_local.py file\n"
74 " and override the LOG_FILE setting per\n"
75 " https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
76 format(
77 os.path.dirname(config.LOG_FILE),
78 getpass.getuser(),
79 config.APP_VERSION))
80 sys.exit(1)
81
82 # Create the session directory (if not present).
83 session_dir_created = False
84 try:

Callers 2

setup_dbFunction · 0.90
create_appFunction · 0.90

Calls 3

dirnameMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected