mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added support for the server side file manager, which will be useful in
selection, creation, upload/download files/directories resides on the server side. This will be useful for file selection/creation for different server side utilites like pg_dump, pg_dumpall, pg_restore.
This commit is contained in:
68
web/pgadmin/utils/paths.py
Normal file
68
web/pgadmin/utils/paths.py
Normal file
@@ -0,0 +1,68 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
"""This file contains functions fetching different utility paths."""
|
||||
|
||||
import os
|
||||
from flask.ext.security import current_user, login_required
|
||||
import config
|
||||
|
||||
|
||||
@login_required
|
||||
def get_storage_directory():
|
||||
|
||||
if config.SERVER_MODE is not True:
|
||||
return None
|
||||
|
||||
storage_dir = getattr(
|
||||
config, 'STORAGE_DIR',
|
||||
os.path.join(
|
||||
os.path.realpath(
|
||||
os.path.expanduser('~/.pgadmin/')
|
||||
), 'storage'
|
||||
)
|
||||
)
|
||||
username = current_user.email.split('@')[0]
|
||||
if len(username) == 0 or username[0].isdigit():
|
||||
username = 'pga_user_' + username
|
||||
|
||||
storage_dir = os.path.join(storage_dir, username)
|
||||
print(storage_dir)
|
||||
|
||||
if not os.path.exists(storage_dir):
|
||||
os.makedirs(storage_dir, int('700', 8))
|
||||
|
||||
return storage_dir
|
||||
|
||||
|
||||
def init_app(app):
|
||||
|
||||
if config.SERVER_MODE is not True:
|
||||
return None
|
||||
|
||||
storage_dir = getattr(
|
||||
config, 'STORAGE_DIR',
|
||||
os.path.join(
|
||||
os.path.realpath(
|
||||
os.path.expanduser('~/.pgadmin/')
|
||||
), 'storage'
|
||||
)
|
||||
)
|
||||
|
||||
if not os.path.isdir(storage_dir):
|
||||
if os.path.exists(storage_dir):
|
||||
raise Exception(
|
||||
'The value specified for as the storage directory is not a directory!'
|
||||
)
|
||||
os.makedirs(storage_dir, int('700', 8))
|
||||
|
||||
if not os.access(storage_dir, os.W_OK | os.R_OK):
|
||||
raise Exception(
|
||||
'The user does not have permission to read, write on the specified storage directory!'
|
||||
)
|
||||
Reference in New Issue
Block a user