help='Select flavour (default is "generic")')
parser.add_argument('--config', '-c', action='store',
help='Select a specific config option')
- parser.add_argument('--note', '-n', action='store',
- help='Write a specific note to a config option in annotations (used with --write)')
-
- ga = parser.add_argument_group(title='Action').add_mutually_exclusive_group(required=True)
+ parser.add_argument('--query', '-q', action='store_true',
+ help='Query annotations')
+ ga = parser.add_argument_group(title='Action').add_mutually_exclusive_group(required=False)
ga.add_argument('--write', '-w', action='store',
metavar='VALUE', dest='value',
help='Set a specific config value in annotations (use \'null\' to remove)')
- ga.add_argument('--query', '-q', action='store_true',
- help='Query annotations')
+ ga.add_argument('--note', '-n', action='store',
+ help='Write a specific note to a config option in annotations')
ga.add_argument('--export', '-e', action='store_true',
help='Convert annotations to .config format')
ga.add_argument('--import', '-i', action='store',
res = a.search_config(config=args.config, arch=args.arch, flavour=args.flavour)
print(json.dumps(res, indent=4))
+def do_note(args):
+ if args.config is None:
+ arg_fail('error: --note requires --config')
+
+ # Set the note in annotations
+ a = Annotation(args.file)
+ a.set(args.config, note=args.note)
+
+ # Save back to annotations
+ a.save(args.file)
+
+ # Query and print back the value
+ res = a.search_config(config=args.config)
+ print(json.dumps(res, indent=4))
+
def do_write(args):
if args.config is None:
arg_fail('error: --write requires --config')
def main():
args = _ARGPARSER.parse_args()
autodetect_annotations(args)
- if args.query:
- do_query(args)
- elif args.value:
+ if args.value:
do_write(args)
+ elif args.note:
+ do_note(args)
elif args.export:
do_export(args)
elif args.import_file:
do_update(args)
elif args.check_file:
do_check(args)
+ else:
+ do_query(args)
if __name__ == '__main__':
main()
def set(self, config : str, arch: str = None, flavour: str = None,
value : str = None, note : str = None):
- if config not in self.config:
- self.config[config] = { 'policy': {} }
- if arch is not None:
- if flavour is not None:
- flavour = f'{arch}-{flavour}'
+ if value is not None:
+ if config not in self.config:
+ self.config[config] = { 'policy': {} }
+ if arch is not None:
+ if flavour is not None:
+ flavour = f'{arch}-{flavour}'
+ else:
+ flavour = arch
+ self.config[config]['policy'][flavour] = value
else:
- flavour = arch
- self.config[config]['policy'][flavour] = value
- else:
- for arch in self.arch:
- self.config[config]['policy'][arch] = value
+ for arch in self.arch:
+ self.config[config]['policy'][arch] = value
if note is not None:
self.config[config]['note'] = "'" + note.replace("'", '') + "'"