Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification of the CLI to include the use of ElabFTW methods. #75

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1fae8fc
Modification of the CLI to include the use of ElabFTW methods.
killianrochet May 22, 2023
07c60ec
Modification of the CLI:
killianrochet May 22, 2023
473cd59
Modification of the CLI:
killianrochet May 22, 2023
6332ece
Modification of the CLI:
killianrochet May 24, 2023
801d860
Modification of the CLI:
killianrochet May 24, 2023
92eb98f
Modification of the CLI:
killianrochet May 24, 2023
7f1fb46
Add a default value for the server variable
killianrochet May 24, 2023
12ead0c
Add conditional argument. When --server elabftw is selected for downl…
killianrochet May 25, 2023
4852afa
Add conditional argument. When --server elabftw is selected for downl…
killianrochet May 25, 2023
7189400
Modification of the test to add elabftw server
killianrochet May 25, 2023
0aa423e
Change the cli to allow the use of experiment_id only when --server e…
killianrochet May 25, 2023
d274b89
Change the cli to allow the use of experiment_id only when --server e…
killianrochet May 25, 2023
9919efa
Modification of the test for the elabftw server side
killianrochet May 25, 2023
ca54b10
Modification of the test for the elabftw server side
killianrochet May 25, 2023
32458df
Modification of the test for the elabftw server side
killianrochet May 25, 2023
f9c6dff
Modification of the test for the elabftw server side
killianrochet May 25, 2023
83b0ef3
Modification of download server elabftw to correct bug on the test
killianrochet May 25, 2023
a34c482
Modification of download server elabftw to correct bug on the test
killianrochet May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions redcap_bridge/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""
Provide CLI for the main functionalities of the redcap bridge
"""
import sys

from redcap_bridge.server_interface import download_records
from redcap_bridge.server_elab_interface import download_experiment


def main(command_line=None):
Expand All @@ -19,6 +21,8 @@ def main(command_line=None):
)

subparsers = parser.add_subparsers(dest='command')

# Download command
download = subparsers.add_parser('download', help='Downloads the data records')
killianrochet marked this conversation as resolved.
Show resolved Hide resolved
download.add_argument("destination", nargs=1, metavar='destination', type=str,
help="The destination filename.")
Expand All @@ -28,18 +32,29 @@ def main(command_line=None):
help="Format to store the data (json/csv)")
download.add_argument("-c", "--compressed", action='store_true',
help="Compress the output file (use labels and merge checkbox columns)")
download.add_argument("-s", "--server", type=str, nargs=1, metavar='server',
choices=['redcap', 'elabftw'], help="The two server choices are redcap or elabftw",
default='redcap')
download.add_argument("experiment_id", nargs='?', metavar='experiment_id', type=str,
help="Experiment id.")

# parse arguments
args = parser.parse_args(command_line)

if args.debug:
print("debug: " + str(args))

if args.command == 'download':
if not args.format:
args.format = ['csv']

download_records(args.destination[0], args.config_json[0], format=args.format[0],
compressed=bool(args.compressed))
if args.server == 'elabftw':
if not args.experiment_id:
parser.error("The experiment_id argument is required when --server elabftw is specified.")
download_experiment(args.config_json[0], args.experiment_id[0])
else:
download_records(args.destination[0], args.config_json[0], format=args.format[0],
compressed=bool(args.compressed))


if __name__ == '__main__':
Expand Down
7 changes: 7 additions & 0 deletions redcap_bridge/test_redcap/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ def test_download(initialize_test_dir):
stdout=subprocess.PIPE)
assert 'error' not in str(result.stdout)
assert pathlib.Path(output_file).exists()

# download with Elabftw server
result = subprocess.run(['RedCapBridge', 'download', SERVER_CONFIG_YAML, '--server', 'elabftw', '232'],
killianrochet marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are assuming the content of experiment id 232 on the server. However this won't work for another elab server or when the server is cleaned or someone manually deletes that experiment. It would be better to upload a known experiment first to then test the download function on that new experiment. Ideally you would also remove that experiment again from the server afterwards to keep everything in a clean state.

stdout=subprocess.PIPE)
assert 'error' not in str(result.stdout)
assert pathlib.Path(output_file).exists()