mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Merge branch 'fz-dev' into dev
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from flipper.app import App
|
||||
from os.path import join, exists
|
||||
from os import makedirs, environ
|
||||
from os.path import join, exists, relpath
|
||||
from os import makedirs, walk, environ
|
||||
from update import Main as UpdateMain
|
||||
import shutil
|
||||
import zipfile
|
||||
import tarfile
|
||||
|
||||
|
||||
class ProjectDir:
|
||||
@@ -17,6 +19,8 @@ class ProjectDir:
|
||||
|
||||
|
||||
class Main(App):
|
||||
DIST_FILE_PREFIX = "flipper-z-"
|
||||
|
||||
def init(self):
|
||||
self.subparsers = self.parser.add_subparsers(help="sub-command help")
|
||||
|
||||
@@ -45,9 +49,13 @@ class Main(App):
|
||||
def get_project_filename(self, project, filetype):
|
||||
# Temporary fix
|
||||
project_name = project.project
|
||||
if project_name == "firmware" and filetype != "elf":
|
||||
project_name = "full"
|
||||
return f"flipper-z-{self.target}-{project_name}-{self.args.suffix}.{filetype}"
|
||||
if project_name == "firmware":
|
||||
if filetype == "zip":
|
||||
project_name = "sdk"
|
||||
elif filetype != "elf":
|
||||
project_name = "full"
|
||||
|
||||
return f"{self.DIST_FILE_PREFIX}{self.target}-{project_name}-{self.args.suffix}.{filetype}"
|
||||
|
||||
def get_dist_filepath(self, filename):
|
||||
return join(self.output_dir_path, filename)
|
||||
@@ -56,10 +64,28 @@ class Main(App):
|
||||
obj_directory = join("build", project.dir)
|
||||
|
||||
for filetype in ("elf", "bin", "dfu", "json"):
|
||||
shutil.copyfile(
|
||||
join(obj_directory, f"{project.project}.{filetype}"),
|
||||
self.get_dist_filepath(self.get_project_filename(project, filetype)),
|
||||
)
|
||||
if exists(src_file := join(obj_directory, f"{project.project}.{filetype}")):
|
||||
shutil.copyfile(
|
||||
src_file,
|
||||
self.get_dist_filepath(
|
||||
self.get_project_filename(project, filetype)
|
||||
),
|
||||
)
|
||||
if exists(sdk_folder := join(obj_directory, "sdk")):
|
||||
with zipfile.ZipFile(
|
||||
self.get_dist_filepath(self.get_project_filename(project, "zip")),
|
||||
"w",
|
||||
zipfile.ZIP_DEFLATED,
|
||||
) as zf:
|
||||
for root, dirs, files in walk(sdk_folder):
|
||||
for file in files:
|
||||
zf.write(
|
||||
join(root, file),
|
||||
relpath(
|
||||
join(root, file),
|
||||
sdk_folder,
|
||||
),
|
||||
)
|
||||
|
||||
def copy(self):
|
||||
self.projects = dict(
|
||||
@@ -103,9 +129,8 @@ class Main(App):
|
||||
)
|
||||
|
||||
if self.args.version:
|
||||
bundle_dir = join(
|
||||
self.output_dir_path, f"{self.target}-update-{self.args.suffix}"
|
||||
)
|
||||
bundle_dir_name = f"{self.target}-update-{self.args.suffix}"
|
||||
bundle_dir = join(self.output_dir_path, bundle_dir_name)
|
||||
bundle_args = [
|
||||
"generate",
|
||||
"-d",
|
||||
@@ -131,9 +156,6 @@ class Main(App):
|
||||
)
|
||||
)
|
||||
bundle_args.extend(self.other_args)
|
||||
self.logger.info(
|
||||
f"Use this directory to self-update your Flipper:\n\t{bundle_dir}"
|
||||
)
|
||||
log_custom_fz_name = (
|
||||
environ.get("CUSTOM_FLIPPER_NAME", None)
|
||||
or ""
|
||||
@@ -143,7 +165,23 @@ class Main(App):
|
||||
f"Flipper Custom Name is set:\n\tName: {log_custom_fz_name} : length - {len(log_custom_fz_name)} chars"
|
||||
)
|
||||
|
||||
return UpdateMain(no_exit=True)(bundle_args)
|
||||
if (bundle_result := UpdateMain(no_exit=True)(bundle_args)) == 0:
|
||||
self.logger.info(
|
||||
f"Use this directory to self-update your Flipper:\n\t{bundle_dir}"
|
||||
)
|
||||
|
||||
# Create tgz archive
|
||||
with tarfile.open(
|
||||
join(
|
||||
self.output_dir_path,
|
||||
f"{self.DIST_FILE_PREFIX}{bundle_dir_name}.tgz",
|
||||
),
|
||||
"w:gz",
|
||||
compresslevel=9,
|
||||
) as tar:
|
||||
tar.add(bundle_dir, arcname=bundle_dir_name)
|
||||
|
||||
return bundle_result
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user