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))
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
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
def delete(id): try: api = MyelindlApi() result = api.project_delete(id) except MyelindlApiError, e: click.echo("delete a project failed, {}".format(e)) raise
def download(job_id): try: api = MyelindlApi() api.job_download(job_id) except Exception, e: click.echo("failed, {}".format(e)) raise
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
def log(job_id): try: api = MyelindlApi() click.echo(api.job_log(job_id)) except MyelindlApiError, e: click.echo("failed, {}".format(e)) raise
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))
def delete(id): try: api = MyelindlApi() result = api.checkpoint_delete(id) except MyelindlApiError as e: click.echo("delete a checkpoint failed, {}".format(e)) raise
def delete(id): try: api = MyelindlApi() result = api.service_delete(id) except MyelindlApiError, e: click.echo("delete a service failed, {}".format(e)) raise
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))
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
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
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
def pull(tag): try: api = MyelindlApi() result = api.image_pull(tag) click.echo(result) except MyelindlApiError as e: click.echo(str(e)) raise
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
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
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
def delete(id): try: api = MyelindlApi() result = api.image_delete(id) click.echo(result) except MyelindlApiError as e: click.echo(str(e)) raise
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
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
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
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
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
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
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
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))
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
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))
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