flipperzero-firmware/scripts/flipper/app.py
あく 2751440193
[FL-1970, FL-1965, FL-1872, FL-1689] Python framework, Scripts and fixes (#779)
* Scripts: add flipper lib, migrate ob to flipper lib, update ob.data
* Makefile: speedup build with phony target for .d files
* FuriHal,U8G2: full MGG display support and ERC contrast tuning.
* Desktop: fix dolphin rename artifact.
* Scripts: port otp.py to flipper scripting lib.
* Scripts: add wipe and core1 flashing to flash.py, remove obsolete shell scripts
* Scripts: replace core1 flashing script with global makefile.
* Scripts: final touches and migration to python. Root Makefile for everything.
2021-10-21 15:24:34 +03:00

48 lines
1.4 KiB
Python

import logging
import argparse
import sys
import os
class App:
def __init__(self):
# Argument Parser
self.parser = argparse.ArgumentParser()
self.parser.add_argument("-d", "--debug", action="store_true", help="Debug")
# Logging
self.logger = logging.getLogger()
# Application specific initialization
self.init()
def __call__(self):
self.args = self.parser.parse_args()
if "func" not in self.args:
self.parser.error("Choose something to do")
# configure log output
self.log_level = logging.DEBUG if self.args.debug else logging.INFO
self.logger.setLevel(self.log_level)
self.handler = logging.StreamHandler(sys.stdout)
self.handler.setLevel(self.log_level)
self.formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
# execute requested function
self.before()
return_code = self.args.func()
self.after()
if isinstance(return_code, int):
exit(return_code)
else:
self.logger.error(f"Missing return code")
exit(255)
def init(self):
raise Exception("init() is not implemented")
def before(self):
pass
def after(self):
pass