Skip to content

Commit

Permalink
cli: Improve http/https dichotomy
Browse files Browse the repository at this point in the history
Removed https protocol from protocol options, keeping only http or xrootd
Accepting https with --server option
closes #92
  • Loading branch information
Parth Shandilya committed Nov 17, 2020
1 parent 591ff17 commit 24fa085
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 70 deletions.
8 changes: 6 additions & 2 deletions cernopendata_client/cli.py
Expand Up @@ -115,7 +115,7 @@ def get_metadata(server, recid, doi, title, output_value):
@click.option(
"--protocol",
default="http",
type=click.Choice(["http", "https", "xrootd"]),
type=click.Choice(["http", "xrootd"]),
help="Protocol to be used in links.",
)
@click.option(
Expand Down Expand Up @@ -147,6 +147,8 @@ def get_file_locations(server, recid, doi, title, protocol, expand, verbose):
$ cernopendata-client get-file-locations --recid 5500 --verbose
"""
validate_server(server)
if server != SERVER_HTTP_URI:
protocol = server.split(":")[0]
if recid is not None:
validate_recid(recid)
record_json = get_record_as_json(server, recid, doi, title)
Expand All @@ -165,7 +167,7 @@ def get_file_locations(server, recid, doi, title, protocol, expand, verbose):
@click.option(
"--protocol",
default="http",
type=click.Choice(["http", "https", "xrootd"]),
type=click.Choice(["http", "xrootd"]),
help="Protocol to be used in links.",
)
@click.option(
Expand Down Expand Up @@ -229,6 +231,8 @@ def download_files(
$ cernopendata-client download-files --recid 5500 --filter-regexp py --filter-range 1-2
"""
validate_server(server)
if server != SERVER_HTTP_URI:
protocol = server.split(":")[0]
if recid is not None:
validate_recid(recid)
record_json = get_record_as_json(server, recid, doi, title)
Expand Down
2 changes: 1 addition & 1 deletion cernopendata_client/downloader.py
Expand Up @@ -87,7 +87,7 @@ def download_single_file(path=None, file_location=None, protocol=None):
if not xrootd_available:
display_message(
msg_type="error",
msg="xrootd is not installed on system. Please use the 'http' or 'https' protocol instead.",
msg="xrootd is not installed on system. Please use the 'http' protocol instead.",
)
sys.exit(1)
file_src = file_location.split("root://eospublic.cern.ch/")[-1]
Expand Down
2 changes: 1 addition & 1 deletion cernopendata_client/searcher.py
Expand Up @@ -180,7 +180,7 @@ def get_files_list(
:param server: CERN Open Data server to query
:param record_json: Record content in JSON
:protocol: Protocol to be used in links(http | https | xrootd)
:protocol: Protocol to be used in links(http | xrootd)
:expand: Flag for expanding file indexes
:verbose: Flag for showing size and checksum of file
:type server: str
Expand Down
66 changes: 2 additions & 64 deletions docs/usage.rst
Expand Up @@ -111,25 +111,7 @@ the **get-file-locations** command:
http://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/mass4l_combine.png
This command will output URIs for all the files associated with the record ID 5500, using the HTTP protocol.

**HTTPS protocol**

.. code-block:: console
$ cernopendata-client get-file-locations --recid 5500 --protocol https
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/BuildFile.xml
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/HiggsDemoAnalyzer.cc
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/List_indexfile.txt
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/M4Lnormdatall.cc
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/M4Lnormdatall_lvl3.cc
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/demoanalyzer_cfg_level3MC.py
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/demoanalyzer_cfg_level3data.py
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/demoanalyzer_cfg_level4MC.py
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/demoanalyzer_cfg_level4data.py
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/mass4l_combine.pdf
https://opendata.cern.ch/eos/opendata/cms/software/HiggsExample20112012/mass4l_combine.png
This command will output URIs for all the files associated with the record ID 5500, using the HTTPS protocol.
Note that you can specify `--server https://opendata.cern.ch` if you would like to use the HTTPS protocol instead.

**XRootD protocol**

Expand Down Expand Up @@ -271,51 +253,7 @@ In order to download data files belonging to a record, please use the
==> Success!
The command will download files into a `5500` directory.

**HTTPS protocol**

Note that you can use ``--protocol https`` command-line option if you
would rather want to download files with https protocol:

.. code-block:: console
$ cernopendata-client download-files --recid 5500 --protocol https
==> Downloading file 1 of 11
-> File: ./5500/BuildFile.xml
-> Progress: 0/0 kiB (100%)
==> Downloading file 2 of 11
-> File: ./5500/HiggsDemoAnalyzer.cc
-> Progress: 81/81 kiB (100%)
==> Downloading file 3 of 11
-> File: ./5500/List_indexfile.txt
-> Progress: 1/1 kiB (100%)
==> Downloading file 4 of 11
-> File: ./5500/M4Lnormdatall.cc
-> Progress: 14/14 kiB (100%)
==> Downloading file 5 of 11
-> File: ./5500/M4Lnormdatall_lvl3.cc
-> Progress: 15/15 kiB (100%)
==> Downloading file 6 of 11
-> File: ./5500/demoanalyzer_cfg_level3MC.py
-> Progress: 3/3 kiB (100%)
==> Downloading file 7 of 11
-> File: ./5500/demoanalyzer_cfg_level3data.py
-> Progress: 3/3 kiB (100%)
==> Downloading file 8 of 11
-> File: ./5500/demoanalyzer_cfg_level4MC.py
-> Progress: 3/3 kiB (100%)
==> Downloading file 9 of 11
-> File: ./5500/demoanalyzer_cfg_level4data.py
-> Progress: 3/3 kiB (100%)
==> Downloading file 10 of 11
-> File: ./5500/mass4l_combine.pdf
-> Progress: 17/17 kiB (100%)
==> Downloading file 11 of 11
-> File: ./5500/mass4l_combine.png
-> Progress: 90/90 kiB (100%)
==> Success!
The command will download files into a `5500` directory.
Note that you can specify `--server https://opendata.cern.ch` if you would like to use the HTTPS protocol instead.

**XRootD protocol**

Expand Down
5 changes: 3 additions & 2 deletions tests/test_cli_download_files.py
Expand Up @@ -14,6 +14,7 @@

from click.testing import CliRunner
from cernopendata_client.cli import download_files
from cernopendata_client.config import SERVER_HTTPS_URI


def test_dry_run_from_recid():
Expand Down Expand Up @@ -94,7 +95,7 @@ def test_download_files_https_pycurl():
os.remove(test_file)
test_download_files = CliRunner()
test_result = test_download_files.invoke(
download_files, ["--recid", 3005, "--protocol", "https"]
download_files, ["--recid", 3005, "--server", SERVER_HTTPS_URI]
)
assert test_result.exit_code == 0
assert os.path.isfile(test_file) is True
Expand All @@ -112,7 +113,7 @@ def test_download_files_https_requests(mocker):
os.remove(test_file)
test_download_files = CliRunner()
test_result = test_download_files.invoke(
download_files, ["--recid", 3005, "--protocol", "https"]
download_files, ["--recid", 3005, "--server", SERVER_HTTPS_URI]
)
assert test_result.exit_code == 0
assert os.path.isfile(test_file) is True
Expand Down

0 comments on commit 24fa085

Please sign in to comment.