def export(ctx, filepath): """Export a dataset to an input set json.""" try: ds = get_dataset(ctx) ds.export_inputset(filepath) except Exception as e: print_error(e, DEBUG)
def backup(ctx, filepath): """Pickles the complete dataset.""" try: ds = get_dataset(ctx) ds.backup(filepath) except Exception as e: print_error(e, DEBUG)
def get(ctx, metadata, versions): """Downloads project and version information.""" backup_ds = None rolled_back = False # load project metadata if metadata: try: ds = get_dataset(ctx) backup_ds = deepcopy(ds) ds.get_projects_meta() except Exception as e: print_error(e, DEBUG) # roll back the db ctx.obj['dataset'] = backup_ds rolled_back = True # load project versions if versions: try: ds = get_dataset(ctx) backup_ds = deepcopy(ds) ds.get_project_versions(historical=versions) except Exception as e: print_error(e, DEBUG) # roll back the db ctx.obj['dataset'] = backup_ds rolled_back = True if rolled_back: print(' The dataset was not modified.')
def sample(ctx, n, on_versions, seed): """Samples projects or versions from a dataset.""" backup_ds = None try: ds = get_dataset(ctx) backup_ds = deepcopy(ds) ds.sample(n, on_versions, seed) except Exception as e: print_error(e, DEBUG) # roll back the db ctx.obj['dataset'] = backup_ds print(' The dataset was not modified.')
def sort(ctx, keywords_string): """Sorts a dataset.""" backup_ds = None try: ds = get_dataset(ctx) backup_ds = deepcopy(ds) ds.sort(keywords_string.split()) except Exception as e: print_error(e, DEBUG) # roll back the db ctx.obj['dataset'] = backup_ds print(' The dataset was not modified.')
def show(ctx): """Opens the complete dataset as a json for easier review.""" try: ds = get_dataset(ctx) data_dict = ds.to_json() # save temp file filepath = TEMP_DIR + 'jsonify.json' with open(filepath, 'w') as file: json.dump(data_dict, file, indent=4) fullpath = os.path.realpath(filepath) # open in system's default json viewer webbrowser.open_new('file://' + fullpath) except Exception as e: print_error(e, DEBUG)