コード例 #1
0
def list():
    api = MyelindlApi()
    try:
        result = api.dataset_list()
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise
    longest = 10
    if result['datasets']:
        longest = max(len(d['name']) for d in result['datasets'])
    if longest < 10:
        longest = 10
    template = '| {:>10} | {:>%d} | {:>30} | {:>10} | {:>10} | {:>10} |' % longest
    header = template.format('id', 'name', 'description', 'size', 'type',
                             'user')

    click.echo('=' * len(header))
    click.echo(header)
    click.echo('=' * len(header))

    for ds in result['datasets']:
        line = template.format(
            ds['id'],
            ds['name'],
            ds['description'],
            sizeof_fmt(ds['size']),
            ds['type'],
            ds['username'],
        )
        click.echo(line)
    click.echo('=' * len(header))
コード例 #2
0
def publish(data_dir, name, id, type, description):

    if not os.path.exists(data_dir):
        click.echo('data-dir: {} not exists!'.format(data_dir))

    temp_dir = 'mlt_tmp-{}'.format(str(uuid.uuid1())[:8])
    try:
        api = MyelindlApi()
        api.data_upload(data_dir, temp_dir)

        dataset_id = id if id else ''
        dataset_type = type if type else 'file'

        result = api.publish_dataset(
            id=dataset_id,
            type=dataset_type,
            name=name,
            description=description,
            data_dir=temp_dir,
        )

        click.echo('Dataset {} published with id {}'.format(
            name, result['id']))
    except MyelindlApiError as e:
        click.echo(u'Dataset publish fail, due to {}'.format(str(e)))
        raise
コード例 #3
0
def list(is_json):
    try:
        api = MyelindlApi()
        result = api.project_list()
        longest = 10
        if result:
            longest = max(len(p['name']) for p in result)
        if longest < 10:
            longest = 10
        if is_json:
            click.echo(json.dumps(result, indent=2, sort_keys=True))
            return
        template = '| {:>8} | {:>%d} | {:>8} | {:>21} |' % longest
        header = template.format('id', 'name', 'user', 'create time')
        click.echo('=' * len(header))
        click.echo(header)
        click.echo('=' * len(header))
        for project in result:
            line = template.format(
                project['id'], project['name'], project['username'],
                datetime.fromtimestamp(
                    project['create_time']).strftime("%Y %b %d, %H:%M:%S"))
            click.echo(line)
        click.echo('=' * len(header))
    except MyelindlApiError, e:
        click.echo("list project failed, {}".format(e))
        raise
コード例 #4
0
def delete(id):
    try:
        api = MyelindlApi()
        result = api.project_delete(id)
    except MyelindlApiError, e:
        click.echo("delete a project failed, {}".format(e))
        raise
コード例 #5
0
def download(job_id):
    try:
        api = MyelindlApi()
        api.job_download(job_id)
    except Exception, e:
        click.echo("failed, {}".format(e))
        raise
コード例 #6
0
def list(is_json):
    try:
        api = MyelindlApi()
        result = api.job_list()
        longest = 10
        if result['jobs']:
            longest = max(len(j['name']) for j in result['jobs'])
        if longest < 10:
            longest = 10
        if is_json:
            click.echo(json.dumps(result, indent=2, sort_keys=True) + '\n')
            return
        template = '| {:>16} | {:>%d} | {:>10} | {:>8} | {:>21} | {:>10} |' % longest
        header = template.format('id', 'name', 'project', 'status',
                                 'create time', 'user')
        click.echo('=' * len(header))
        click.echo(header)
        click.echo('=' * len(header))
        for inst in result['jobs']:
            line = template.format(
                inst['id'], inst['name'], inst['project'],
                inst['status_history'][-1][0],
                datetime.fromtimestamp(inst['status_history'][0][1]).strftime(
                    "%Y %b %d, %H:%M:%S"), inst['username'])
            click.echo(line)
        click.echo('=' * len(header))
    except Exception, e:
        click.echo("submit failed, {}".format(e))
        raise
コード例 #7
0
def log(job_id):
    try:
        api = MyelindlApi()
        click.echo(api.job_log(job_id))
    except MyelindlApiError, e:
        click.echo("failed, {}".format(e))
        raise
コード例 #8
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def versions(tag, offset, limit):
    results = []
    try:
        api = MyelindlApi()
        results = api.model_versions(
            tag,
            offset=offset,
            limit=limit,
        )
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise

    longest = max(len(d['tag']) for d in results)
    if longest < 10:
        longest = 10
    template = '| {:>%d} | {:>20} | {:>10} | {:>10} | {:>10} | {:>10} |'% longest
    header = template.format('tag', 'name', 'version', 'size', 'type', 'user')


    click.echo('=' * len(header))
    click.echo(header)
    click.echo('=' * len(header))

    for ds in results:
        line = template.format(
            ds['tag'],
            ds['name'],
            ds['version'],
            sizeof_fmt(ds['size']),
            ds['type'],
            ds['username'],
        )
        click.echo(line)
    click.echo('='* len(header))
コード例 #9
0
ファイル: checkpoint.py プロジェクト: myelintek/lib-mlsteam
def delete(id):
    try:
        api = MyelindlApi()
        result = api.checkpoint_delete(id)
    except MyelindlApiError as e:
        click.echo("delete a checkpoint failed, {}".format(e))
        raise
コード例 #10
0
ファイル: service.py プロジェクト: myelintek/lib-mlsteam
def delete(id):
    try:
        api = MyelindlApi()
        result = api.service_delete(id)
    except MyelindlApiError, e:
        click.echo("delete a service failed, {}".format(e))
        raise
コード例 #11
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def list(offset, limit):
    results = []
    try:
        api = MyelindlApi()
        results = api.model_list(
            offset=offset,
            limit=limit
        )
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise

    template = '| {:>30}|'
    header = template.format('model')

    click.echo('=' * len(header))
    click.echo(header)
    click.echo('=' * len(header))

    for ds in results:
        line = template.format(
            ds,
        )
        click.echo(line)
    click.echo('='* len(header))
コード例 #12
0
ファイル: checkpoint.py プロジェクト: myelintek/lib-mlsteam
def download(id):
    try:
        api = MyelindlApi()
        result = api.checkpoint_download(id)
        click.echo(result)
    except MyelindlApiError as e:
        click.echo("download checkpoint failed, {}".format(e))
        raise
コード例 #13
0
ファイル: checkpoint.py プロジェクト: myelintek/lib-mlsteam
def info(id):
    try:
        api = MyelindlApi()
        result=api.checkpoint_info(id)
        click.echo(json.dumps(result, indent=2, sort_keys=True))
    except MyelindlApiError as e:
        click.echo("show checkpoint info failed, {}".format(e))
        raise
コード例 #14
0
ファイル: checkpoint.py プロジェクト: myelintek/lib-mlsteam
def list():
    try:
        api = MyelindlApi()
        result = api.checkpoint_list()
        click.echo(json.dumps(result, indent=2, sort_keys=True))
    except MyelindlApiError as e:
        click.echo("list checkpoint failed, {}".format(e))
        raise
コード例 #15
0
ファイル: container.py プロジェクト: myelintek/lib-mlsteam
def pull(tag):
    try:
        api = MyelindlApi()
        result = api.image_pull(tag)
        click.echo(result)
    except MyelindlApiError as e:
        click.echo(str(e))
        raise
コード例 #16
0
def abort(job_id):
    try:
        api = MyelindlApi()
        result = api.job_abort(job_id)
        click.echo('Job {} aborted '.format(job_id))
    except Exception, e:
        click.echo("failed, {}".format(e))
        raise
コード例 #17
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def delete(tag):
    try:
        api = MyelindlApi()
        api.model_delete(tag)
        click.echo('Model deleted {}'.format(tag))
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise
コード例 #18
0
ファイル: service.py プロジェクト: myelintek/lib-mlsteam
def create(id):
    try:
        api = MyelindlApi()
        result = api.service_create(id)
        click.echo(result)
    except MyelindlApiError, e:
        click.echo("create service failed, {}".format(e))
        raise
コード例 #19
0
ファイル: container.py プロジェクト: myelintek/lib-mlsteam
def delete(id):
    try:
        api = MyelindlApi()
        result = api.image_delete(id)
        click.echo(result)
    except MyelindlApiError as e:
        click.echo(str(e))
        raise
コード例 #20
0
ファイル: service.py プロジェクト: myelintek/lib-mlsteam
def list():
    try:
        api = MyelindlApi()
        result = api.service_list()
        click.echo(json.dumps(result, indent=2, sort_keys=True))
    except MyelindlApiError, e:
        click.echo("list service failed, {}".format(e))
        raise
コード例 #21
0
def unpublish(id):
    api = MyelindlApi()
    try:
        result = api.unpublish_dataset(id)
        click.echo('Dataset {} unpublished'.format(id))
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise
コード例 #22
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def pull(tag, output_dir):
    try:
        api = MyelindlApi()
        api.model_pull(
            tag,
            output_dir
        )
        click.echo('Finish model pull {}' .format(tag))
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise
コード例 #23
0
def info():
    try:
        api = MyelindlApi()
        server_ver = api.version()
        click.echo("Version: {}, sha: {}".format(version.__version__,
                                                 version.__sha__))
        click.echo("Server: {}".format(api.host))
        click.echo("Username: {}".format(api.username))
        click.echo("Data Port: {}".format(api.data_port))
    except MyelindlApiError as e:
        click.echo(u'Fail due to {}'.format(e))
        raise
コード例 #24
0
def create(name, dataset):
    try:
        if dataset.startswith('bk/'):
            click.echo("no need 'bk/' prefix for dataset.")
            return
        api = MyelindlApi()
        result = api.project_create(name, dataset)

        click.echo('{}'.format(result['id']))
    except MyelindlApiError, e:
        click.echo("new project failed, {}".format(e))
        raise
コード例 #25
0
def browse(id, dir):

    api = MyelindlApi()
    try:
        result = api.get_dataset_items(id, dir)
        for file in result:
            if file['type'] == 'dir':
                click.echo('{}/'.format(file['basename']))
            else:
                click.echo(file['basename'])
    except Exception as e:
        click.echo("Fail due to {}".format(str(e)))
        raise
コード例 #26
0
def info(id):
    try:
        api = MyelindlApi()
        result = api.project_get_info(id)

        template = '| {:>11} | {:>40}|'
        header = template.format('Field', 'Value')
        click.echo('=' * len(header))
        click.echo(header)
        click.echo('=' * len(header))

        for k, v in result['info'].iteritems():
            line = template.format(k, v)
            click.echo(line)
        click.echo('=' * len(header))
    except MyelindlApiError, e:
        click.echo("show project info failed, {}".format(e))
        raise
コード例 #27
0
def info(id):
    api = MyelindlApi()
    try:
        result = api.get_dataset_info(id)
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise

    template = '| {:>20} | {:>30}|'
    header = template.format('Field', 'Value')

    click.echo('=' * len(header))
    click.echo(header)
    click.echo('=' * len(header))

    for k, v in result.iteritems():
        line = template.format(k, v)
        click.echo(line)
    click.echo('=' * len(header))
コード例 #28
0
ファイル: container.py プロジェクト: myelintek/lib-mlsteam
def list():
    try:
        api = MyelindlApi()
        result = api.image_list()
        longest = 20
        if result:
            longest = max(len(x['tag']) for x in result)
        if longest < 20:
            longest = 20
        template = '| {:>10} | {:>%d} |' % longest
        header = template.format('id', 'tag')
        click.echo('=' * len(header))
        click.echo(header)
        click.echo('=' * len(header))
        for image in result:
            line = template.format(image['id'], image['tag'])
            click.echo(line)
        click.echo('=' * len(header))
    except MyelindlApiError as e:
        click.echo(str(e))
        raise
コード例 #29
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def info(tag):
    result = {}
    try:
        api = MyelindlApi()
        result = api.model_info(tag)
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        raise
    
    longest = max(len(str(v)) for v in result.values())
    longest = longest if longest >= 10 else 10
    template = '| {:>16} | {:>%d} |'% longest
    header = template.format('key', 'value')

    click.echo('=' * len(header))
    click.echo(header)
    click.echo('=' * len(header))

    for k,v in result.iteritems():
        line = template.format(k, v)
        click.echo(line)
    click.echo('='* len(header))
コード例 #30
0
ファイル: model.py プロジェクト: myelintek/lib-mlsteam
def push(tag, model_dir, description, type):
    if not os.path.exists(model_dir):
        click.echo('model-dir: {} not exists!'.format(model_dir))

    temp_dir = 'mlt_tmp-{}'.format(str(uuid.uuid1())[:8])
    try:
        api = MyelindlApi()
        api.data_upload(model_dir, temp_dir)

        dataset_id = id if id else ''
        dataset_type = type if type else 'file'
        
        result = api.model_push(
            tag,
            temp_dir,
            description,
            type,
        )
        click.echo( 'Model {} pushed.'.format(tag))
    except MyelindlApiError as e:
        print str(e)
        click.echo( 'Dataset publish fail, due to {}'.format(str(e)))
        raise