Пример #1
0
def subscriber_pull_main():
    """Execute the kcidb-mq-subscriber-pull command-line tool"""
    sys.excepthook = misc.log_and_print_excepthook
    description = \
        'kcidb-mq-subscriber-pull - Pull with a Kernel CI report subscriber'
    parser = misc.OutputArgumentParser(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 subscription\'s message queue topic',
                        required=True)
    parser.add_argument('-s',
                        '--subscription',
                        help='Name of the subscription to pull from',
                        required=True)
    parser.add_argument(
        '--timeout',
        metavar="SECONDS",
        type=float,
        help='Wait the specified number of SECONDS for a report message, '
        'or forever, if zero',
        default=0,
        required=False)
    args = parser.parse_args()
    subscriber = Subscriber(args.project, args.topic, args.subscription)
    items = subscriber.pull(1, timeout=args.timeout)
    if items:
        ack_id, data = items[0]
        misc.json_dump(data, sys.stdout, indent=args.indent, seq=args.seq)
        sys.stdout.flush()
        subscriber.ack(ack_id)
Пример #2
0
def schema_main():
    """Execute the kcidb-schema command-line tool"""
    sys.excepthook = misc.log_and_print_excepthook
    description = 'kcidb-schema - Output latest I/O JSON schema'
    parser = misc.OutputArgumentParser(description=description)
    args = parser.parse_args()
    misc.json_dump(io.schema.LATEST.json,
                   sys.stdout,
                   indent=args.indent,
                   seq=args.seq)
Пример #3
0
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)
Пример #4
0
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)