Exemplo n.º 1
0
def test_default_result_renderer():
    # a bunch of bad cases of results
    testcases = [
        # an empty result will surface
        ({}, ['<action-unspecified>(<status-unspecified>)']),
        # non-standard status makes it out again
        (dict(status='funky'), ['<action-unspecified>(funky)']),
        # just an action result is enough to get some output
        (dict(action='funky'), ['funky(<status-unspecified>)']),
        # a plain path produces output, although
        (dict(path='funky'), ['<action-unspecified>(<status-unspecified>): funky']),
        # plain type makes it through
        (dict(type='funky'),
         ['<action-unspecified>(<status-unspecified>): (funky)']),
        # plain message makes it through
        (dict(message='funky'),
         ['<action-unspecified>(<status-unspecified>): [funky]']),
    ]
    if on_windows:
        testcases.extend([
            # if relpath'ing is not possible, takes the path verbatim
            (dict(path='C:\\funky', refds='D:\\medina'),
             ['<action-unspecified>(<status-unspecified>): C:\\funky']),
        ])
    else:
        testcases.extend([
            (dict(path='/funky/cold/medina', refds='/funky'),
             ['<action-unspecified>(<status-unspecified>): cold/medina']),
        ])
    for result, contenttests in testcases:
        with swallow_outputs() as cmo:
            default_result_renderer(result)
            for ctest in contenttests:
                assert_in(ctest, cmo.out)
Exemplo n.º 2
0
 def custom_result_renderer(res, **kwargs):
     if res["action"] != "containers":
         default_result_renderer(res)
     else:
         ui.message("{name} -> {path}".format(
             name=ac.color_word(res["name"], ac.MAGENTA),
             path=op.relpath(res["path"], res["refds"])))
Exemplo n.º 3
0
    def custom_result_renderer(res, **kwargs):
        if (res['status'] != 'ok' or
                res['action'] not in ('get_configuration',
                                      'dump_configuration')):
            if 'message' not in res and 'name' in res:
                suffix = '={}'.format(res['value']) if 'value' in res else ''
                res['message'] = '{}{}'.format(
                    res['name'],
                    suffix)
            default_result_renderer(res)
            return
        # TODO source
        from datalad.ui import ui
        name = res['name']
        if res['action'] == 'dump_configuration':
            for key in ('purpose', 'description'):
                s = res.get(key)
                if s:
                    ui.message('\n'.join(wrap(
                        s,
                        initial_indent='# ',
                        subsequent_indent='# ',
                    )))

        if kwargs.get('recursive', False):
            have_subds = res['path'] != res['refds']
            # we need to mark up from which dataset results are reported
            prefix = '<ds>{}{}:'.format(
                '/' if have_subds else '',
                Path(res['path']).relative_to(res['refds']).as_posix()
                if have_subds else '',
            )
        else:
            prefix = ''

        if kwargs.get('action', None) == 'dump':
            if 'value_type' in res:
                value_type = res['value_type']
                vtype = value_type.short_description() \
                    if hasattr(value_type, 'short_description') else str(value_type)
                vtype = f'Value constraint: {vtype}'
                ui.message('\n'.join(wrap(
                    vtype,
                    initial_indent='# ',
                    subsequent_indent='#                    ',
                    break_on_hyphens=False,
                )))
            else:
                vtype = ''
            value = res['value'] if res['value'] is not None else ''
            if value in (True, False):
                # normalize booleans for git-config syntax
                value = str(value).lower()
            ui.message(f'{prefix}{ac.color_word(name, ac.BOLD)}={value}')
        else:
            ui.message('{}{}'.format(
                prefix,
                res['value'] if res['value'] is not None else '',
            ))
Exemplo n.º 4
0
 def custom_result_renderer(res, **kwargs):
     dry_run = kwargs.get("dry_run")
     if dry_run and "dry_run_info" in res:
         if dry_run == "basic":
             _display_basic(res)
         elif dry_run == "command":
             ui.message(res["dry_run_info"]["cmd_expanded"])
         else:
             raise ValueError(f"Unknown dry-run mode: {dry_run!r}")
     else:
         default_result_renderer(res)
 def custom_result_renderer(res, **kwargs):
     from datalad.ui import ui
     status_str = "{action}({status}): "
     if res['action'] == "create-project-osf":
         ui.message("{action}({status}): {url}".format(
             action=ac.color_word(res['action'], ac.BOLD),
             status=ac.color_status(res['status']),
             url=res['url']))
     elif res['action'] == "add-sibling-osf":
         ui.message("{action}({status})".format(
             action=ac.color_word(res['action'], ac.BOLD),
             status=ac.color_status(res['status'])))
     else:
         from datalad.interface.utils import default_result_renderer
         default_result_renderer(res, **kwargs)
 def custom_result_renderer(res, **kwargs):
     from datalad.ui import ui
     if res['action'] == "create-sibling-osf":
         msg = res.get('message', None)
         ui.message("{action}({status}): {url}{msg}".format(
             action=ac.color_word(res['action'], ac.BOLD),
             status=ac.color_status(res['status']),
             url=res.get('url', ''),
             msg=' [{}]'.format(msg[0] % msg[1:] if isinstance(msg, tuple)
                                else res['message']) if msg else ''))
     elif res['action'] == "add-sibling-osf":
         ui.message("{action}({status})".format(
             action=ac.color_word(res['action'], ac.BOLD),
             status=ac.color_status(res['status'])))
     else:
         from datalad.interface.utils import default_result_renderer
         default_result_renderer(res)
Exemplo n.º 7
0
    def custom_result_renderer(res, **kwargs):
        if (res['status'] != 'ok' or res['action']
                not in ('get_configuration', 'dump_configuration')):
            if 'message' not in res and 'name' in res:
                suffix = '={}'.format(res['value']) if 'value' in res else ''
                res['message'] = '{}{}'.format(res['name'], suffix)
            default_result_renderer(res)
            return
        # TODO source
        from datalad.ui import ui
        name = res['name']
        if res['action'] == 'dump_configuration':
            for key in ('purpose', 'description'):
                s = res.get(key)
                if s:
                    ui.message('\n'.join(
                        wrap(
                            s,
                            initial_indent='# ',
                            subsequent_indent='# ',
                        )))

        if kwargs.get('recursive', False):
            have_subds = res['path'] != res['refds']
            # we need to mark up from which dataset results are reported
            prefix = '<ds>{}{}:'.format(
                '/' if have_subds else '',
                Path(res['path']).relative_to(res['refds']).as_posix()
                if have_subds else '',
            )
        else:
            prefix = ''

        if kwargs.get('action', None) == 'dump':
            ui.message('{}{}={}'.format(
                prefix,
                ac.color_word(name, ac.BOLD),
                res['value'] if res['value'] is not None else '',
            ))
        else:
            ui.message('{}{}'.format(
                prefix,
                res['value'] if res['value'] is not None else '',
            ))
Exemplo n.º 8
0
    def custom_result_renderer(res, **kwargs):
        from datalad.ui import ui
        from datalad.interface.utils import default_result_renderer

        if res['status'] != 'ok':
            # logging complained about this already
            return

        if 'procedure' not in res.get('action', ''):
            # it's not our business
            default_result_renderer(res)
            return

        if kwargs.get('discover', None):
            ui.message('{name} ({path}){msg}'.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'],
                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)