Example #1
0
def cmd_watch_builds(args, osbs):
    field_selector = ",".join([
        "status!={status}".format(status=status.capitalize())
        for status in BUILD_FINISHED_STATES
    ])
    cols_to_display = CLI_WATCH_BUILDS_DEFAULT_COLS
    if args.columns:
        cols_to_display = args.columns.split(",")

    data = [{
        "changetype": "CHANGE",
        "status": "STATUS",
        "created": "CREATED",
        "name": "NAME",
    }]
    for changetype, obj in osbs.watch_builds(field_selector=field_selector):
        try:
            name = obj['metadata']['name']
        except KeyError:
            logger.error("'object' doesn't have any name")
            continue
        else:
            try:
                status = obj['status']['phase']
            except KeyError:
                status = '(not reported)'

            try:
                timestamp = obj['metadata']['creationTimestamp']
            except KeyError:
                created = '(not reported)'
            else:
                created = time.ctime(get_time_from_rfc3339(timestamp))

            b = {
                "changetype": changetype,
                "name": name or '',
                "status": status,
                "created": created,
            }
            data.append(b)
        if args.output == 'json':
            print(json.dumps(b))
            sys.stdout.flush()
        elif args.output == 'text':
            tp = TablePrinter(data, cols_to_display)
            tp.render()
Example #2
0
def cmd_watch_builds(args, osbs):
    field_selector = ",".join(["status!={status}".format(status=status.capitalize())
                               for status in BUILD_FINISHED_STATES])
    cols_to_display = CLI_WATCH_BUILDS_DEFAULT_COLS
    if args.columns:
        cols_to_display = args.columns.split(",")

    data = [{
        "changetype": "CHANGE",
        "status": "STATUS",
        "created": "CREATED",
        "name": "NAME",
    }]
    for changetype, obj in osbs.watch_builds(field_selector=field_selector):
        try:
            name = obj['metadata']['name']
        except KeyError:
            logger.error("'object' doesn't have any name")
            continue
        else:
            try:
                status = obj['status']['phase']
            except KeyError:
                status = '(not reported)'

            try:
                timestamp = obj['metadata']['creationTimestamp']
            except KeyError:
                created = '(not reported)'
            else:
                created = time.ctime(get_time_from_rfc3339(timestamp))

            b = {
                "changetype": changetype,
                "name": name or '',
                "status": status,
                "created": created,
            }
            data.append(b)
        if args.output == 'json':
            print(json.dumps(b))
            sys.stdout.flush()
        elif args.output == 'text':
            tp = TablePrinter(data, cols_to_display)
            tp.render()
Example #3
0
 def get_time_created_in_seconds(self):
     return get_time_from_rfc3339(self.get_time_created())
Example #4
0
 def get_time_created_in_seconds(self):
     return get_time_from_rfc3339(self.get_time_created())
Example #5
0
def test_get_time_from_rfc3339_invalid(rfc3339):
    with pytest.raises(ValueError):
        get_time_from_rfc3339(rfc3339)
Example #6
0
def test_get_time_from_rfc3339_valid_alt_format(rfc3339, seconds, tz):
    os.environ['TZ'] = tz
    tzset()
    assert get_time_from_rfc3339(rfc3339) == seconds
Example #7
0
def test_get_time_from_rfc3339_valid(rfc3339, seconds, tz):
    os.environ['TZ'] = tz
    tzset()
    assert get_time_from_rfc3339(rfc3339) == seconds
Example #8
0
def test_get_time_from_rfc3339_invalid(rfc3339):
    with pytest.raises(ValueError):
        get_time_from_rfc3339(rfc3339)
Example #9
0
def test_get_time_from_rfc3339_valid(rfc3339, seconds):
    assert get_time_from_rfc3339(rfc3339) == seconds