Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def custom_result_renderer(res, **kwargs):
from datalad.ui import ui
if res.get('action', None) == 'create' and \
res.get('status', None) == 'ok' and \
res.get('type', None) == 'dataset':
ui.message("Created dataset at {}.".format(res['path']))
else:
ui.message("Nothing was created")
return
if kwargs.get('discover', None):
ui.message('{name} ({path}){msg}'.format(
# bold-faced name, if active
name=ac.color_word(res['procedure_name'], ac.BOLD)
if res['state'] == 'executable' else res['procedure_name'],
path=res['path'],
msg=' [{}]'.format(
res['message'][0] % res['message'][1:]
if isinstance(res['message'], tuple) else res['message'])
if 'message' in res else ''
))
elif kwargs.get('help_proc', None):
ui.message('{name} ({path}){help}'.format(
name=ac.color_word(res['procedure_name'], ac.BOLD),
path=op.relpath(
res['path'],
res['refds'])
if res.get('refds', None) else res['path'],
help='{nl}{msg}'.format(
nl=os.linesep,
msg=res['message'][0] % res['message'][1:]
if isinstance(res['message'], tuple) else res['message'])
if 'message' in res else ''
))
else:
default_result_renderer(res)
def custom_result_renderer(res, **kwargs): # pragma: no cover
from datalad.ui import ui
if res.get('action', None) == 'create' and \
res.get('status', None) == 'ok' and \
res.get('type', None) == 'dataset':
ui.message("Created dataset at {}.".format(res['path']))
else:
ui.message("Nothing was created")
def result_renderer_cmdline(res, args):
from datalad.ui import ui
res = assure_list(res)
if args.dryrun:
ui.message('DRYRUN -- Anticipated results:')
if not len(res):
ui.message("Nothing done")
else:
for d, url, existed in res:
ui.message(
"'{}'{} configured as sibling '{}' for {}".format(
url,
" (existing repository)" if existed else '',
args.name,
d))
and res.get('state', None) != 'clean'):
# logging reported already
return
from datalad.ui import ui
# when to render relative paths:
# 1) if a dataset arg was given
# 2) if CWD is the refds
refds = res.get('refds', None)
refds = refds if kwargs.get('dataset', None) is not None \
or refds == os.getcwd() else None
path = res['path'] if refds is None \
else str(ut.Path(res['path']).relative_to(refds))
type_ = res.get('type', res.get('type_src', ''))
max_len = len('untracked')
state = res['state']
ui.message('{fill}{state}: {path}{type_}'.format(
fill=' ' * max(0, max_len - len(state)),
state=ut.ac.color_word(
state,
ut.state_color_map.get(res['state'], ut.ac.WHITE)),
path=path,
type_=' ({})'.format(
ut.ac.color_word(type_, ut.ac.MAGENTA) if type_ else '')))
def result_renderer_cmdline(res, args):
from datalad.ui import ui
res = assure_list(res)
if args.dryrun:
ui.message('DRYRUN -- Anticipated results:')
if not len(res):
ui.message("Nothing done")
else:
for d, url, existed in res:
ui.message(
"'{}'{} configured as sibling '{}' for {}".format(
url,
" (existing repository)" if existed else '',
args.name,
d))
else:
reraise(*exc_info)
else:
raise NoDatasetArgumentFound(
"No DataLad dataset found at current location. "
"The DataLad superdataset location %r exists, "
"but does not contain an dataset."
% DEFAULT_DATASET_PATH)
elif ui.yesno(
title="No DataLad dataset found at current location",
text="Would you like to install the DataLad "
"superdataset at %r?"
% DEFAULT_DATASET_PATH):
from datalad.api import install
default_ds = install(DEFAULT_DATASET_PATH, source='///')
ui.message(
"From now on you can refer to this dataset using the "
"label '///'"
)
else:
reraise(*exc_info)
lgr.info(
"Performing search using DataLad superdataset %r",
default_ds.path
)
for res in default_ds.search(query):
yield res
return
else:
raise # this function is called within exception handling block
from datalad.ui import ui
from os import linesep
if not len(res):
ui.message("Got nothing new")
return
nfiles = count_results(res, type='file')
nsuccess_file = count_results(res, type='file', status='ok')
nfailure = nfiles - nsuccess_file
msg = "Tried to get %d %s that had no content yet." % (
nfiles, single_or_plural("file", "files", nfiles))
if nsuccess_file:
msg += " Successfully obtained %d. " % nsuccess_file
if nfailure:
msg += " %d (failed)." % (nfailure,)
ui.message(msg)
# if just a few or less than initially explicitly requested
if len(res) < 10:
msg = linesep.join([
"{path}{type} ... {suc}".format(
suc=item.get('status'),
path=item.get('path'),
type=' [{}]'.format(item['type']) if 'type' in item else '')
for item in res])
ui.message(msg)
def custom_result_renderer(res, **kwargs): # pragma: more cover
from datalad.ui import ui
if res.get('action', None) == 'create' and \
res.get('status', None) == 'ok' and \
res.get('type', None) == 'dataset':
ui.message("Created dataset at {}.".format(res['path']))
else:
ui.message("Nothing was created")
def custom_result_renderer(res, **kwargs):
from datalad.ui import ui
if not res or res.get('type', None) != 'dataset' or 'path' not in res:
return
ds = Dataset(res['path'])
commit = ds.repo.get_hexsha()
ui.message('Saved state: {0} for {1}'.format(
commit,
ds))