#coding: utf-8
"""Throwaway script.
Usage:
test.py
test.py zip <project>...
"""
import os, sys
from docopt import docopt
import zipfile
import re
#%%
_dir = os.path.dirname(__file__)
if __name__ == '__main__':
args = docopt(__doc__)
if args['zip']:
ignore_files = [r'\.pyc']
for path in args['<project>']:
zip_path = os.path.join(_dir, 'test_projects',
os.path.basename(path) + '.zip')
with zipfile.ZipFile(zip_path, 'w') as _zip:
# with zipfile.PyZipFile(zip_path, 'w') as _zip:
# for name in os.listdir(path):
# filepath = os.path.join(path, name)
# if os.path.isfile(filepath) and not name.endswith('.py'):
# continue
# _zip.writepy(filepath)
for current_path, dirs, files in os.walk(path):
for name in files:
if any(re.search(regexp, name) for regexp in ignore_files):
continue
relpath = os.path.relpath(current_path, path)
_zip.write(os.path.join(current_path, name),
os.path.join(relpath, name))