Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 27 additions & 10 deletions datalad_xnat/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,34 @@ def __call__(url,
'anonymous' if platform.credential_name == 'anonymous'
else platform.authenticated_user)
projects = platform.get_project_ids()
ui.message(
'No project name specified. The following projects are '
'available on {} for user {}:'.format(
from datalad.ui import ui
if ui.is_interactive:
import inquirer
from inquirer.themes import GreenPassion
message = 'Select a project via arrow keys, ' \
'confirm with "Enter"'.format(
url,
'anonymous' if platform.credential_name == 'anonymous'
else platform.authenticated_user))
for p in sorted(projects):
# list and prep for C&P
# TODO multi-column formatting?
ui.message(" {}".format(quote_cmdlinearg(p)))
return
'anonymous' if platform.credential_name == 'anonymous' \
else platform.authenticated_user)
checkbox = [inquirer.List('project',
message=message,
choices=sorted(projects))]
resp = inquirer.prompt(checkbox, theme=GreenPassion())
lgr.info("Received the following project selection from the "
"interactive prompt: %s", str(resp['project']))
project = resp['project']
else:
ui.message(
'No project name specified. The following projects are '
'available on {} for user {}:'.format(
url,
'anonymous' if platform.credential_name == 'anonymous'
else platform.authenticated_user))
for p in sorted(projects):
# list and prep for C&P
# TODO multi-column formatting?
ui.message(" {}".format(quote_cmdlinearg(p)))
return

# query the specified project to make sure it exists and is accessible
try:
Expand Down
46 changes: 36 additions & 10 deletions datalad_xnat/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,43 @@ def __call__(subjects='list', credential=None, dataset=None, ifexists=None, reck

# provide subject list
if 'list' in subjects:
from datalad.ui import ui
subs = platform.get_subject_ids(xnat_project)
ui.message(
'The following subjects are available for XNAT '
'project {}:'.format(xnat_project))
for s in sorted(subs):
ui.message(" {}".format(quote_cmdlinearg(s)))
ui.message(
'Specify a specific subject(s) or "all" to download associated '
'files for.')
return
from datalad.ui import ui
if ui.is_interactive:
import inquirer
from inquirer.themes import GreenPassion
hit = False
subs.insert(0, 'all')
subs.insert(1, 'cancel')
while not hit:
message = 'Select subject(s) to download from ' \
'Project "{}" via arrow keys. ' \
'Confirm with "Enter"'.format(xnat_project)
checkbox = [inquirer.Checkbox('subject',
message=message,
choices=subs)]
resp = inquirer.prompt(checkbox, theme=GreenPassion())
if resp['subject']:
hit = True
else:
ui.message("Please select one or more subjects using "
"the right arrow keys. Unselect with the "
"left arrow key.")
if 'cancel' in resp['subject']:
return
lgr.info("Received the following subject list from an "
"interactive prompt: %s", str(resp['subject']))
subjects = resp['subject']
else:
ui.message(
'The following subjects are available for XNAT '
'project {}:'.format(xnat_project))
for s in sorted(subs):
ui.message(" {}".format(quote_cmdlinearg(s)))
ui.message(
'Specify a specific subject(s) or "all" to download associated '
'files for.')
return

# query the specified subject(s) to make sure it exists and is accessible
# TODO we culd just take the input subject list at face-value
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python_requires = >= 3.6
install_requires =
datalad >= 0.15.0
requests
inquirer
packages = find:
include_package_data = True

Expand Down