new file versioning policy and manager. be sure to add version_folder in your conf
This commit is contained in:
@@ -29,6 +29,36 @@ def file_date_human(num):
|
||||
).strftime(app.config['DATE_FORMAT'])
|
||||
|
||||
|
||||
def file_name_version(full_path):
|
||||
""" New name versioned with date of the file """
|
||||
file_dir = os.path.dirname(full_path)
|
||||
file_name = os.path.basename(full_path)
|
||||
file_time = os.stat(full_path).st_mtime
|
||||
time_formatted = datetime.fromtimestamp(
|
||||
file_time
|
||||
).strftime('%Y%m%d_%H%M%S')
|
||||
|
||||
new_name = '%s.%s'%(
|
||||
time_formatted,
|
||||
file_name
|
||||
)
|
||||
return new_name
|
||||
|
||||
|
||||
def version_date(full_path):
|
||||
""" Date of versioned file """
|
||||
file_dir = os.path.dirname(full_path)
|
||||
file_name = os.path.basename(full_path)
|
||||
try:
|
||||
return datetime.strptime(
|
||||
file_name[0:15],
|
||||
'%Y%m%d_%H%M%S'
|
||||
)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def file_stat(path, filename):
|
||||
full_path = os.path.join(path, filename)
|
||||
s = os.stat(full_path)
|
||||
@@ -110,9 +140,12 @@ def is_valid_url(url, qualifying = None):
|
||||
for qualifying_attr in qualifying])
|
||||
|
||||
|
||||
def iter_folder_files(path, recursive = True):
|
||||
def iter_folder_files(path, recursive = True, version_folder = None):
|
||||
if recursive:
|
||||
for dirpath, dirnames, filenames in os.walk(path, topdown = False):
|
||||
path_list = dirpath.split(os.sep)
|
||||
if path_list[-1] == version_folder:
|
||||
continue
|
||||
relative_path = os.path.relpath(dirpath,path)
|
||||
dirnames.sort()
|
||||
if "/." in relative_path:
|
||||
|
||||
Reference in New Issue
Block a user