import zipfile import glob import os # TODO: should we include .pyc files? # TODO: add urwid source into the repo somewhere files = { '__main__.py': 'clients/urwid/main.py', 'nntp_client.py': 'clients/nntp_client.py', 'urwid': 'env/lib/python3.8/site-packages/urwid/*.py', } with open('bbj_demo', 'wb') as f: f.write(b"#!/usr/bin/env python3\n") with zipfile.ZipFile(f, 'w', compression=zipfile.ZIP_DEFLATED) as z: z.comment = b'BBJ' for name, source in files.items(): if '*' in source: dirname = name for path in sorted(glob.glob(source)): name = dirname + '/' + os.path.basename(path) z.write(path, name) else: z.write(source, name) try: mask = os.umask(0) os.umask(mask) except OSError: mask = 0 os.chmod(z.filename, 0o777&~mask)