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

Function get_storage_directory

web/pgadmin/utils/paths.py:35–100  ·  view source on GitHub ↗
(user=current_user, shared_storage='')

Source from the content-addressed store, hash-verified

33
34
35def get_storage_directory(user=current_user, shared_storage=''):
36 # Don't move this import statement to the top of the file,
37 # it throws circular import error.
38 import config
39 if config.SERVER_MODE is not True:
40 return None
41
42 is_shared_storage = False
43 if shared_storage != MY_STORAGE and shared_storage:
44 is_shared_storage = True
45 selected_dir = [sdir for sdir in config.SHARED_STORAGE if
46 sdir['name'] == shared_storage]
47 storage_dir = None
48 if len(selected_dir) > 0:
49 the_dir = selected_dir[0]['path']
50 storage_dir = the_dir
51 else:
52 storage_dir = getattr(
53 config, 'STORAGE_DIR',
54 os.path.join(
55 os.path.realpath(
56 os.path.expanduser(PGADMIN_PATH)
57 ), 'storage'
58 )
59 )
60
61 if storage_dir is None:
62 return None
63
64 username = preprocess_username(user.username.split('@')[0])
65
66 # Figure out the old-style storage directory name
67 old_storage_dir = os.path.join(
68 storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode')
69 else storage_dir,
70 username
71 )
72
73 username = preprocess_username(user.username)
74
75 if is_shared_storage:
76 # Figure out the new style storage directory name
77 storage_dir = os.path.join(
78 storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode')
79 else storage_dir
80 )
81 else:
82 # Figure out the new style storage directory name
83 storage_dir = os.path.join(
84 storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode')
85 else storage_dir,
86 username
87 )
88
89 # Rename an old-style storage directory, if the new style doesn't exist
90 if os.path.exists(old_storage_dir) and not os.path.exists(storage_dir):
91 current_app.logger.warning(
92 'Renaming storage directory %s to %s.',

Callers 9

create_import_export_jobFunction · 0.90
current_storage_dirMethod · 0.90
load_fileFunction · 0.90
save_fileFunction · 0.90
__init__Method · 0.90
get_complete_file_pathFunction · 0.85

Calls 6

preprocess_usernameFunction · 0.85
joinMethod · 0.80
decodeMethod · 0.80
warningMethod · 0.80
renameMethod · 0.65
existsMethod · 0.45

Tested by

no test coverage detected