mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 12:51:22 +04:00
[FL-3097] fbt, faploader: minimal app module implementation (#2420)
* fbt, faploader: minimal app module implementation * faploader, libs: moved API hashtable core to flipper_application * example: compound api * lib: flipper_application: naming fixes, doxygen comments * fbt: changed `requires` manifest field behavior for app extensions * examples: refactored plugin apps; faploader: changed new API naming; fbt: changed PLUGIN app type meaning * loader: dropped support for debug apps & plugin menus * moved applications/plugins -> applications/external * Restored x bit on chiplist_convert.py * git: fixed free-dap submodule path * pvs: updated submodule paths * examples: example_advanced_plugins.c: removed potential memory leak on errors * examples: example_plugins: refined requires * fbt: not deploying app modules for debug/sample apps; extra validation for .PLUGIN-type apps * apps: removed cdefines for external apps * fbt: moved ext app path definition * fbt: reworked fap_dist handling; f18: synced api_symbols.csv * fbt: removed resources_paths for extapps * scripts: reworked storage * scripts: reworked runfap.py & selfupdate.py to use new api * wip: fal runner * fbt: moved file packaging into separate module * scripts: storage: fixes * scripts: storage: minor fixes for new api * fbt: changed internal artifact storage details for external apps * scripts: storage: additional fixes and better error reporting; examples: using APP_DATA_PATH() * fbt, scripts: reworked launch_app to deploy plugins; moved old runfap.py to distfap.py * fbt: extra check for plugins descriptors * fbt: additional checks in emitter * fbt: better info message on SDK rebuild * scripts: removed requirements.txt * loader: removed remnants of plugins & debug menus * post-review fixes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from typing import final
|
||||
from flipper.app import App
|
||||
from flipper.storage import FlipperStorage
|
||||
from flipper.storage import FlipperStorage, FlipperStorageOperations
|
||||
from flipper.utils.cdc import resolve_port
|
||||
|
||||
import logging
|
||||
@@ -24,89 +24,47 @@ class Main(App):
|
||||
# logging
|
||||
self.logger = logging.getLogger()
|
||||
|
||||
# make directory with exist check
|
||||
def mkdir_on_storage(self, storage, flipper_dir_path):
|
||||
if not storage.exist_dir(flipper_dir_path):
|
||||
self.logger.debug(f'"{flipper_dir_path}" does not exist, creating')
|
||||
if not storage.mkdir(flipper_dir_path):
|
||||
self.logger.error(f"Error: {storage.last_error}")
|
||||
return False
|
||||
else:
|
||||
self.logger.debug(f'"{flipper_dir_path}" already exists')
|
||||
return True
|
||||
|
||||
# send file with exist check and hash check
|
||||
def send_file_to_storage(self, storage, flipper_file_path, local_file_path, force):
|
||||
exists = storage.exist_file(flipper_file_path)
|
||||
do_upload = not exists
|
||||
if exists:
|
||||
hash_local = storage.hash_local(local_file_path)
|
||||
hash_flipper = storage.hash_flipper(flipper_file_path)
|
||||
self.logger.debug(f"hash check: local {hash_local}, flipper {hash_flipper}")
|
||||
do_upload = force or (hash_local != hash_flipper)
|
||||
|
||||
if do_upload:
|
||||
self.logger.info(f'Sending "{local_file_path}" to "{flipper_file_path}"')
|
||||
if not storage.send_file(local_file_path, flipper_file_path):
|
||||
self.logger.error(f"Error: {storage.last_error}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def install(self):
|
||||
if not (port := resolve_port(self.logger, self.args.port)):
|
||||
return 1
|
||||
|
||||
storage = FlipperStorage(port)
|
||||
storage.start()
|
||||
if not os.path.isfile(self.args.manifest_path):
|
||||
self.logger.error("Error: manifest not found")
|
||||
return 2
|
||||
|
||||
manifest_path = pathlib.Path(os.path.abspath(self.args.manifest_path))
|
||||
manifest_name, pkg_name = manifest_path.parts[-1], manifest_path.parts[-2]
|
||||
|
||||
pkg_dir_name = self.args.pkg_dir_name or pkg_name
|
||||
update_root = "/ext/update"
|
||||
flipper_update_path = f"{update_root}/{pkg_dir_name}"
|
||||
|
||||
self.logger.info(f'Installing "{pkg_name}" from {flipper_update_path}')
|
||||
|
||||
try:
|
||||
if not os.path.isfile(self.args.manifest_path):
|
||||
self.logger.error("Error: manifest not found")
|
||||
return 2
|
||||
with FlipperStorage(port) as storage:
|
||||
storage_ops = FlipperStorageOperations(storage)
|
||||
storage_ops.mkpath(update_root)
|
||||
storage_ops.mkpath(flipper_update_path)
|
||||
storage_ops.recursive_send(
|
||||
flipper_update_path, manifest_path.parents[0]
|
||||
)
|
||||
|
||||
manifest_path = pathlib.Path(os.path.abspath(self.args.manifest_path))
|
||||
manifest_name, pkg_name = manifest_path.parts[-1], manifest_path.parts[-2]
|
||||
|
||||
pkg_dir_name = self.args.pkg_dir_name or pkg_name
|
||||
update_root = "/ext/update"
|
||||
flipper_update_path = f"{update_root}/{pkg_dir_name}"
|
||||
|
||||
self.logger.info(f'Installing "{pkg_name}" from {flipper_update_path}')
|
||||
# if not os.path.exists(self.args.manifest_path):
|
||||
# self.logger.error("Error: package not found")
|
||||
if not self.mkdir_on_storage(
|
||||
storage, update_root
|
||||
) or not self.mkdir_on_storage(storage, flipper_update_path):
|
||||
self.logger.error(f"Error: cannot create {storage.last_error}")
|
||||
return -2
|
||||
|
||||
for dirpath, dirnames, filenames in os.walk(manifest_path.parents[0]):
|
||||
for fname in filenames:
|
||||
self.logger.debug(f"Uploading {fname}")
|
||||
local_file_path = os.path.join(dirpath, fname)
|
||||
flipper_file_path = f"{flipper_update_path}/{fname}"
|
||||
if not self.send_file_to_storage(
|
||||
storage, flipper_file_path, local_file_path, False
|
||||
):
|
||||
self.logger.error(f"Error: {storage.last_error}")
|
||||
return -3
|
||||
|
||||
# return -11
|
||||
storage.send_and_wait_eol(
|
||||
f"update install {flipper_update_path}/{manifest_name}\r"
|
||||
)
|
||||
result = storage.read.until(storage.CLI_EOL)
|
||||
if not b"Verifying" in result:
|
||||
self.logger.error(f"Unexpected response: {result.decode('ascii')}")
|
||||
return -4
|
||||
return 3
|
||||
result = storage.read.until(storage.CLI_EOL)
|
||||
if not result.startswith(b"OK"):
|
||||
self.logger.error(result.decode("ascii"))
|
||||
return -5
|
||||
break
|
||||
return 0
|
||||
finally:
|
||||
storage.stop()
|
||||
return 4
|
||||
return 0
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
return 5
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user