def publisher_publish_main(): """Execute the kcidb-mq-publisher-publish command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = \ 'kcidb-mq-publisher-publish - ' \ 'Publish with a Kernel CI report publisher, print publishing IDs' parser = misc.ArgumentParser(description=description) parser.add_argument( '-p', '--project', help='ID of the Google Cloud project with the message queue', required=True) parser.add_argument('-t', '--topic', help='Name of the message queue topic to publish to', required=True) args = parser.parse_args() publisher = Publisher(args.project, args.topic) def print_publishing_id(publishing_id): print(publishing_id, file=sys.stdout) sys.stdout.flush() publisher.publish_iter( (io.schema.upgrade(io.schema.validate(data), copy=False) for data in misc.json_load_stream_fd(sys.stdin.fileno())), done_cb=print_publishing_id)
def describe_main(): """Execute the kcidb-describe command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-describe - Output descriptions of report objects' parser = misc.ArgumentParser(description=description) parser.add_argument('obj_list_name', metavar='LIST', choices={n for n in io.schema.LATEST.tree if n}, help='Name of the object list to output (%(choices)s)') parser.add_argument('ids', metavar='ID', nargs='*', default=[], help='ID of the object to limit output to') args = parser.parse_args() for io_data in misc.json_load_stream_fd(sys.stdin.fileno()): io_data = io.schema.upgrade(io.schema.validate(io_data), copy=False) oo_data = oo.from_io(io_data) obj_map = oo_data.get(args.obj_list_name, {}) for obj_id in args.ids or obj_map: if obj_id in obj_map: sys.stdout.write(obj_map[obj_id].describe()) sys.stdout.write("\x00") sys.stdout.flush()
def submit_main(): """Execute the kcidb-submit command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = \ 'kcidb-submit - Submit Kernel CI reports, print submission IDs' parser = misc.ArgumentParser(description=description) parser.add_argument( '-p', '--project', help='ID of the Google Cloud project containing the message queue', required=True) parser.add_argument('-t', '--topic', help='Name of the message queue topic to publish to', required=True) args = parser.parse_args() client = Client(project_id=args.project, topic_name=args.topic) def print_submission_id(submission_id): print(submission_id, file=sys.stdout) sys.stdout.flush() client.submit_iter( (io.schema.upgrade(io.schema.validate(data), copy=False) for data in misc.json_load_stream_fd(sys.stdin.fileno())), done_cb=print_submission_id)
def validate_main(): """Execute the kcidb-validate command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-validate - Validate I/O JSON data' parser = misc.ArgumentParser(description=description) parser.parse_args() for data in misc.json_load_stream_fd(sys.stdin.fileno()): io.schema.validate(data)
def count_main(): """Execute the kcidb-count command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-count - Count number of objects in I/O JSON data' parser = misc.ArgumentParser(description=description) parser.parse_args() for data in misc.json_load_stream_fd(sys.stdin.fileno()): print(io.get_obj_num(io.schema.validate(data)), file=sys.stdout) sys.stdout.flush()
def load_main(): """Execute the kcidb-db-load command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = \ 'kcidb-db-load - Load reports into Kernel CI report database' parser = ArgumentParser(description=description) args = parser.parse_args() client = Client(args.dataset, project_id=args.project) for data in misc.json_load_stream_fd(sys.stdin.fileno()): data = io.schema.upgrade(io.schema.validate(data), copy=False) client.load(data)
def upgrade_main(): """Execute the kcidb-upgrade command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-upgrade - Upgrade I/O JSON data to latest schema' parser = misc.OutputArgumentParser(description=description) args = parser.parse_args() misc.json_dump_stream( (io.schema.upgrade(data, copy=False) for data in misc.json_load_stream_fd(sys.stdin.fileno())), sys.stdout, indent=args.indent, seq=args.seq)
def notify_main(): """Execute the kcidb-notify command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-notify - Generate notifications for new I/O data' parser = misc.ArgumentParser(description=description) parser.add_argument('base', metavar='BASE_FILE', nargs='?', help='Path to a JSON file with base I/O data') args = parser.parse_args() base = io.new() if args.base is not None: try: with open(args.base, "r") as json_file: base_reports = [ io.schema.validate(data) for data in misc.json_load_stream_fd(json_file.fileno()) ] base = io.merge(base, base_reports, copy_target=False, copy_sources=False) except (jq.JSONParseError, jsonschema.exceptions.ValidationError) as err: raise Exception("Failed reading base file") from err try: for new in misc.json_load_stream_fd(sys.stdin.fileno()): new = io.schema.validate(new) for notification in subscriptions.match_new_io(base, new): sys.stdout.write(notification.render().as_string( policy=email.policy.SMTPUTF8)) sys.stdout.write("\x00") sys.stdout.flush() base = io.merge(base, [new], copy_target=False, copy_sources=False) except (jq.JSONParseError, jsonschema.exceptions.ValidationError) as err: raise Exception("Failed reading new I/O data") from err
def complement_main(): """Execute the kcidb-db-complement command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = \ 'kcidb-db-complement - Complement reports from database' parser = OutputArgumentParser(description=description) args = parser.parse_args() client = Client(args.dataset, project_id=args.project) misc.json_dump_stream( (client.complement(io.schema.upgrade(data, copy=False)) for data in misc.json_load_stream_fd(sys.stdin.fileno())), sys.stdout, indent=args.indent, seq=args.seq)
def merge_main(): """Execute the kcidb-merge command-line tool""" sys.excepthook = misc.log_and_print_excepthook description = 'kcidb-merge - Upgrade and merge I/O data sets' parser = misc.OutputArgumentParser(description=description) args = parser.parse_args() sources = [ io.schema.validate(data) for data in misc.json_load_stream_fd(sys.stdin.fileno()) ] merged_data = io.merge(io.new(), sources, copy_target=False, copy_sources=False) misc.json_dump(merged_data, sys.stdout, indent=args.indent, seq=args.seq)