24 parser = argparse.ArgumentParser(
25 description=
'Export CONSTANT value with given file format.')
26 parser.add_argument(
'-c',
30 help=
'Constant name to export')
36 choices=[
'cfg',
'txt'],
38 'File format to export. The created cfg file contains CONSTANT under the one-optimize section.'
43 help=
'Exports the rest of the options except for the given constant')
44 parser.add_argument(
'-o',
48 help=
'Path to output')
50 args = parser.parse_args()
52 if not hasattr(CONSTANT, args.constant):
53 raise NameError(
'Not found given constant name')
56 constant_to_exclude = getattr(CONSTANT, args.constant)
57 constant_to_export = []
58 for opt
in CONSTANT.OPTIMIZATION_OPTS:
59 if opt[0]
in constant_to_exclude:
61 constant_to_export.append(opt[0])
63 constant_to_export = getattr(CONSTANT, args.constant)
65 if args.format ==
'cfg':
66 SECTION_TO_EXPORT =
'one-optimize'
67 config = configparser.ConfigParser()
68 config[SECTION_TO_EXPORT] = dict()
69 for constant
in constant_to_export:
70 config[SECTION_TO_EXPORT][constant] =
'True'
72 with open(args.output_path,
'w')
as f:
75 if args.format ==
'txt':
76 with open(args.output_path,
'w')
as f:
77 for constant
in constant_to_export:
78 f.write(f
"{constant}\n")