Ejemplo n.º 1
0
def main(conf):
    """ main function """
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--clear',
                        help='clear previous messagesi. works only with -f',
                        default=False,
                        action='store_true')
    parser.add_argument('-f',
                        '--follow',
                        help='follow mode',
                        default=False,
                        action='store_true')
    parser.add_argument('-l', '--lines', help='number of lines', default='5')
    parser.add_argument('-r', '--region', help='security region', default='40')
    args = parser.parse_args()

    numlines = args.lines
    url = conf.get('global', 'baseurl') + conf.get('regions',
                                                   'region' + args.region)

    data = libp2000.get_p2000_data(url)
    p2000data = libp2000.convert_to_json(data)

    for _ in range(int(numlines)):
        idx = _
        if args.follow:
            # output the first item last
            idx = int(numlines) - _
        print(p2000_pp(p2000data['p2000'][idx - 1]))

    if args.follow:
        refreshtime = int(conf.get('global', 'refreshtime'))
        bar = Bar('Refresh in: ', max=refreshtime)
        olddata = p2000data['p2000']
        try:
            while True:
                newdata = libp2000.convert_to_json(
                    libp2000.get_p2000_data(url))['p2000']
                newdata.reverse()
                diff = [x for x in newdata if x not in olddata]
                if len(diff) > 0:
                    if args.clear:
                        os.system('clear')
                    for item in diff:
                        print(p2000_pp(item))
                olddata = newdata
                bar.goto(0)
                for t in range(refreshtime):
                    bar.next()
                    time.sleep(1)
                bar.clearln()

        except KeyboardInterrupt:
            bar.finish()
            sys.exit(0)
Ejemplo n.º 2
0
def main(conf):
    """ main function """
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--clear', help='clear previous messagesi. works only with -f', default=False, action='store_true')
    parser.add_argument('-f', '--follow', help='follow mode', default=False, action='store_true')
    parser.add_argument('-l', '--lines', help='number of lines', default='5')
    parser.add_argument('-r', '--region', help='security region', default='40')
    args = parser.parse_args()

    numlines = args.lines
    url = conf.get('global', 'baseurl') + conf.get('regions', 'region' + args.region)

    data = libp2000.get_p2000_data(url)
    p2000data = libp2000.convert_to_json(data)

    for _ in range(int(numlines)):
        idx = _
        if args.follow:
            # output the first item last
            idx = int(numlines) - _
        print(p2000_pp(p2000data['p2000'][idx-1]))

    if args.follow:
        refreshtime = int(conf.get('global', 'refreshtime'))
        bar = Bar('Refresh in: ', max=refreshtime)
        olddata = p2000data['p2000']
        try:
            while True:
                newdata = libp2000.convert_to_json(libp2000.get_p2000_data(url))['p2000']
                newdata.reverse()
                diff = [x for x in newdata if x not in olddata]
                if len(diff) > 0:
                    if args.clear:
                        os.system('clear')
                    for item in diff:
                        print(p2000_pp(item))
                olddata = newdata
                bar.goto(0)
                for t in range(refreshtime):
                    bar.next()
                    time.sleep(1)
                bar.clearln()

        except KeyboardInterrupt:
            bar.finish()
            sys.exit(0)
Ejemplo n.º 3
0
def push_image(client, dest_repo, dest_tag):
    bar = Bar()
    results = client.images.push(dest_repo, dest_tag, stream=True, decode=True)

    print('')

    for result in results:
        status = result.get('status')

        if 'id' in result:
            if status == 'Pushing':
                output = '{id}: {status} {progress}'.format(**result)
                bar.writeln(output)
            elif status == 'Pushed':
                bar.clearln()
                print('{id}: {status}'.format(**result))

    bar.finish()
    bar.clearln()
Ejemplo n.º 4
0
def pull_image(client, src):
    src_repo, src_tag = split_tag(src)
    bar = Bar()
    results = client.api.pull(src_repo, src_tag, stream=True, decode=True)

    print('')

    for result in results:
        status = result.get('status')

        if 'id' in result:
            if status == 'Downloading' or status == 'Extracting':
                output = '{id}: {status} {progress}'.format(**result)
                bar.writeln(output)
            elif status == 'Download complete' or status == 'Pull complete':
                bar.clearln()
                print('{id}: {status}'.format(**result))

    bar.finish()
    bar.clearln()

    return client.images.get(src)