Skip to content

Commit

Permalink
start adding gather/filter/optimize pipeline as #34
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Jul 19, 2022
1 parent fdbf190 commit 65a801d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pygbag/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
__version__ = "0.1.2"

try:
sched_yield
except:
__import__("builtins").sched_yield = lambda : None
6 changes: 6 additions & 0 deletions pygbag/filtering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@



def filter(*argv, **kw):
pass

16 changes: 16 additions & 0 deletions pygbag/gathering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from os import walk
from pathlib import Path

class Error(Exception):
pass


def gather(root:Path,*kw):
if root.is_file():
if root.name == "main.py":
raise Error("project must be a folder or an archive")


for current, dirnames, filenames in walk(root):
print(current, len(dirnames), len(filenames))
yield
2 changes: 2 additions & 0 deletions pygbag/optimizing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def optimize(*argv, **kw):
pass
18 changes: 15 additions & 3 deletions pygbag/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import zipfile
from pathlib import Path

from .gathering import gather
from .filtering import filter
from .optimizing import optimize

"""
pngquant -f --ext -pygbag.png --quality 40 $(find|grep png$)
Expand Down Expand Up @@ -64,7 +68,8 @@ def pack_files(zf, parent, zfolders, newpath):
continue

if subdir == "venv":
print("""
print(
"""
===================================================================
Not packing venv. if non stdlib pure python modules were used
they should be in game folder not venv install ( for now ).
Expand Down Expand Up @@ -121,7 +126,6 @@ def pack_files(zf, parent, zfolders, newpath):
if f.endswith(".gitignore"):
continue


if Path(f).is_symlink():
print("sym", f)

Expand All @@ -136,7 +140,7 @@ def pack_files(zf, parent, zfolders, newpath):

ext = f.rsplit(".", 1)[-1].lower()

if ext in ["pyc", "pyx", "pyd", "pyi","exe"]:
if ext in ["pyc", "pyx", "pyd", "pyi", "exe"]:
continue

zpath = list(zfolders)
Expand Down Expand Up @@ -171,6 +175,14 @@ def archive(apkname, target_folder, build_dir=None):
if build_dir:
apkname = build_dir.joinpath(apkname).as_posix()

files = []
for f in gather(target_folder):
files.append(f)
sched_yield()




try:
with zipfile.ZipFile(
apkname, mode="x", compression=zipfile.ZIP_DEFLATED, compresslevel=9
Expand Down
2 changes: 2 additions & 0 deletions pygbag/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ def get(url, path):

finally:
if error:
print("WARNING: web.get", e)
raise error

if data_fileNone:
return Path(data_file), header
raise Exception(f"cannot cache {url} to {path}")


if __name__ == "__main__":
fixcert()

0 comments on commit 65a801d

Please sign in to comment.