Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Francesco Sforazzini
XnatUtils
Commits
1075a902
Commit
1075a902
authored
Apr 21, 2017
by
Tom Close
Browse files
cleaned up argparse
parent
ec9868f7
Changes
6
Hide whitespace changes
Inline
Side-by-side
bin/xnat-get
View file @
1075a902
...
...
@@ -34,15 +34,17 @@ credentials.
"""
import
os.path
import
argparse
from
xnatutils
import
get
,
XnatUtilsUsageError
,
data_format_exts
from
xnatutils
import
get
,
XnatUtilsUsageError
,
data_format_exts
,
__version__
conv_choices
=
[
f
.
lower
()
for
f
in
data_format_exts
if
f
!=
'DICOM'
]
converter_choices
=
(
'dcm2niix'
,
'mrconvert'
)
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
.
add_argument
(
'session'
,
type
=
str
,
nargs
=
'+'
,
help
=
"Name of the session(s) to download the dataset from"
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'session_or_regex'
,
type
=
str
,
nargs
=
'+'
,
help
=
(
"Name or regular expression of the session(s) to "
"download the dataset from"
))
parser
.
add_argument
(
'--target'
,
'-t'
,
type
=
str
,
default
=
None
,
help
=
(
"Path to download the scans to. If not provided the "
"current working directory will be used"
))
...
...
@@ -83,6 +85,8 @@ parser.add_argument('--strip_name', '-n', action='store_true', default=False,
help
=
(
"Whether to strip the default name of each dicom"
" file to have just a number. Ex. 0001.dcm. It will"
" work just on DICOM files, not NIFTI."
))
parser
.
add_argument
(
'--version'
,
'-V'
,
action
=
'version'
,
version
=
'%(prog)s '
+
__version__
)
args
=
parser
.
parse_args
()
...
...
@@ -92,7 +96,7 @@ else:
download_dir
=
os
.
path
.
expanduser
(
args
.
target
)
try
:
get
(
args
.
session
,
download_dir
,
scans
=
args
.
scans
,
get
(
args
.
session
_or_regex
,
download_dir
,
scans
=
args
.
scans
,
data_format
=
args
.
format
,
with_scans
=
args
.
with_scans
,
without_scans
=
args
.
without_scans
,
convert_to
=
args
.
convert_to
,
converter
=
args
.
converter
,
subject_dirs
=
args
.
subject_dirs
,
...
...
bin/xnat-ls
View file @
1075a902
...
...
@@ -25,14 +25,16 @@ exist the tool will ask whether to create a ~/.netrc file with the given
credentials.
"""
import
argparse
from
xnatutils
import
ls
,
XnatUtilsUsageError
from
xnatutils
import
ls
,
XnatUtilsUsageError
,
__version__
DATATYPES
=
(
'project'
,
'subject'
,
'session'
,
'scan'
)
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
.
add_argument
(
'id'
,
type
=
str
,
nargs
=
'*'
,
help
=
"The ID of the project/subject/session to list from"
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'id_or_regex'
,
type
=
str
,
nargs
=
'*'
,
help
=
(
"The ID or regular expression of the "
"project/subject/session to list from."
))
parser
.
add_argument
(
'--datatype'
,
'-d'
,
type
=
str
,
choices
=
DATATYPES
,
default
=
None
,
help
=
(
"The data type to list, can be one of '{}'"
...
...
@@ -45,11 +47,13 @@ parser.add_argument('--without_scans', '-o', type=str, default=None, nargs='+',
"specified scans"
))
parser
.
add_argument
(
'--user'
,
'-u'
,
type
=
str
,
default
=
None
,
help
=
(
"The user to connect to MBI-XNAT with"
))
parser
.
add_argument
(
'--version'
,
'-V'
,
action
=
'version'
,
version
=
'%(prog)s '
+
__version__
)
args
=
parser
.
parse_args
()
try
:
print
'
\n
'
.
join
(
ls
(
args
.
id
,
datatype
=
args
.
datatype
,
user
=
args
.
user
,
with_scans
=
args
.
with_scans
,
print
'
\n
'
.
join
(
ls
(
args
.
id
_or_regex
,
datatype
=
args
.
datatype
,
user
=
args
.
user
,
with_scans
=
args
.
with_scans
,
without_scans
=
args
.
without_scans
))
except
XnatUtilsUsageError
as
e
:
print
e
...
...
bin/xnat-put
View file @
1075a902
...
...
@@ -20,9 +20,10 @@ credentials.
"""
import
argparse
import
re
from
xnatutils
import
put
,
XnatUtilsUsageError
from
xnatutils
import
put
,
XnatUtilsUsageError
,
__version__
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'filename'
,
type
=
str
,
help
=
"Filename of the dataset to upload to XNAT"
)
parser
.
add_argument
(
'session'
,
type
=
str
,
...
...
@@ -42,6 +43,8 @@ parser.add_argument('--format', '-f', type=str, default=None,
"in most cases it won't be necessary to specify"
))
parser
.
add_argument
(
'--user'
,
'-u'
,
type
=
str
,
default
=
None
,
help
=
(
"The user to connect to MBI-XNAT with"
))
parser
.
add_argument
(
'--version'
,
'-V'
,
action
=
'version'
,
version
=
'%(prog)s '
+
__version__
)
args
=
parser
.
parse_args
()
try
:
...
...
bin/xnat-varget
View file @
1075a902
...
...
@@ -10,9 +10,10 @@ credentials.
"""
from
__future__
import
print_function
import
argparse
from
xnatutils
import
varget
,
XnatUtilsUsageError
from
xnatutils
import
varget
,
XnatUtilsUsageError
,
__version__
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'subject_or_session_id'
,
type
=
str
,
help
=
"Name of subject or session to get the variable from"
)
parser
.
add_argument
(
'variable'
,
type
=
str
,
...
...
@@ -21,6 +22,8 @@ parser.add_argument('--default', type=str, default='',
help
=
"Default value if object does not have a value"
)
parser
.
add_argument
(
'--user'
,
'-u'
,
type
=
str
,
default
=
None
,
help
=
(
"The user to connect to MBI-XNAT with"
))
parser
.
add_argument
(
'--version'
,
'-V'
,
action
=
'version'
,
version
=
'%(prog)s '
+
__version__
)
args
=
parser
.
parse_args
()
try
:
...
...
bin/xnat-varput
View file @
1075a902
...
...
@@ -10,9 +10,10 @@ credentials.
"""
import
argparse
import
re
from
xnatutils
import
varput
,
XnatUtilsUsageError
from
xnatutils
import
varput
,
XnatUtilsUsageError
,
__version__
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
parser
.
add_argument
(
'subject_or_session_id'
,
type
=
str
,
help
=
"Name of subject or session to set the variable of"
)
parser
.
add_argument
(
'variable'
,
type
=
str
,
...
...
@@ -20,6 +21,8 @@ parser.add_argument('variable', type=str,
parser
.
add_argument
(
'value'
,
help
=
"Value of the variable"
)
parser
.
add_argument
(
'--user'
,
'-u'
,
type
=
str
,
default
=
None
,
help
=
(
"The user to connect to MBI-XNAT with"
))
parser
.
add_argument
(
'--version'
,
'-V'
,
action
=
'version'
,
version
=
'%(prog)s '
+
__version__
)
args
=
parser
.
parse_args
()
...
...
xnatutils.py
View file @
1075a902
...
...
@@ -9,6 +9,8 @@ import xnat
from
xnat.exceptions
import
XNATResponseError
import
warnings
__version__
=
'0.1'
MBI_XNAT_SERVER
=
'https://mbi-xnat.erc.monash.edu.au'
data_format_exts
=
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment