Commit 83df08a1 authored by horkko's avatar horkko
Browse files

- Keep trace of local files in json format file for future bank update

parent 69b74a96
......@@ -115,6 +115,17 @@ def migrate_bank(cur, bank, history=False):
if prod['logfile'] and os.path.exists(prod['logfile']):
b.banks.update({'name':, '': session_id},
{'$set': {'sessions.$.log_file': prod['logfile']}})
# Downloaded and local files (created by 'bank.save_session')
# remove as created empty due to 'save_sessions' call
cache_dir = b.config.get('cache.dir')
download_file = os.path.join(cache_dir, 'files_' + str(session_id))
local_file = os.path.join(cache_dir, 'local_files_' + str(session_id))
if os.path.isfile(download_file):
if os.path.isfile(local_file):
# Due to the way save_session set also the production, to exclude last session
# from the production entries, we need to loop over each production entries
if history:
......@@ -143,28 +154,31 @@ def migrate_bank(cur, bank, history=False):
listing = "{\"files\": [], \"name\": \"" + fileExtension.replace('.', '') + "\"," + listing + "}"
if root_file.startswith('flat'):
if root_file.startswith('flat') and session_id not in not_prod:
flat_dir = os.path.join(prod['path'], root_file)
if not os.path.exists(flat_dir):
print("[%s] [WARN] Can't list %s/flat directory. Skipping ..." % (, prod['path']))
flat_files = os.listdir(os.path.join(prod['path'], 'flat'))
flat_files = os.listdir(flat_dir)
files_info = []
for flat_file in flat_files:
file_info = os.stat(flat_file)
file_info = os.stat(os.path.join(flat_dir, flat_file))
except IOError as err:
print("[%s][WARN] Failed to get info about %s" % (,str(file_info)))
print("[%s][WARN] Failed to stat get info from %s: %s" % (,str(file_info), str(err)))
ctime = datetime.datetime.fromtimestamp(flat_file[9])
ctime = datetime.datetime.fromtimestamp(file_info[9])
files_info.append({'name': flat_file, 'save_as': flat_file,
'user': flat_file[4], 'group': flat_file[5],
'user': file_info[4], 'group': file_info[5],
'year': ctime.year, 'day':, 'month': ctime.month,
'root': prod['remotedir'], 'url': prod['protocol'] + '://' + prod['server'],
'size': flat_file[6]})
cache_dir = b.config.get('cache.dir')
local_files = open(os.path.join(cache_dir, 'files_' + str(session_id)), 'w')
'size': file_info[6]})
if len(files_info) > 0:
# Saved files
local_file = open(local_file, 'w')
# Current link?
pathelts = prod['path'].split('/')
del pathelts[-1]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment