2023-11-11 20:28:45 -05:00

34 lines
728 B
Python

import os
import sys
import zipfile
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(".xml") or file == "manifest.inf":
ziph.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join(path, '..')))
if len(sys.argv) > 1:
if sys.argv[1] == "build":
if len(sys.argv) > 2:
# usage: mocha lib build (folder) (filename.zip)
if len(sys.argv) > 3:
with zipfile.ZipFile(sys.argv[3], 'w', zipfile.ZIP_DEFLATED) as zipf:
zipdir(sys.argv[2], zipf)
else:
print ("usage: mocha lib build FILENAME")
else:
print ("usage: mocha lib build")
else:
print ("usage: mocha lib build")