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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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
killianrochet committed May 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 07c60ecbe57ec41e8725c910d54685896da99a29
62 changes: 26 additions & 36 deletions redcap_bridge/cli.py
Original file line number Diff line number Diff line change
@@ -11,58 +11,48 @@ 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',
action='store_true',
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')
killianrochet marked this conversation as resolved.
Show resolved Hide resolved
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__':