示例#1
0
    def module_info(self, module, showInfo=True, showTitle=True):
        if showTitle == True:
            messages.title()

        if showInfo:
            # extract the payload class name from the instantiated object, then chop off the load folder prefix
            #modulename = "/".join(str(str(module.__class__)[str(module.__class__).find("ClassName"):]).split(".")[0].split("/")[1:])

            print helpers.color(" Module information:\n", blue=True)
            print "\tName:\t\t" + module.name
            print "\tLanguage:\t" + module.language
            # format this all nice-like
            print helpers.formatLong("Description:", module.description)
        # if required options were specified, output them
        if hasattr(module, 'required_options'):
            print helpers.color("\n Required Options:\n", blue=True)

            print " Name\t\t\tCurrent Value\tDescription"
            print " ----\t\t\t-------------\t-----------"

            # sort the dictionary by key before we output, so it looks nice
            for key in sorted(module.required_options.iterkeys()):
                print " %s\t%s\t%s" % ('{0: <16}'.format(key),
                                       '{0: <8}'.format(
                                           module.required_options[key][0]),
                                       module.required_options[key][1])

            print ""
示例#2
0
def helpModule(module):
    """
    Print the first text chunk for each established method in a module.

    module: module to write output from, format "folder.folder.module"
    """

    # split module.x.y into "from module.x import y" 
    t = module.split(".")
    importName = "from " + ".".join(t[:-1]) + " import " + t[-1]

    # dynamically do the import
    exec(importName)
    moduleName = t[-1]

    # extract all local functions from the imported module, 
    # referenced here by locals()[moduleName]
    functions = [locals()[moduleName].__dict__.get(a) for a in dir(locals()[moduleName]) if isinstance(locals()[moduleName].__dict__.get(a), types.FunctionType)]

    # pull all the doc strings out from said functions and print the top chunk
    for function in functions:
        base = function.func_doc
        base = base.replace("\t", " ")
        doc = "".join(base.split("\n\n")[0].strip().split("\n"))
        # print function.func_name + " : " + doc
        print helpers.formatLong(function.func_name, doc)
示例#3
0
    def module_info(self, module, showInfo=True, showTitle=True):
        if showTitle == True:
            messages.title()

        if showInfo:
            # extract the payload class name from the instantiated object, then chop off the load folder prefix
            #modulename = "/".join(str(str(module.__class__)[str(module.__class__).find("ClassName"):]).split(".")[0].split("/")[1:])

            print helpers.color(" Module information:\n", blue=True)
            print "\tName:\t\t" + module.name
            print "\tLanguage:\t" + module.language
            # format this all nice-like
            print helpers.formatLong("Description:", module.description)
        # if required options were specified, output them
        if hasattr(module, 'required_options'):
            print helpers.color("\n Required Options:\n", blue=True)

            print " Name\t\t\tCurrent Value\tDescription"
            print " ----\t\t\t-------------\t-----------"

            # sort the dictionary by key before we output, so it looks nice
            for key in sorted(module.required_options.iterkeys()):
                print " %s\t%s\t%s" % ('{0: <16}'.format(key), '{0: <8}'.format(module.required_options[key][0]), module.required_options[key][1])

            print ""