Commit f5eb8cb8 authored by Taylor Hanayik's avatar Taylor Hanayik
Browse files

rename and add options

parent 9ef6774b
......@@ -2,42 +2,65 @@
# or ^ fslpython
import argparse
import os
from sys import exit
from os.path import abspath, join, exists
from os import getcwd
import sys
from subprocess import run
from shutil import rmtree
pwd = os.getcwd
pwd = abspath(getcwd())
# describe the commandline tool
parser = argparse.ArgumentParser(
description="download a dataset from openneuro.org"
)
)
# id must be a string and is not optional
parser.add_argument(
'id',
'id',
type=str,
help="a dataset ID. Openneuro.org provides these in the form of ds###### (e.g. ds002190)"
)
# savepath must be a string and is optional. the default is the current working dir
parser.add_argument(
'--savepath',
'--savepath',
type=str,
help="the output directory where you would like to download the dataset (default is the current working directory + the dataset id)",
default=pwd(),
help="the output directory where you would like to download the dataset (default is the current working directory)",
default=pwd,
)
# savename is an optional name to give the downloaded dataset folder. The default is the dataset id.
parser.add_argument(
'--savename',
type=str,
help="savename is an optional name to give the downloaded dataset folder. The default is the dataset id.",
default=None,
)
# overwrite is a boolean flag and is optional. The default is false (no overwriting)
parser.add_argument(
'--w',
help="overwrite existing dataset with the same ID if it already exists in the savepath",
default=False,
action='store_true'
)
if __name__ == "__main__":
def main():
args = parser.parse_args()
savepath = os.path.join(
args.savepath, args.id
)
if os.path.exists(savepath):
print("ERROR: savepath {} already exists, not overwriting.".format(savepath))
exit(1)
savename = args.savename
if savename is None:
savename = args.id
savepath = abspath(
join(
args.savepath, savename
)
)
overwrite = args.w
if exists(savepath):
if not overwrite:
print("ERROR: savepath {} already exists, not overwriting. Try the --w flag if you wish to re-sync the data with what appears on openneuro".format(savepath))
sys.exit(1)
if args.id[:2] != "ds":
print("ERROR: a dataset id must start with 'ds'. Please check your dataset id")
exit(1)
print("ERROR: an openneuro dataset id must start with 'ds'. Please check your dataset id")
sys.exit(1)
# use subprocess.run to call the aws command to sync from the aws bucket (download the dataset)
run(
......@@ -54,5 +77,5 @@ if __name__ == "__main__":
)
if __name__ == "__main__":
sys.exit(main())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment