def collect_data( user_handle: str, parent: str, data_types: List[str], filename: str, create_json: bool, ) -> None: """Collect data of a Dataverse installation. Collect data from a data node down the Dataverse tree-like data structure. Collects the complete data of a Dataverse instance in a tree structure (`tree.json`), containing all Dataverses, Datasets and Datafiles. The file is stored in your instance directory (e. g. `utils/data/instances/dataverse_production`). """ if user_handle == "public": api = NativeApi(config.BASE_URL) else: users = read_json(config.USER_FILENAME) api = NativeApi(config.BASE_URL, users[user_handle]["api-token"]) tree = api.get_children(parent, children_types=data_types) if not os.path.isdir(os.path.join(ROOT_DIR, "data")): os.makedirs(os.path.join(ROOT_DIR, "data")) if not os.path.isdir(os.path.join(ROOT_DIR, "data", "utils")): os.makedirs(os.path.join(ROOT_DIR, "data", "utils")) if not os.path.isdir( os.path.join(ROOT_DIR, "data", "utils", user_handle)): os.makedirs( os.path.join(ROOT_DIR, "data", "utils", user_handle)) write_json(os.path.join(UTILS_DATA_DIR, user_handle, filename), tree) if create_json: generate_data(tree, user_handle, filename)
def remove_testdata( user_handle: str, parent: str, data_types: List[str] = ["dataverses", "datasets"], force: bool = False, parent_data_type: str = "dataverse", remove_parent: bool = False, ) -> None: """Remove testdata. Removes all data created by `create-testdata`. It recursively collects all Dataverses and Datasets from a passed Dataverse down (by default = `science`). If `PRODUCTION` is `true`, this function will not execute, as long as you not add `--force` to the function call. This is to protect from unwanted changes on a production instance. """ if config.PRODUCTION and not force: print( "Delete testdata on a PRODUCTION instance not allowed. Use --force to force it." ) sys.exit() user = read_json(config.USER_FILENAME)[user_handle] api = NativeApi(config.BASE_URL, user["api-token"]) # Clean up data = api.get_children(parent, children_types=data_types) dataverses, datasets, = dataverse_tree_walker(data) if parent_data_type == "dataverse" and remove_parent: dataverses.append({"dataverse_alias": parent}) for ds in datasets: api.destroy_dataset(ds["pid"]) for dv in dataverses: api.delete_dataverse(dv["dataverse_alias"])