upload_6.py 771 B

1234567891011121314151617
  1. def upload(filename):
  2. parsed_name = filename.split('/')
  3. dir = parsed_name[0]
  4. file = parsed_name[1].split('-')
  5. gz_filename = file[0] + '-archive'
  6. for el in file[1:]:
  7. gz_filename = gz_filename + '-' + el
  8. gz_filename = gz_filename + '.bz2'
  9. full_file_path = log_dir + dir + '/' + gz_filename
  10. print('Compressing: ' + log_dir + filename)
  11. with open(log_dir + filename, 'rb') as f_in, bz2.BZ2File(log_dir + dir + '/' + gz_filename, 'w') as f_out:
  12. shutil.copyfileobj(f_in, f_out)
  13. print('Removing: ' + log_dir + filename)
  14. os.remove(log_dir + filename)
  15. if encrypt(dir + '/' + gz_filename):
  16. upload_to_s3([dir + '/' + gz_filename + '.aes', ], bucket)
  17. os.remove(log_dir + dir + '/' + gz_filename + '.aes')