From 1fae8fcaba0ee975ba4ea86cb551181781486d68 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Mon, 22 May 2023 11:32:44 +0200 Subject: [PATCH 01/18] Modification of the CLI to include the use of ElabFTW methods. The methods / options will be modified as the methods are developed --- redcap_bridge/cli.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 65b375ad..4b1aec10 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -3,6 +3,7 @@ """ from redcap_bridge.server_interface import download_records +from redcap_bridge.server_elab_interface import download_experiment def main(command_line=None): @@ -10,7 +11,7 @@ def main(command_line=None): import argparse # create a parser object - parser = argparse.ArgumentParser(description="A simple Python interface for RedCap") + parser = argparse.ArgumentParser(description="A simple Python interface for RedCap and ElabFTW") parser.add_argument( '--debug', @@ -18,7 +19,11 @@ def main(command_line=None): help='Print debug info' ) + parser.add_argument('--redcap', action='store_true', help='Use RedCap') + parser.add_argument('--elabftw', action='store_true', help='Use ElabFTW') + subparsers = parser.add_subparsers(dest='command') + download = subparsers.add_parser('download', help='Downloads the data records') download.add_argument("destination", nargs=1, metavar='destination', type=str, help="The destination filename.") @@ -29,18 +34,36 @@ def main(command_line=None): download.add_argument("-c", "--compressed", action='store_true', help="Compress the output file (use labels and merge checkbox columns)") - # parse arguments + # Options for downloading Elab. To be modified afterwards + elabftw = subparsers.add_parser('elabftw', help='Downloads the data records from ElabFTW') + elabftw.add_argument("config_json", nargs=1, metavar='config_json', type=str, + help="The json configuration file of the project") + elabftw.add_argument("experiment_id", nargs=1, metavar='config_json', type=str, + help="The experiment id") + args = parser.parse_args(command_line) if args.debug: print("debug: " + str(args)) + + # We need to have 1 option + if not args.redcap and not args.elabftw: + parser.error("Please specify either --redcap or --elabftw") + + # Only elab or redcap as options choosing both is not possible + if args.redcap and args.elabftw: + parser.error("Please specify only one of --redcap or --elabftw") + 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.redcap: + download_records(args.destination[0], args.config_json[0], format=args.format[0], + compressed=bool(args.compressed)) + elif args.elabftw: + download_experiment(args.config_json[0], args.experiment_id[0]) if __name__ == '__main__': - main() + main() \ No newline at end of file From 07c60ecbe57ec41e8725c910d54685896da99a29 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Mon, 22 May 2023 14:27:07 +0200 Subject: [PATCH 02/18] Modification of the CLI: Removed the addition of a new parser. Now only one option added to define if we want to use the RedCap server or the ElabFTW server --- redcap_bridge/cli.py | 62 +++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 4b1aec10..e79be7c9 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -11,7 +11,7 @@ def main(command_line=None): import argparse # create a parser object - parser = argparse.ArgumentParser(description="A simple Python interface for RedCap and ElabFTW") + parser = argparse.ArgumentParser(description="A simple Python interface for RedCap and elabftw") parser.add_argument( '--debug', @@ -19,50 +19,40 @@ def main(command_line=None): help='Print debug info' ) - parser.add_argument('--redcap', action='store_true', help='Use RedCap') - parser.add_argument('--elabftw', action='store_true', help='Use ElabFTW') - - subparsers = parser.add_subparsers(dest='command') - - download = subparsers.add_parser('download', help='Downloads the data records') - download.add_argument("destination", nargs=1, metavar='destination', type=str, - help="The destination filename.") - download.add_argument("config_json", nargs=1, metavar='config_json', type=str, - help="The json configuration file of the project") - download.add_argument("-f", "--format", type=str, nargs=1, metavar='format', - 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)") - - # Options for downloading Elab. To be modified afterwards - elabftw = subparsers.add_parser('elabftw', help='Downloads the data records from ElabFTW') - elabftw.add_argument("config_json", nargs=1, metavar='config_json', type=str, - help="The json configuration file of the project") - elabftw.add_argument("experiment_id", nargs=1, metavar='config_json', type=str, - help="The experiment id") + parser.add_argument( + 'command', + choices=['redcap', 'elabftw'], + help='Choose the server to download from (redcap or elabftw)' + ) + parser.add_argument("destination", metavar='destination', type=str, + help="The destination filename.") + parser.add_argument("config_json", metavar='config_json', type=str, + help="The json configuration file of the project") + parser.add_argument("-f", "--format", type=str, metavar='format', + help="Format to store the data (json/csv)") + parser.add_argument("-c", "--compressed", action='store_true', + help="Compress the output file (use labels and merge checkbox columns)") + parser.add_argument("experiment_id", metavar='experiment', type=str, + help="Experiment id") + + # parse arguments args = parser.parse_args(command_line) if args.debug: print("debug: " + str(args)) - # We need to have 1 option - if not args.redcap and not args.elabftw: - parser.error("Please specify either --redcap or --elabftw") - - # Only elab or redcap as options choosing both is not possible - if args.redcap and args.elabftw: - parser.error("Please specify only one of --redcap or --elabftw") + if args.command == 'redcap': + if not args.format: + args.format = 'csv' - if args.command == 'download': + download_records(args.destination, args.config_json, format=args.format, + compressed=bool(args.compressed)) + elif args.command == 'elabftw': if not args.format: - args.format = ['csv'] + args.format = 'csv' - if args.redcap: - download_records(args.destination[0], args.config_json[0], format=args.format[0], - compressed=bool(args.compressed)) - elif args.elabftw: - download_experiment(args.config_json[0], args.experiment_id[0]) + download_experiment(args.config_json, args.experiment_id) if __name__ == '__main__': From 473cd59d5e821898daf2fd7018b7fe33a42b3e93 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Mon, 22 May 2023 15:07:49 +0200 Subject: [PATCH 03/18] Modification of the CLI: Removed the addition of a new parser. Now only one option added to define if we want to use the RedCap server or the ElabFTW server --- redcap_bridge/cli.py | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index e79be7c9..9bff1b34 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -11,7 +11,7 @@ def main(command_line=None): import argparse # create a parser object - parser = argparse.ArgumentParser(description="A simple Python interface for RedCap and elabftw") + parser = argparse.ArgumentParser(description="A simple Python interface for RedCap") parser.add_argument( '--debug', @@ -19,22 +19,22 @@ def main(command_line=None): help='Print debug info' ) - parser.add_argument( - 'command', - choices=['redcap', 'elabftw'], - help='Choose the server to download from (redcap or elabftw)' - ) - - parser.add_argument("destination", metavar='destination', type=str, - help="The destination filename.") - parser.add_argument("config_json", metavar='config_json', type=str, - help="The json configuration file of the project") - parser.add_argument("-f", "--format", type=str, metavar='format', - help="Format to store the data (json/csv)") - parser.add_argument("-c", "--compressed", action='store_true', - help="Compress the output file (use labels and merge checkbox columns)") - parser.add_argument("experiment_id", metavar='experiment', type=str, - help="Experiment id") + subparsers = parser.add_subparsers(dest='command') + + # Download command + download = subparsers.add_parser('download', help='Downloads the data records') + download.add_argument("destination", nargs=1, metavar='destination', type=str, + help="The destination filename.") + download.add_argument("config_json", nargs=1, metavar='config_json', type=str, + help="The json configuration file of the project") + download.add_argument("-f", "--format", type=str, nargs=1, metavar='format', + 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("--serveur", type=str, nargs=1, metavar='serveur', + help="Server name") + download.add_argument("experiment_id", nargs=1, metavar='experiment_id', type=str, + help="Experiment id.") # parse arguments args = parser.parse_args(command_line) @@ -42,18 +42,18 @@ def main(command_line=None): if args.debug: print("debug: " + str(args)) - if args.command == 'redcap': - if not args.format: - args.format = 'csv' - - download_records(args.destination, args.config_json, format=args.format, - compressed=bool(args.compressed)) - elif args.command == 'elabftw': + if args.command == 'download': if not args.format: - args.format = 'csv' + args.format = ['csv'] - download_experiment(args.config_json, args.experiment_id) + if args.serveur[0] == 'redcap': + download_records(args.destination[0], args.config_json[0], format=args.format[0], + compressed=bool(args.compressed)) + elif args.serveur[0] == 'elabftw': + download_experiment(args.config_json[0], args.experiment_id[0]) + else: + print("Unknown server name.") if __name__ == '__main__': - main() \ No newline at end of file + main() From 6332ece9dae01a73f34a6e23d42a97720d54aaac Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Wed, 24 May 2023 14:37:58 +0200 Subject: [PATCH 04/18] Modification of the CLI: Modification of the test function for the CLI --- redcap_bridge/cli.py | 2 +- redcap_bridge/test_redcap/test_cli.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 9bff1b34..d384ce1d 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -31,7 +31,7 @@ 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("--serveur", type=str, nargs=1, metavar='serveur', + download.add_argument("--server", type=str, nargs=1, metavar='server', help="Server name") download.add_argument("experiment_id", nargs=1, metavar='experiment_id', type=str, help="Experiment id.") diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index 6fc60774..458fecfe 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -30,15 +30,15 @@ def test_download(initialize_test_dir): output_file = test_directory / 'cli_download_test.csv' # download with default arguments - result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML], + result = subprocess.run(['RedCapBridge', 'redcap', 'download', output_file, SERVER_CONFIG_YAML, 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert output_file.exists() output_file.unlink() # download in compressed mode - result = subprocess.run(['RedCapBridge', 'download', '--compressed', output_file, - SERVER_CONFIG_YAML], + result = subprocess.run(['RedCapBridge', 'redcap', 'download', '--compressed', output_file, + SERVER_CONFIG_YAML, 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() @@ -46,7 +46,7 @@ def test_download(initialize_test_dir): # download with format argument result = subprocess.run(['RedCapBridge', 'download', '--format', 'csv', output_file, - SERVER_CONFIG_YAML], + SERVER_CONFIG_YAML, 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() From 801d8604b7f3d3b90c97bdaae6b8040ece00b077 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Wed, 24 May 2023 14:40:48 +0200 Subject: [PATCH 05/18] Modification of the CLI: Modification of the test function for the CLI --- redcap_bridge/test_redcap/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index 458fecfe..938f0138 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -30,14 +30,14 @@ def test_download(initialize_test_dir): output_file = test_directory / 'cli_download_test.csv' # download with default arguments - result = subprocess.run(['RedCapBridge', 'redcap', 'download', output_file, SERVER_CONFIG_YAML, 'redcap'], + result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML, 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert output_file.exists() output_file.unlink() # download in compressed mode - result = subprocess.run(['RedCapBridge', 'redcap', 'download', '--compressed', output_file, + result = subprocess.run(['RedCapBridge', 'download', '--compressed', output_file, SERVER_CONFIG_YAML, 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) From 92eb98fccba263d7d486b39545a54448e2ae03e8 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Wed, 24 May 2023 14:42:43 +0200 Subject: [PATCH 06/18] Modification of the CLI: Modification of the test function for the CLI --- redcap_bridge/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index d384ce1d..81651f76 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -46,10 +46,10 @@ def main(command_line=None): if not args.format: args.format = ['csv'] - if args.serveur[0] == 'redcap': + if args.server[0] == 'redcap': download_records(args.destination[0], args.config_json[0], format=args.format[0], compressed=bool(args.compressed)) - elif args.serveur[0] == 'elabftw': + elif args.server[0] == 'elabftw': download_experiment(args.config_json[0], args.experiment_id[0]) else: print("Unknown server name.") From 7f1fb4657df6f5202989ca16d2af8567b5c3b663 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Wed, 24 May 2023 14:54:19 +0200 Subject: [PATCH 07/18] Add a default value for the server variable Modification of the CLI tests --- redcap_bridge/cli.py | 2 +- redcap_bridge/test_redcap/test_cli.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 81651f76..5d979928 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -32,7 +32,7 @@ def main(command_line=None): download.add_argument("-c", "--compressed", action='store_true', help="Compress the output file (use labels and merge checkbox columns)") download.add_argument("--server", type=str, nargs=1, metavar='server', - help="Server name") + help="The two server choices are redcap or elabftw", default='redcap') download.add_argument("experiment_id", nargs=1, metavar='experiment_id', type=str, help="Experiment id.") diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index 938f0138..1f2f51fe 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -30,7 +30,7 @@ def test_download(initialize_test_dir): output_file = test_directory / 'cli_download_test.csv' # download with default arguments - result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML, 'redcap'], + result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML, '--server', 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert output_file.exists() @@ -38,7 +38,7 @@ def test_download(initialize_test_dir): # download in compressed mode result = subprocess.run(['RedCapBridge', 'download', '--compressed', output_file, - SERVER_CONFIG_YAML, 'redcap'], + SERVER_CONFIG_YAML, '--server', 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() @@ -46,7 +46,7 @@ def test_download(initialize_test_dir): # download with format argument result = subprocess.run(['RedCapBridge', 'download', '--format', 'csv', output_file, - SERVER_CONFIG_YAML, 'redcap'], + SERVER_CONFIG_YAML, '--server', 'redcap'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() From 12ead0cfa81f2dcdbf3c5ff5208314c5b745d27b Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:16:22 +0200 Subject: [PATCH 08/18] Add conditional argument. When --server elabftw is selected for download experiment_id is required --- redcap_bridge/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 5d979928..5b3e7ed4 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -1,6 +1,7 @@ """ 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 @@ -31,9 +32,10 @@ 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("--server", type=str, nargs=1, metavar='server', + download.add_argument("--server", required=False, type=str, nargs=1, metavar='server', help="The two server choices are redcap or elabftw", default='redcap') - download.add_argument("experiment_id", nargs=1, metavar='experiment_id', type=str, + download.add_argument("experiment_id", required='--server elabftw' in sys.argv, nargs=1, metavar='experiment_id', + type=str, help="Experiment id.") # parse arguments From 4852afa015bb0bb3e977603f18a2b1b7cea20519 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:21:31 +0200 Subject: [PATCH 09/18] Add conditional argument. When --server elabftw is selected for download experiment_id is required --- redcap_bridge/cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 5b3e7ed4..175efb18 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -34,16 +34,18 @@ def main(command_line=None): help="Compress the output file (use labels and merge checkbox columns)") download.add_argument("--server", required=False, type=str, nargs=1, metavar='server', help="The two server choices are redcap or elabftw", default='redcap') - download.add_argument("experiment_id", required='--server elabftw' in sys.argv, nargs=1, metavar='experiment_id', - type=str, - help="Experiment id.") + download.add_argument("experiment_id", nargs='?', metavar='experiment_id', type=str, help="Experiment id.") # parse arguments - args = parser.parse_args(command_line) + args, experiment_argument = parser.parse_known_args(command_line) if args.debug: print("debug: " + str(args)) + if args.command == 'download' and args.server != 'elabftw': + if 'experiment_id' in experiment_argument: + parser.error("Argument 'experiment_id' is only allowed when '--server elabftw' is specified.") + if args.command == 'download': if not args.format: args.format = ['csv'] @@ -52,7 +54,7 @@ def main(command_line=None): download_records(args.destination[0], args.config_json[0], format=args.format[0], compressed=bool(args.compressed)) elif args.server[0] == 'elabftw': - download_experiment(args.config_json[0], args.experiment_id[0]) + download_experiment(args.config_json[0], args.experiment_id) else: print("Unknown server name.") From 718940037bce7a001c14ccd7f562f8117eee4308 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:35:48 +0200 Subject: [PATCH 10/18] Modification of the test to add elabftw server --- redcap_bridge/cli.py | 11 ++++------- redcap_bridge/test_redcap/test_cli.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 175efb18..659106ef 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -32,20 +32,17 @@ 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("--server", required=False, type=str, nargs=1, metavar='server', + download.add_argument("-s", "--server", type=str, nargs=1, metavar='server', 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.") + download.add_argument("experiment_id", required=False, nargs=1, metavar='experiment_id', type=str, + help="Experiment id.") # parse arguments - args, experiment_argument = parser.parse_known_args(command_line) + args = parser.parse_known_args(command_line) if args.debug: print("debug: " + str(args)) - if args.command == 'download' and args.server != 'elabftw': - if 'experiment_id' in experiment_argument: - parser.error("Argument 'experiment_id' is only allowed when '--server elabftw' is specified.") - if args.command == 'download': if not args.format: args.format = ['csv'] diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index 1f2f51fe..a9a35075 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -30,7 +30,7 @@ def test_download(initialize_test_dir): output_file = test_directory / 'cli_download_test.csv' # download with default arguments - result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML, '--server', 'redcap'], + result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert output_file.exists() @@ -38,7 +38,7 @@ def test_download(initialize_test_dir): # download in compressed mode result = subprocess.run(['RedCapBridge', 'download', '--compressed', output_file, - SERVER_CONFIG_YAML, '--server', 'redcap'], + SERVER_CONFIG_YAML], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() @@ -46,7 +46,15 @@ def test_download(initialize_test_dir): # download with format argument result = subprocess.run(['RedCapBridge', 'download', '--format', 'csv', output_file, - SERVER_CONFIG_YAML, '--server', 'redcap'], + SERVER_CONFIG_YAML], 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', '--format', 'csv', output_file, + SERVER_CONFIG_YAML, '--server', 'elabftw', 232], + stdout=subprocess.PIPE) + assert 'error' not in str(result.stdout) + assert pathlib.Path(output_file).exists() + From 0aa423e7c159308acff83994cc5d827d3968c797 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:47:00 +0200 Subject: [PATCH 11/18] Change the cli to allow the use of experiment_id only when --server elabftw is provided --- redcap_bridge/cli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 659106ef..c8a7cb80 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -33,7 +33,8 @@ def main(command_line=None): 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', - help="The two server choices are redcap or elabftw", default='redcap') + choices=['redcap', 'elabftw'], help="The two server choices are redcap or elabftw", + default='redcap') download.add_argument("experiment_id", required=False, nargs=1, metavar='experiment_id', type=str, help="Experiment id.") @@ -47,13 +48,13 @@ def main(command_line=None): if not args.format: args.format = ['csv'] - if args.server[0] == 'redcap': + 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)) - elif args.server[0] == 'elabftw': - download_experiment(args.config_json[0], args.experiment_id) - else: - print("Unknown server name.") if __name__ == '__main__': From d274b897777fc71475ac605d184140ad0b1a0453 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:50:41 +0200 Subject: [PATCH 12/18] Change the cli to allow the use of experiment_id only when --server elabftw is provided --- redcap_bridge/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index c8a7cb80..9a8ba29a 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -35,7 +35,7 @@ def main(command_line=None): 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", required=False, nargs=1, metavar='experiment_id', type=str, + download.add_argument("experiment_id", nargs='?', metavar='experiment_id', type=str, help="Experiment id.") # parse arguments From 9919efabe4c7e5bc68d56615bfcf8d64607bf74e Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:53:56 +0200 Subject: [PATCH 13/18] Modification of the test for the elabftw server side --- redcap_bridge/cli.py | 2 +- redcap_bridge/test_redcap/test_cli.py | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 9a8ba29a..90cc35c3 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -35,7 +35,7 @@ def main(command_line=None): 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, + download.add_argument("experiment_id", nargs='?', metavar='experiment_id', type=int, help="Experiment id.") # parse arguments diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index a9a35075..6fc60774 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -50,11 +50,3 @@ 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', '--format', 'csv', output_file, - SERVER_CONFIG_YAML, '--server', 'elabftw', 232], - stdout=subprocess.PIPE) - assert 'error' not in str(result.stdout) - assert pathlib.Path(output_file).exists() - From ca54b10271fed3cbaf93615e9834f5df87746096 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 14:56:08 +0200 Subject: [PATCH 14/18] Modification of the test for the elabftw server side --- redcap_bridge/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index 90cc35c3..c6aa4643 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -39,7 +39,7 @@ def main(command_line=None): help="Experiment id.") # parse arguments - args = parser.parse_known_args(command_line) + args = parser.parse_args(command_line) if args.debug: print("debug: " + str(args)) From 32458df2591f85f191d3b6df8a3f6866e1181a2d Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 15:02:24 +0200 Subject: [PATCH 15/18] Modification of the test for the elabftw server side Adding of elabftw test download --- redcap_bridge/test_redcap/test_cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index 6fc60774..a9a35075 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -50,3 +50,11 @@ 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', '--format', 'csv', output_file, + SERVER_CONFIG_YAML, '--server', 'elabftw', 232], + stdout=subprocess.PIPE) + assert 'error' not in str(result.stdout) + assert pathlib.Path(output_file).exists() + From f9c6dff0be2c00f9eb3f8426993b2abae45eef6b Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 15:34:19 +0200 Subject: [PATCH 16/18] Modification of the test for the elabftw server side Adding of elabftw test download --- redcap_bridge/test_redcap/test_cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index a9a35075..ff74696f 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -52,8 +52,7 @@ def test_download(initialize_test_dir): assert pathlib.Path(output_file).exists() # download with Elabftw server - result = subprocess.run(['RedCapBridge', 'download', '--format', 'csv', output_file, - SERVER_CONFIG_YAML, '--server', 'elabftw', 232], + result = subprocess.run(['RedCapBridge', 'download', SERVER_CONFIG_YAML, '--server', 'elabftw', 232], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists() From 83b0ef3be4cddad2dfb6bd953b068e8332beb05b Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 15:36:58 +0200 Subject: [PATCH 17/18] Modification of download server elabftw to correct bug on the test --- redcap_bridge/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redcap_bridge/cli.py b/redcap_bridge/cli.py index c6aa4643..3ec59295 100644 --- a/redcap_bridge/cli.py +++ b/redcap_bridge/cli.py @@ -35,7 +35,7 @@ def main(command_line=None): 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=int, + download.add_argument("experiment_id", nargs='?', metavar='experiment_id', type=str, help="Experiment id.") # parse arguments From a34c4820ed05b13cc2fabe51bf3347b9dbe0d94c Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Thu, 25 May 2023 15:39:58 +0200 Subject: [PATCH 18/18] Modification of download server elabftw to correct bug on the test --- redcap_bridge/test_redcap/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redcap_bridge/test_redcap/test_cli.py b/redcap_bridge/test_redcap/test_cli.py index ff74696f..33e25e17 100644 --- a/redcap_bridge/test_redcap/test_cli.py +++ b/redcap_bridge/test_redcap/test_cli.py @@ -52,7 +52,7 @@ def test_download(initialize_test_dir): assert pathlib.Path(output_file).exists() # download with Elabftw server - result = subprocess.run(['RedCapBridge', 'download', SERVER_CONFIG_YAML, '--server', 'elabftw', 232], + result = subprocess.run(['RedCapBridge', 'download', SERVER_CONFIG_YAML, '--server', 'elabftw', '232'], stdout=subprocess.PIPE) assert 'error' not in str(result.stdout) assert pathlib.Path(output_file).exists()