Advertisement
go6odn28

zip_file

Jun 30th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import os
  2. import zipfile
  3. import datetime
  4.  
  5. def pack():
  6.     # Remove old archive
  7.     for item in os.listdir('.'):
  8.         if item.endswith(".zip"):
  9.             os.remove(item)
  10.     dt = datetime.datetime.now().strftime('%H-%M_%d.%m.%y')
  11.     with zipfile.ZipFile(f'submission-{dt}.zip', 'w', zipfile.ZIP_DEFLATED) as zipf:
  12.         for root, dirs, files in os.walk(os.getcwd()):
  13.             # Skip the .venv directory
  14.             if '.venv' in root.split(os.sep):
  15.                 continue
  16.             for file in files:
  17.                 file_path = os.path.join(root, file)
  18.                 archive_path = os.path.relpath(file_path, '.')
  19.                 current_dir = root.split(os.sep)[-1]
  20.                 if file in ['requirements.txt', 'manage.py', 'caller.py']\
  21.                         or current_dir in ['main_app', 'orm_skeleton', 'migrations']:
  22.                     zipf.write(file_path, archive_path)
  23.  
  24.     print('Submission created!')
  25.  
  26. if __name__ == '__main__':
  27.     pack()
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement