Пример #1
0
def delete(job_id):
    try:
        api = MyelindlApi()
        result = api.job_delete(job_id)
        click.echo(result)
    except Exception, e:
        click.echo("failed, {}".format(e))
Пример #2
0
def list():
    api = MyelindlApi()
    try:
        result = api.list_publish_dataset()
    except MyelindlApiError as e:
        click.echo('Fail due to {}'.format(str(e)))
        return

    template = '| {:>10} | {:>10} | {:>30} | {:>10} | {:>10} | {:>10} |'
    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))
Пример #3
0
def delete(id):
    try:
        api = MyelindlApi()
        name = api.project_get_info(id)['info']['name']
        result = api.project_delete(id)
    except MyelindlApiError, e:
        click.echo("delete a project failed, {}".format(e))
Пример #4
0
def pull(tag):
    try:
        api = MyelindlApi()
        result = api.image_pull(tag)
        click.echo(result) 
    except MyelindlApiError as e:
        click.echo(str(e))
Пример #5
0
def training(job_name, package_path, module_name, image_tag, dataset_path, num_gpu, user_args):
    dst_path = ''
    job_id = None
    project = os.getenv('PROJECT', None)
    if project is None:
        click.echo("PROJECT not defined, use '{}' as project name".format(job_name))
        project = job_name
    if package_path:
        if not os.path.exists(package_path):
            click.echo('--package-path: {} not exists!'.format(package_path))
            return
    try:
        args = [a for a in user_args]
        api = MyelindlApi()
        result = api.job_create(
            project=project,
            pkg_path=package_path,
            image_tag=image_tag,
            dataset_path=dataset_path,
            job_name=job_name,
            module_name=module_name,
            num_gpu=num_gpu,
            user_args=' '.join(args),
        )
        job_id = result['id']
        click.echo('Job id: {}'.format(job_id))
        result = api.job_train(job_id)
        click.echo('Job {}: {}'.format(job_name, result))
    except MyelindlApiError as e:
        if job_id:
            api.job_delete(job_id)
        click.echo("submit failed, %s"% str(e))
Пример #6
0
def delete(id):
    try:
        api = MyelindlApi()
        result = api.image_delete(id)
        click.echo(result) 
    except MyelindlApiError as e:
        click.echo(str(e))
Пример #7
0
def download(job_id):
    try:
        api = MyelindlApi()
        api.job_download(job_id)
        #click.echo(result)
    except Exception, e:
        click.echo("failed, {}".format(e))
Пример #8
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)))
Пример #9
0
def server(model):
    try:
        api = MyelindlApi()
        result = api.create_server(model)
        server_id = result['server_id']
        print ("Server runing on  http://localhost/models/server/{}/view".format(server_id))
    except MyelindlApiError as e:
        click.echo(str(e))
Пример #10
0
def create(name):
    try:
        api = MyelindlApi()
        result = api.project_create(name)

        #click.echo('{}'.format(project_id))
    except MyelindlApiError, e:
        click.echo("new project failed, {}".format(e))
Пример #11
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)))
        return
Пример #12
0
def browse(id, dir):

    api = MyelindlApi()
    try:
        result = api.get_dataset_items(id, dir)
        if 'files' not in result:
            raise Exception('Browse unsupported dataset type.'
                            'We only support browse file type of dataset')

        for file in result['files']:
            if file['is_dir']:
                click.echo('{}/'.format(file['name']))
            else:
                click.echo(file['name'])
    except Exception as e:
        click.echo("Fail due to {}".format(str(e)))
Пример #13
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))
Пример #14
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)))
        return

    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))
Пример #15
0
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))
Пример #16
0
def list(is_json):
    try:
        api = MyelindlApi()
        result = api.project_list()

        if is_json:
            click.echo(json.dumps(result, indent=2, sort_keys=True))
            return
        template = '| {:>8} | {:>10} | {:>8} | {:>20} |'
        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))
Пример #17
0
def list(is_json):
    try:
        api = MyelindlApi()
        result = api.job_list()
        if is_json:
            click.echo(json.dumps(result, indent=2, sort_keys=True)+'\n')
            return

        template = '| {:>12} | {:>20} | {:>8} | {:>20} | {:>10} |'
        header = template.format('id', 'name', '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['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))
Пример #18
0
def log(job_id):
    try:
        api = MyelindlApi()
        click.echo(api.job_log(job_id))
    except MyelindlApiError, e:
        click.echo("failed, {}".format(e))