5
from pathlib import Path
6
from zipfile import ZipFile
26
"_bootstrap_external.py",
32
def remove_prefix(text, prefix):
33
if text.startswith(prefix):
34
return text[len(prefix) :]
38
def write_to_zip(file_path, strip_file_path, zf, prepend_str=""):
39
stripped_file_path = prepend_str + remove_prefix(file_path, strip_file_dir + "/")
40
path = Path(stripped_file_path)
41
if path.name in DENY_LIST:
43
zf.write(file_path, stripped_file_path)
48
parser = argparse.ArgumentParser(description="Zip py source")
49
parser.add_argument("paths", nargs="*", help="Paths to zip.")
51
"--install-dir", "--install_dir", help="Root directory for all output files"
56
help="The absolute directory we want to remove from zip",
61
help="A string to prepend onto all paths of a file in the zip",
64
parser.add_argument("--zip-name", "--zip_name", help="Output zip name")
66
args = parser.parse_args()
68
zip_file_name = args.install_dir + "/" + args.zip_name
69
strip_file_dir = args.strip_dir
70
prepend_str = args.prepend_str
71
zf = ZipFile(zip_file_name, mode="w")
73
for p in sorted(args.paths):
75
files = glob.glob(p + "/**/*.py", recursive=True)
76
for file_path in sorted(files):
79
file_path, strip_file_dir + "/", zf, prepend_str=prepend_str
82
write_to_zip(p, strip_file_dir + "/", zf, prepend_str=prepend_str)
85
if __name__ == "__main__":