2021-10-26 15:33:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-11-18 08:46:47 +00:00
|
|
|
from flipper.app import App
|
2021-10-26 15:33:38 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
2021-11-18 08:46:47 +00:00
|
|
|
class Main(App):
|
|
|
|
def init(self):
|
|
|
|
self.subparsers = self.parser.add_subparsers(help="sub-command help")
|
|
|
|
|
|
|
|
# generate
|
|
|
|
self.parser_generate = self.subparsers.add_parser(
|
|
|
|
"generate", help="Generate JSON meta file"
|
|
|
|
)
|
|
|
|
self.parser_generate.add_argument("-p", dest="project", required=True)
|
|
|
|
self.parser_generate.add_argument(
|
|
|
|
"-DBUILD_DATE", dest="build_date", required=True
|
|
|
|
)
|
|
|
|
self.parser_generate.add_argument("-DGIT_COMMIT", dest="commit", required=True)
|
|
|
|
self.parser_generate.add_argument("-DGIT_BRANCH", dest="branch", required=True)
|
|
|
|
self.parser_generate.add_argument(
|
|
|
|
"-DTARGET", dest="target", type=int, required=True
|
|
|
|
)
|
|
|
|
self.parser_generate.set_defaults(func=self.generate)
|
|
|
|
|
|
|
|
# merge
|
|
|
|
self.parser_merge = self.subparsers.add_parser(
|
|
|
|
"merge", help="Merge JSON meta files"
|
|
|
|
)
|
|
|
|
self.parser_merge.add_argument(
|
|
|
|
"-i", dest="input", action="append", nargs="+", required=True
|
|
|
|
)
|
|
|
|
self.parser_merge.set_defaults(func=self.merge)
|
|
|
|
|
|
|
|
def generate(self):
|
2021-10-26 15:33:38 +00:00
|
|
|
meta = {}
|
|
|
|
for k, v in vars(self.args).items():
|
2021-12-01 10:21:26 +00:00
|
|
|
if k in ["project", "func", "debug"]:
|
2021-10-26 15:33:38 +00:00
|
|
|
continue
|
|
|
|
if isinstance(v, str):
|
|
|
|
v = v.strip('"')
|
|
|
|
meta[self.args.project + "_" + k] = v
|
|
|
|
|
|
|
|
print(json.dumps(meta, indent=4))
|
2021-11-18 08:46:47 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def merge(self):
|
|
|
|
full = {}
|
|
|
|
for path in self.args.input[0]:
|
|
|
|
with open(path, mode="r") as file:
|
|
|
|
dict = json.loads(file.read())
|
2021-11-30 17:46:54 +00:00
|
|
|
full.update(dict)
|
2021-11-18 08:46:47 +00:00
|
|
|
|
|
|
|
print(json.dumps(full, indent=4))
|
|
|
|
return 0
|
2021-10-26 15:33:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
Main()()
|