Skip to content

Commit b1870bd

Browse files
sminotnathanthorpe
andauthored
CI-169 - Let the user specify a dataset to download by name only (#122)
* Let the user specify a dataset to download by name only * list-datasets, allow ID or name of project * run-ingest, id or name for project & process * fix bug * add run configuration for intellij --------- Co-authored-by: Nathan Thorpe <[email protected]>
1 parent 802b6b7 commit b1870bd

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

.run/cli.run.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="cli" type="PythonConfigurationType" factoryName="Python">
3+
<module name="Cirro-client" />
4+
<option name="ENV_FILES" value="" />
5+
<option name="INTERPRETER_OPTIONS" value="" />
6+
<option name="PARENT_ENVS" value="true" />
7+
<envs>
8+
<env name="PYTHONUNBUFFERED" value="1" />
9+
</envs>
10+
<option name="SDK_HOME" value="" />
11+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/cirro/cli" />
12+
<option name="IS_MODULE_SDK" value="true" />
13+
<option name="ADD_CONTENT_ROOTS" value="true" />
14+
<option name="ADD_SOURCE_ROOTS" value="true" />
15+
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
16+
<EXTENSION ID="software.aws.toolkits.jetbrains.core.execution.PythonAwsConnectionExtension">
17+
<option name="credential" />
18+
<option name="region" />
19+
<option name="useCurrentConnection" value="false" />
20+
</EXTENSION>
21+
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/cirro/cli/cli.py" />
22+
<option name="PARAMETERS" value="list-datasets --project Test2" />
23+
<option name="SHOW_COMMAND_LINE" value="false" />
24+
<option name="EMULATE_TERMINAL" value="true" />
25+
<option name="MODULE_MODE" value="false" />
26+
<option name="REDIRECT_INPUT" value="false" />
27+
<option name="INPUT_FILE" value="" />
28+
<method v="2" />
29+
</configuration>
30+
</component>

cirro/cli/controller.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ def run_list_datasets(input_params: ListArguments, interactive=False):
3232
_check_configure()
3333
cirro = CirroApi()
3434
logger.info(f"Collecting data from {cirro.configuration.base_url}")
35+
projects = cirro.projects.list()
3536

36-
# If the user provided the --interactive flag
37-
if interactive:
38-
39-
# Get the list of projects available to the user
40-
projects = cirro.projects.list()
41-
42-
if len(projects) == 0:
43-
raise InputError(NO_PROJECTS)
37+
if len(projects) == 0:
38+
raise InputError(NO_PROJECTS)
4439

40+
if interactive:
4541
# Prompt the user for the project
4642
input_params = gather_list_arguments(input_params, projects)
43+
else:
44+
input_params['project'] = get_id_from_name(projects, input_params['project'])
4745

4846
# List the datasets available in that project
4947
datasets = cirro.datasets.list(input_params['project'])
@@ -70,6 +68,8 @@ def run_ingest(input_params: UploadArguments, interactive=False):
7068
input_params, files = gather_upload_arguments(input_params, projects, processes)
7169
directory = input_params['data_directory']
7270
else:
71+
input_params['project'] = get_id_from_name(projects, input_params['project'])
72+
input_params['process'] = get_id_from_name(processes, input_params['process'])
7373
directory = input_params['data_directory']
7474
files = get_files_in_directory(directory)
7575

@@ -134,6 +134,13 @@ def run_download(input_params: DownloadArguments, interactive=False):
134134
raise InputError('There are no files in this dataset to download')
135135

136136
files_to_download = ask_dataset_files(files)
137+
project_id = input_params['project']
138+
dataset_id = input_params['dataset']
139+
140+
else:
141+
project_id = get_id_from_name(projects, input_params['project'])
142+
datasets = cirro.datasets.list(project_id)
143+
dataset_id = get_id_from_name(datasets, input_params['dataset'])
137144

138145
logger.info("Downloading files")
139146
if cirro.configuration.enable_additional_checksum:
@@ -142,8 +149,6 @@ def run_download(input_params: DownloadArguments, interactive=False):
142149
checksum_method = "MD5"
143150
logger.info(f"File content validated by {checksum_method}")
144151

145-
project_id = get_id_from_name(projects, input_params['project'])
146-
dataset_id = input_params['dataset']
147152
cirro.datasets.download_files(project_id=project_id,
148153
dataset_id=dataset_id,
149154
download_location=input_params['data_directory'],

0 commit comments

Comments
 (0)