Make drive letters available in file picker
This commit is contained in:
parent
e22ecda137
commit
7eef44f73c
46
cps/admin.py
Executable file → Normal file
46
cps/admin.py
Executable file → Normal file
|
@ -26,11 +26,12 @@ import base64
|
||||||
import json
|
import json
|
||||||
import operator
|
import operator
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
import string
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from datetime import time as datetime_time
|
from datetime import time as datetime_time
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
from flask import Blueprint, flash, redirect, url_for, abort, request, make_response, send_from_directory, g, Response
|
from flask import Blueprint, flash, redirect, url_for, abort, request, make_response, send_from_directory, g, Response
|
||||||
from flask_login import login_required, current_user, logout_user, confirm_login
|
from flask_login import login_required, current_user, logout_user, confirm_login
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
|
@ -52,7 +53,6 @@ from .services.worker import WorkerThread
|
||||||
from .babel import get_available_translations, get_available_locale, get_user_locale_language
|
from .babel import get_available_translations, get_available_locale, get_user_locale_language
|
||||||
from . import debug_info
|
from . import debug_info
|
||||||
|
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
|
|
||||||
feature_support = {
|
feature_support = {
|
||||||
|
@ -67,12 +67,14 @@ feature_support = {
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import rarfile # pylint: disable=unused-import
|
import rarfile # pylint: disable=unused-import
|
||||||
|
|
||||||
feature_support['rar'] = True
|
feature_support['rar'] = True
|
||||||
except (ImportError, SyntaxError):
|
except (ImportError, SyntaxError):
|
||||||
feature_support['rar'] = False
|
feature_support['rar'] = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .oauth_bb import oauth_check, oauthblueprints
|
from .oauth_bb import oauth_check, oauthblueprints
|
||||||
|
|
||||||
feature_support['oauth'] = True
|
feature_support['oauth'] = True
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
log.debug('Cannot import Flask-Dance, login with Oauth will not work: %s', err)
|
log.debug('Cannot import Flask-Dance, login with Oauth will not work: %s', err)
|
||||||
|
@ -80,7 +82,6 @@ except ImportError as err:
|
||||||
oauthblueprints = []
|
oauthblueprints = []
|
||||||
oauth_check = {}
|
oauth_check = {}
|
||||||
|
|
||||||
|
|
||||||
admi = Blueprint('admin', __name__)
|
admi = Blueprint('admin', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,6 +160,7 @@ def shutdown():
|
||||||
show_text['text'] = _(u'Unknown command')
|
show_text['text'] = _(u'Unknown command')
|
||||||
return json.dumps(show_text), 400
|
return json.dumps(show_text), 400
|
||||||
|
|
||||||
|
|
||||||
@admi.route("/metadata_backup", methods=["POST"])
|
@admi.route("/metadata_backup", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
|
@ -978,6 +980,19 @@ def prepare_tags(user, action, tags_name, id_list):
|
||||||
return ",".join(saved_tags_list)
|
return ",".join(saved_tags_list)
|
||||||
|
|
||||||
|
|
||||||
|
def get_drives(current):
|
||||||
|
drive_letters = []
|
||||||
|
for d in string.ascii_uppercase:
|
||||||
|
if os.path.exists('{}:'.format(d)) and current[0].lower() != d.lower():
|
||||||
|
drive = "{}:\\".format(d)
|
||||||
|
data = {"name": drive, "fullpath": drive}
|
||||||
|
data["sort"] = "_" + data["fullpath"].lower()
|
||||||
|
data["type"] = "dir"
|
||||||
|
data["size"] = ""
|
||||||
|
drive_letters.append(data)
|
||||||
|
return drive_letters
|
||||||
|
|
||||||
|
|
||||||
def pathchooser():
|
def pathchooser():
|
||||||
browse_for = "folder"
|
browse_for = "folder"
|
||||||
folder_only = request.args.get('folder', False) == "true"
|
folder_only = request.args.get('folder', False) == "true"
|
||||||
|
@ -985,40 +1000,41 @@ def pathchooser():
|
||||||
path = os.path.normpath(request.args.get('path', ""))
|
path = os.path.normpath(request.args.get('path', ""))
|
||||||
|
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
oldfile = path
|
old_file = path
|
||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
else:
|
else:
|
||||||
oldfile = ""
|
old_file = ""
|
||||||
|
|
||||||
absolute = False
|
absolute = False
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
# if os.path.isabs(path):
|
|
||||||
cwd = os.path.realpath(path)
|
cwd = os.path.realpath(path)
|
||||||
absolute = True
|
absolute = True
|
||||||
# else:
|
|
||||||
# cwd = os.path.relpath(path)
|
|
||||||
else:
|
else:
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
|
|
||||||
cwd = os.path.normpath(os.path.realpath(cwd))
|
cwd = os.path.normpath(os.path.realpath(cwd))
|
||||||
parentdir = os.path.dirname(cwd)
|
parent_dir = os.path.dirname(cwd)
|
||||||
if not absolute:
|
if not absolute:
|
||||||
if os.path.realpath(cwd) == os.path.realpath("/"):
|
if os.path.realpath(cwd) == os.path.realpath("/"):
|
||||||
cwd = os.path.relpath(cwd)
|
cwd = os.path.relpath(cwd)
|
||||||
else:
|
else:
|
||||||
cwd = os.path.relpath(cwd) + os.path.sep
|
cwd = os.path.relpath(cwd) + os.path.sep
|
||||||
parentdir = os.path.relpath(parentdir) + os.path.sep
|
parent_dir = os.path.relpath(parent_dir) + os.path.sep
|
||||||
|
|
||||||
if os.path.realpath(cwd) == os.path.realpath("/"):
|
files = []
|
||||||
parentdir = ""
|
if os.path.realpath(cwd) == os.path.realpath("/") \
|
||||||
|
or (sys.platform == "win32" and os.path.realpath(cwd)[1:] == os.path.realpath("/")[1:]):
|
||||||
|
# we are in root
|
||||||
|
parent_dir = ""
|
||||||
|
if sys.platform == "win32":
|
||||||
|
files = get_drives(cwd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
folders = os.listdir(cwd)
|
folders = os.listdir(cwd)
|
||||||
except Exception:
|
except Exception:
|
||||||
folders = []
|
folders = []
|
||||||
|
|
||||||
files = []
|
|
||||||
for f in folders:
|
for f in folders:
|
||||||
try:
|
try:
|
||||||
data = {"name": f, "fullpath": os.path.join(cwd, f)}
|
data = {"name": f, "fullpath": os.path.join(cwd, f)}
|
||||||
|
@ -1051,9 +1067,9 @@ def pathchooser():
|
||||||
context = {
|
context = {
|
||||||
"cwd": cwd,
|
"cwd": cwd,
|
||||||
"files": files,
|
"files": files,
|
||||||
"parentdir": parentdir,
|
"parentdir": parent_dir,
|
||||||
"type": browse_for,
|
"type": browse_for,
|
||||||
"oldfile": oldfile,
|
"oldfile": old_file,
|
||||||
"absolute": absolute,
|
"absolute": absolute,
|
||||||
}
|
}
|
||||||
return json.dumps(context)
|
return json.dumps(context)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user