-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_pack.py
28 lines (23 loc) · 958 Bytes
/
select_pack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Callable
from pathlib import Path
import os, zipfile
import click
def filter_pack(folder: Path, filter: Callable[[Path], bool]):
with zipfile.ZipFile(folder.with_suffix('.zip'), 'w') as zipf:
for root, dirs, files in os.walk(folder):
for file in files:
file_path = Path(os.path.join(root, file))
rel_path = file_path.relative_to(folder)
if filter(rel_path):
zipf.write(file_path, rel_path)
def silly_rule(fpath: Path) -> bool:
if fpath.stem.removeprefix('lib') == 'SillyFramework': return True
if fpath.stem == 'SillyGame' and fpath.suffix != '.log': return True
if fpath.parts[0] == 'res' and fpath.suffix in {'.jpg', '.png'}: return True
return False
if __name__ == '__main__':
@click.command()
@click.argument('folder')
def main(folder: str):
filter_pack(Path(folder).absolute(), silly_rule)
main()