Repository navigation
Expand file tree
/
Copy pathdev.py
More file actions
146 lines (105 loc) · 3.21 KB
/
Copy pathdev.py
File metadata and controls
146 lines (105 loc) · 3.21 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
"""
Development commands for Boring Gorilla.
"""
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
def run(*args: str) -> None:
"""Execute a command from the project root."""
subprocess.run(args, cwd=ROOT, check=True)
def launch() -> None:
"""Launch the Boring Gorilla application."""
run(sys.executable, "BoringGorilla.py")
def design() -> None:
"""Generate Python files from Qt Designer UI files."""
ui_files = (
"BoringGorilla_design",
"Preferences_design",
)
for name in ui_files:
source = Path("ui_design") / f"{name}.ui"
target = ROOT / f"{name}.py"
run("pyuic6", str(source), "-o", str(target))
print(f"Generated: {target.name}")
print("All design files generated successfully.")
def build() -> None:
"""Build the executable."""
run("cxfreeze", "build")
print("Build finished.")
def clean_build() -> None:
"""Remove build subdirectories while preserving files in build dir."""
build_dir = ROOT / "build"
if not build_dir.is_dir():
return
for path in build_dir.iterdir():
if path.is_dir():
shutil.rmtree(path)
print(f"Removed directory: {path.relative_to(ROOT)}")
def clean() -> None:
"""Remove build artifacts, cache files, and MANIFEST."""
directories = (
ROOT / "__pycache__",
ROOT / "BoringGorilla.egg-info",
ROOT / "dist",
)
files = (ROOT / "MANIFEST",)
for path in directories:
if path.is_dir():
shutil.rmtree(path)
print(f"Removed directory: {path.relative_to(ROOT)}")
clean_build()
for path in files:
if path.is_file():
path.unlink()
print(f"Removed file: {path.relative_to(ROOT)}")
print("Clean finished.")
def cleanall() -> None:
"""Remove build artifacts, generated design files, and config.ini."""
clean()
files = (
ROOT / "BoringGorilla_design.py",
ROOT / "Preferences_design.py",
ROOT / "config.ini",
)
for path in files:
if path.is_file():
path.unlink()
print(f"Removed file: {path.relative_to(ROOT)}")
print("Cleanall finished.")
def main() -> None:
"""Display help or execute the requested development command."""
commands = {
"launch": launch,
"design": design,
"build": build,
"clean": clean,
"cleanall": cleanall,
}
parser = argparse.ArgumentParser(
description="Development commands for Boring Gorilla.",
epilog="Available commands:",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
subparsers = parser.add_subparsers(
title="commands",
dest="command",
metavar="<command>",
)
for name, func in commands.items():
subparser = subparsers.add_parser(
name,
help=func.__doc__,
description=func.__doc__,
)
subparser.set_defaults(func=func)
args = parser.parse_args()
if not args.command:
parser.print_help()
return
args.func()
if __name__ == "__main__":
main()