new file versioning policy and manager. be sure to add version_folder in your conf
This commit is contained in:
45
code/app.py
45
code/app.py
@@ -14,7 +14,7 @@ from utils.utils import *
|
||||
from utils.crypt import *
|
||||
|
||||
|
||||
__FLEES_VERSION__ = "20180720.0"
|
||||
__FLEES_VERSION__ = "20180721.0"
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(__name__)
|
||||
# Read config from json !
|
||||
@@ -29,6 +29,7 @@ app.config['DATE_FORMAT'] = config_values['date_format']
|
||||
app.config['UID'] = config_values['uid']
|
||||
app.config['GID'] = config_values['gid']
|
||||
app.config['DEBUG'] = config_values['debug']
|
||||
app.config['VERSION_FOLDER'] = config_values['version_folder']
|
||||
if 'notifier' in config_values:
|
||||
if len(config_values['notifier']) > 0:
|
||||
notifier_config = config_values['notifier'].split(":")
|
||||
@@ -313,7 +314,7 @@ def file_list(name, token):
|
||||
if not ok:
|
||||
return share
|
||||
files = []
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
files.append(path2url(file))
|
||||
files.append("")
|
||||
return "\n".join(files), 200
|
||||
@@ -325,7 +326,7 @@ def file_details(name, token):
|
||||
if not ok:
|
||||
return share
|
||||
files = []
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
status = file_stat(share['path'],file)
|
||||
files.append(status)
|
||||
return jsonify(files), 200
|
||||
@@ -362,7 +363,7 @@ def list_view(name, token = None):
|
||||
return redirect(url_for('list_view',name=name))
|
||||
|
||||
files = []
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
status = file_stat(share['path'],file)
|
||||
status.update({
|
||||
'token': get_direct_token(share, file),
|
||||
@@ -514,7 +515,7 @@ def script_download(name = None, token = None):
|
||||
if not ok:
|
||||
return share
|
||||
commands = []
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
status = file_stat(share['path'], file)
|
||||
commands.append('get_file "%s"'%(
|
||||
status['url'],
|
||||
@@ -534,7 +535,7 @@ def script_direct(name = None, token = None):
|
||||
if not ok:
|
||||
return share
|
||||
commands = []
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
status = file_stat(share['path'], file)
|
||||
commands.append('get_file "%s" "%s"'%(
|
||||
status['url'],
|
||||
@@ -695,22 +696,20 @@ def file_versionize(full_path):
|
||||
""" Move file to versioned with integer """
|
||||
file_dir = os.path.dirname(full_path)
|
||||
file_name = os.path.basename(full_path)
|
||||
basename, extension = os.path.splitext(file_name)
|
||||
version = 1
|
||||
while True:
|
||||
new_name = os.path.join(
|
||||
file_dir,
|
||||
secure_filename("%s.v%d%s"%(
|
||||
basename,
|
||||
version,
|
||||
extension
|
||||
))
|
||||
)
|
||||
if os.path.exists(new_name):
|
||||
version += 1
|
||||
else:
|
||||
break
|
||||
os.rename(full_path,new_name)
|
||||
new_name = file_name_version(full_path)
|
||||
new_path = os.path.join(
|
||||
file_dir,
|
||||
app.config['VERSION_FOLDER'],
|
||||
new_name
|
||||
)
|
||||
|
||||
if os.path.exists(new_path):
|
||||
return
|
||||
makedirs_rights(os.path.join(
|
||||
file_dir,
|
||||
app.config['VERSION_FOLDER']
|
||||
))
|
||||
os.rename(full_path, new_path)
|
||||
|
||||
|
||||
def get_share(name, require_auth = True, token = None):
|
||||
@@ -809,7 +808,7 @@ def zip_share(share):
|
||||
)
|
||||
)
|
||||
zf = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
|
||||
for file in iter_folder_files(share['path']):
|
||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
||||
fp = os.path.join(share['path'], file)
|
||||
if os.path.isdir(fp):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user