All checks were successful
Python tests (make) / test (push) Successful in 12s
Created a python script to bundle the application and some bash scripts to pull and push packages from the registry.
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from datetime import datetime
|
|
import fnmatch
|
|
import os
|
|
import zipfile
|
|
|
|
|
|
class Packager:
|
|
def __init__(
|
|
self,
|
|
name="chess",
|
|
include_dirs=None,
|
|
ignore_patterns=None
|
|
):
|
|
|
|
timestamp = datetime.now().strftime("%Y%m%d%H%M")
|
|
filename = f"{timestamp}.{name}.zip"
|
|
self.outfile = os.path.join("./deploy/package", filename)
|
|
self.include_dirs = include_dirs or []
|
|
self.ignore_patterns = ignore_patterns or []
|
|
|
|
|
|
def create_package(self):
|
|
with zipfile.ZipFile(self.outfile, "w", zipfile.ZIP_DEFLATED) as z:
|
|
for d in self.include_dirs:
|
|
if not os.path.exists(d):
|
|
raise FileNotFoundError(f"Missing directory {d}")
|
|
for root, _, files in os.walk(d):
|
|
for fname in files:
|
|
rel_path = os.path.relpath(
|
|
os.path.join(root, fname),
|
|
start=os.path.dirname(d)
|
|
)
|
|
if self._is_ignored(rel_path):
|
|
continue
|
|
z.write(os.path.join(root, fname), rel_path)
|
|
|
|
print(f"[+] Package created: {self.outfile}")
|
|
os.system(f"unzip -l {self.outfile}")
|
|
|
|
|
|
def _is_ignored(self, path):
|
|
for pat in self.ignore_patterns:
|
|
if fnmatch.fnmatch(path, pat):
|
|
return True
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
packager = Packager(
|
|
name="chess",
|
|
include_dirs=[
|
|
"build",
|
|
"scripts",
|
|
"binding",
|
|
],
|
|
ignore_patterns=[
|
|
"*.pyc",
|
|
"__pycache__/*",
|
|
"*env*",
|
|
"*config*",
|
|
]
|
|
)
|
|
packager.create_package() |