Commit cc8cd449 authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-s/compress-all-sequences' into 'dev'

scripts/ Add a simulate option

See merge request !739
parents 32c97b7b 912c3e47
Pipeline #152504 failed with stages
in 10 minutes and 24 seconds
......@@ -2,6 +2,7 @@ from __future__ import print_function
import defs
import os.path
import base64
import sys
def can_be_compressed(original_filename, server_filename):
server_ext = os.path.splitext(server_filename)[1][1:].lower()
......@@ -12,26 +13,37 @@ def can_be_compressed(original_filename, server_filename):
and not os.path.islink(server_filename)
def compress_all_sequences():
def compress_all_sequences(simulate):
sequences = db(db.sequence_file).select()
compressed = []
for seq in sequences:
if seq.data_file is not None:
data_file = defs.DIR_SEQUENCES+seq.data_file
if can_be_compressed(seq.filename, data_file):
os.system('gzip -9 '+data_file)
if not simulate:
os.system('gzip -9 '+data_file)
new_filename = seq.filename+".gz"
new_data_filename = get_new_uploaded_filename(data_file, new_filename)
os.rename(data_file+".gz", new_data_filename)
log.debug('Compressed '+new_data_filename)
update_name_of_sequence_file(, new_filename, new_data_filename)
if not simulate:
os.rename(data_file+".gz", new_data_filename)
log.debug('Compressed {} {} -> {}'.format("(simulate) " if simulate else '', data_file, new_data_filename))
if not simulate:
update_name_of_sequence_file(, new_filename, new_data_filename)
compressed.append({'data_file': new_data_filename, 'original': new_filename, 'id':})
return compressed
if __name__ == "__main__":
compressed = compress_all_sequences()
simulate = False
if len(sys.argv) > 1:
if sys.argv[1] == '-h':
print("Usage: {} [-s]\n\n-s: just simulate".format(sys.argv[0]))
elif sys.argv[1] == "-s":
simulate = True
if simulate:
print("Simulating mode")
compressed = compress_all_sequences(simulate)
for elements in compressed:
print ("Compressed %s %s %d" % (elements['data_file'], elements['original'], elements['id']))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment