コード例 #1
0
ファイル: app.py プロジェクト: NNPDF/reportengine
    def __call__(self, parser, namespace, values, option_string=None):
        if not values:
            parser.print_help()
        elif values=='config':
            print(helputils.format_config(self.app.config_class))
        elif values in self.app.default_provider_names:
            module = importlib.import_module(values)
            print(helputils.format_providermodule(module))

        else:
            #TODO: This is ugly as hell
            providermods = self.app.load_providers()
            rb = ResourceBuilder(self.app.config_class({}),
                                 providermods,
                                 [])
            try:
                providertree = rb.explain_provider(values)
            except AttributeError:

                alternatives = ['config', *self.app.default_provider_names]

                alternatives += [f for mod in providermods
                                   for f in get_providers(mod).keys()
                                ]

                msg = "No help available for %s" % values
                print(ErrorWithAlternatives(msg, values, alternatives),
                      file=sys.stderr)

            else:
                print(helputils.print_providertree(providertree))

        parser.exit()
コード例 #2
0
ファイル: helputils.py プロジェクト: NNPDF/reportengine
def format_providermodule(module):
    moddoc = sane_fill(module.__doc__, initial_indent='', subsequent_indent='')
    if moddoc is None:
        moddoc = ''

    functions = get_providers(module)
    lines = []

    name = t.bold_underline(module.__name__)

    for val, function in functions.items():

        #Get the docs
        doc = function.__doc__
        if doc is None:
            doc = ''

        if hasattr(function, 'highlight'):
            highlight = '(%s)' % function.highlight
            color_highlight = get_highlight_color(function.highlight)(highlight)
        else:
            color_highlight = highlight = ''


        color_header = "%s%s: "%(t.bold(val), color_highlight)
        white_header = "%s%s:"%(val, highlight)
        lines.append(wrap_lines_with_color_header(color_header, white_header, doc))



    lines = '\n\n'.join(lines)



    s = ("{name}\n{moddoc}\n"
        "The following providers are defined in this module:\n\n"
        "{lines}".format(name=name, moddoc = moddoc, lines=lines))
    return s