mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-18 08:43:10 +00:00
ebc2b66372
* fbt: split sdk management code * scripts: fixed import handling * fbt: sdk: reformatted paths * scrips: dist: bundling libs as a build artifact * fbt: sdk: better path management * typo fix * fbt: sdk: minor path handling fixes * toolchain: fixed windows toolchain download * fbt: minor refactorin * fbt: moved sdk management code to extapps.scons * fbt: fixed sdk symbols header path; disabled -fstack-usage * fbt: changed pathing for .py scripts * fbt: changed SDK_HEADERS pathing; added libusb to SDK; added icon_i.h to SDK; added hw target to SDK meta * fbt: added libusb headers to SDK * picopass: include cleanup; api: added subghz/registry.h; api: added mbedtls to exported headers * picopass: fixed formatting * fbt: fixed COPRO_ASSETS_SCRIPT * sdk: added basic infrared apis * toolchain: added ufbt to list of legal fbtenv callers; updated error messages * fbt: changed manifest collection & icon processing code * fbt: simpler srcdir lookup * toolchain: path management fixes; fbt: fixes for fap private libs paths * scripts: toolchain: reworked download on Windows * toolchain: v17 * scripts: added colorlog for logging * Github: fix unit tests Co-authored-by: あく <alleteam@gmail.com>
67 lines
2 KiB
Python
67 lines
2 KiB
Python
import logging
|
|
import argparse
|
|
import sys
|
|
import colorlog
|
|
|
|
|
|
class App:
|
|
def __init__(self, no_exit=False):
|
|
# Argument Parser
|
|
self.no_exit = no_exit
|
|
self.parser = argparse.ArgumentParser()
|
|
self.parser.add_argument("-d", "--debug", action="store_true", help="Debug")
|
|
# Logging
|
|
self.logger = colorlog.getLogger()
|
|
# Application specific initialization
|
|
self.init()
|
|
|
|
def __call__(self, args=None, skip_logger_init=False):
|
|
self.args, self.other_args = self.parser.parse_known_args(args=args)
|
|
# configure log output
|
|
# if skip_logger_init:
|
|
self.log_level = logging.DEBUG if self.args.debug else logging.INFO
|
|
self.logger.setLevel(self.log_level)
|
|
if not self.logger.hasHandlers():
|
|
self.handler = colorlog.StreamHandler(sys.stdout)
|
|
self.handler.setLevel(self.log_level)
|
|
self.formatter = colorlog.ColoredFormatter(
|
|
"%(log_color)s%(asctime)s [%(levelname)s] %(message)s",
|
|
log_colors={
|
|
"DEBUG": "cyan",
|
|
# "INFO": "white",
|
|
"WARNING": "yellow",
|
|
"ERROR": "red",
|
|
"CRITICAL": "red,bg_white",
|
|
},
|
|
)
|
|
self.handler.setFormatter(self.formatter)
|
|
self.logger.addHandler(self.handler)
|
|
|
|
# execute requested function
|
|
self.before()
|
|
return_code = self.call()
|
|
self.after()
|
|
if isinstance(return_code, int):
|
|
return self._exit(return_code)
|
|
else:
|
|
self.logger.error(f"Missing return code")
|
|
return self._exit(255)
|
|
|
|
def _exit(self, code):
|
|
if self.no_exit:
|
|
return code
|
|
exit(code)
|
|
|
|
def call(self):
|
|
if "func" not in self.args:
|
|
self.parser.error("Choose something to do")
|
|
return self.args.func()
|
|
|
|
def init(self):
|
|
raise Exception("init() is not implemented")
|
|
|
|
def before(self):
|
|
pass
|
|
|
|
def after(self):
|
|
pass
|