build: добавлена возможность создания архива с приложением через команду --archive
This commit is contained in:
@@ -8,7 +8,49 @@ PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|||||||
ENTRY_POINT = os.path.join(PROJECT_ROOT, "src", "mind_reader", "app.py")
|
ENTRY_POINT = os.path.join(PROJECT_ROOT, "src", "mind_reader", "app.py")
|
||||||
|
|
||||||
|
|
||||||
def build():
|
def make_archive(source_dir, output_archive):
|
||||||
|
seven_zip_cmd = shutil.which("7z") or shutil.which("7za")
|
||||||
|
|
||||||
|
default_7z_paths = [
|
||||||
|
r"C:\Program Files\7-Zip\7z.exe",
|
||||||
|
r"C:\Program Files (x86)\7-Zip\7z.exe",
|
||||||
|
]
|
||||||
|
|
||||||
|
for path in default_7z_paths:
|
||||||
|
if os.path.exists(path):
|
||||||
|
seven_zip_cmd = path
|
||||||
|
break
|
||||||
|
|
||||||
|
if seven_zip_cmd:
|
||||||
|
print(f"\nCreating 7z archive using {seven_zip_cmd}...")
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
seven_zip_cmd,
|
||||||
|
"a",
|
||||||
|
"-t7z",
|
||||||
|
"-mx=9",
|
||||||
|
"-m0=lzma2",
|
||||||
|
output_archive,
|
||||||
|
os.path.join(source_dir, "*"),
|
||||||
|
]
|
||||||
|
|
||||||
|
result = subprocess.run(cmd)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
print(f"Archive successfully created: {output_archive}")
|
||||||
|
else:
|
||||||
|
print("Error while archiving with 7-Zip!")
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("\n7-Zip not found in system! Falling back to standard zip...")
|
||||||
|
zip_base = output_archive.replace(".7z", "")
|
||||||
|
archive_path = shutil.make_archive(
|
||||||
|
base_name=zip_base, format="zip", root_dir=source_dir
|
||||||
|
)
|
||||||
|
print(f"Standard ZIP created: {archive_path}")
|
||||||
|
|
||||||
|
|
||||||
|
def build(archive=False):
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable,
|
sys.executable,
|
||||||
"-m",
|
"-m",
|
||||||
@@ -29,9 +71,16 @@ def build():
|
|||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
dist_path = os.path.join(PROJECT_ROOT, "dist", "MindReader")
|
dist_path = os.path.join(PROJECT_ROOT, "dist", "MindReader")
|
||||||
print("\nBuild completed!")
|
print("\nBuild completed!")
|
||||||
print(f"{dist_path}")
|
print(f"App dir: {dist_path}")
|
||||||
|
|
||||||
|
if archive:
|
||||||
|
archive_target = os.path.join(
|
||||||
|
PROJECT_ROOT, "dist", "MindReader-win64.7z"
|
||||||
|
)
|
||||||
|
make_archive(dist_path, archive_target)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("\nError!")
|
print("\nError during build!")
|
||||||
|
|
||||||
|
|
||||||
def clean():
|
def clean():
|
||||||
@@ -59,9 +108,10 @@ def clean():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--clean-only", action="store_true")
|
parser.add_argument("--clean-only", action="store_true")
|
||||||
|
parser.add_argument("--archive", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.clean_only:
|
if args.clean_only:
|
||||||
clean()
|
clean()
|
||||||
else:
|
else:
|
||||||
build()
|
build(archive=args.archive)
|
||||||
|
|||||||
Reference in New Issue
Block a user