예제 #1
0
파일: runp.py 프로젝트: vascop/runp
def print_function(functions, function):
    func = get_function(functions, function)
    if func:
        print pydoc.plain(pydoc.render_doc(
            func,
            "Displaying docstring for %s")
        )
def connected_all_devices():
    print(pydoc.plain(pydoc.render_doc(topology.mount)))
    unmounted_list = topology.unmounted_nodes()
    if unmounted_list:
        for device_name in unmounted_list:
            mount_device(device_name)
#            time.sleep(15)
    else:
        print('There are no (configured) devices unmounted.')
    print(pydoc.plain(pydoc.render_doc(topology.connected)))
    print('connected:  ', topology.connected_nodes())
예제 #3
0
def print_desc(prefix, pkg_path):
    for pkg in pu.iter_modules(pkg_path):
        name = prefix+"."+pkg[1]

        if (pkg[2] == True):
            try:
                print(pd.plain(pd.render_doc(name)))
                docstr = pd.plain(pd.render_doc(name))
                docstr = clean(docstr)
                start = docstr.find("DESCRIPTION")
                docstr = docstr[start: start + 140]
                print(name, docstr)
            except:
                print("UnexpectedError", sys.exc_info()[0])
                continue
def main():
    print(plain(doc(device_mount)))
    for device_name in inventory_unmounted():
        demonstrate(device_name)
        return os.EX_OK
    print('All configured devices are mounted. Demonstration cancelled.')
    return os.EX_TEMPFAIL
예제 #5
0
def draw():
    """ Select a device/interface and demonstrate."""
    print(plain(doc(interface_configuration)))
    foundInterface = False

    G = nx.Graph()

    for device_name in sorted(inventory_connected()):
        G.add_node(device_name)
        print("%s:" % device_name)
        mgmt_name = management_interface(device_name)
        for interface_name in sorted(interface_names(device_name)):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            else:
                match(device_name, interface_name)
                foundInterface = True
                demonstrate(device_name, interface_name)
                to_interface = interface_configuration(device_name, interface_name)[1].split(" ")[1]
                print("interface:%s" % to_interface)
                G.add_edge(device_name, to_interface)
        if not foundInterface:
            print("There are no suitable network interfaces for this device.")

    print(G.nodes())
    print(G.edges())
    # nx.draw(G)
    nx.draw_networkx(G, with_labels=True)
    plt.show()
def main():
    ''' Document and demonstrate the function.'''
    print(plain(doc(inventory_static_route)))
    if demonstrate():
        return os.EX_OK
    else:
        return os.EX_TEMPFAIL
예제 #7
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.mount)))
    try:
        device_name = topology.unmounted_nodes()[0]
        mount_device(device_name)
    except IndexError:
        print('All configured devices are mounted. Demonstration cancelled.')
def main():
    """ 
    Print the documentation then perform the demonstration(s).
    """
    print(plain(doc(static_route_delete)))

    print('Determine which devices are capable.')
    print('inventory_static_route()')
    inventory = inventory_static_route()
    print_table(inventory, headers='device-name')
    if not inventory:
        print("There are no 'static route' capable devices. Demonstration cancelled.")
    else:
        print()
        for device_name in inventory:
            print('static_route_list(%s)' % device_name)
            route_list = static_route_list(device_name)
            print_table(route_list, headers='destination-network')
            print()
            if route_list:
                demonstrate_one(device_name, route_list[0])
                if len(route_list) > 1:
                    demonstrate_all(device_name)
                return EX_OK
        print("There are no devices with a 'static route' configured. Demonstration cancelled.")
    return EX_TEMPFAIL
def main():
    """
    Print the function documentation then demonstrate the function usage.
    """
    print(plain(doc(inventory_static_route)))
    
    return EX_OK if demonstrate() else EX_TEMPFAIL
예제 #10
0
def getdoc(thing, title='Help on %s', forceload=0):

    #g.trace(thing)

    if 1: # Both seem to work.

        # Redirect stdout to a "file like object".
        old_stdout = sys.stdout
        sys.stdout = fo = g.fileLikeObject()
        # Python's builtin help function writes to stdout.
        help(str(thing))
        # Restore original stdout.
        sys.stdout = old_stdout
        # Return what was written to fo.
        return fo.get()

    else:
        # Similar to doc function from pydoc module.
        from pydoc import resolve, describe, inspect, text, plain
        object, name = resolve(thing, forceload)
        desc = describe(object)
        module = inspect.getmodule(object)
        if name and '.' in name:
            desc += ' in ' + name[:name.rfind('.')]
        elif module and module is not object:
            desc += ' in module ' + module.__name__
        doc = title % desc + '\n\n' + text.document(object, name)
        return plain(doc)
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_apply_packet_filter)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            mgmt_name = management_interface(device_name)
            acl_names = acl_list(device_name)
            if not acl_names:
                print('Skip device with no ACLs: ', device_name)
                continue
            else:
                random.shuffle(acl_names)
                acl_name = acl_names[0]
            for ic in interface_configuration_tuple(device_name):
                if ic.name == mgmt_name:
                    continue
                print('Consider %s %s in=%s, out=%s' % (device_name, ic.name, ic.packet_filter_inbound, ic.packet_filter_outbound))
                if not ic.packet_filter_outbound:
                    demonstrate(device_name, ic.name, 'outbound', acl_name)
                    return EX_OK
                if not ic.packet_filter_inbound:
                    demonstrate(device_name, ic.name, 'inbound', acl_name)
                    return EX_OK
        print('There are no network interfaces available to apply an ACL. Demonstration cancelled.')
    return EX_TEMPFAIL
def main():
    print(plain(doc(device_dismount)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print('There are no mounted devices to dismount. Demonstration cancelled.')
    return EX_TEMPFAIL
예제 #13
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.mounted)))
    device_names = settings.config['network_device'].keys()
    if not device_names:
        print('There are no devices configured in the settings.')
    else:
        device_name = device_names[0]
        print('is_mounted(%s):' % device_name, topology.mounted(device_name))
def main():
    print(plain(doc(mounted)))
    device_names = settings.config['network_device'].keys()
    if not device_names:
        print('There are no devices configured in the settings.')
    else:
        device_name = next(iter(device_names))
        print('is mounted(%s):' % device_name, mounted(device_name))
예제 #15
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.dismount)))
    try:
        # Select a mounted device that is in our settings.config
        device_name = next(name for name in topology.mounted_nodes() if name in settings.config['network_device'])
        dismount_device(device_name)
    except(TypeError, StopIteration):
        print('There are no mounted devices to dismount. Demonstration cancelled.')
예제 #16
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.mount)))
    mounted_list = topology.mounted_nodes()
    if mounted_list:
        for device_name in mounted_list:
            dismount_device(device_name)
    else:
        print('There are no mounted devices to dismount.')
def main():
    print(plain(doc(connected)))
    device_names = inventory_mounted()
    if not device_names:
        print('There are no devices mounted on the Controller.')
    else:
        device_name = device_names[0]
        print('is connected(%s):' % device_name, connected(device_name))
예제 #18
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.mount)))
    unmounted_list = topology.unmounted_nodes()
    if unmounted_list:
        for device_name in unmounted_list:
            mount_device(device_name)
    else:
        print('There are no (configured) devices unmounted.')
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(management_interface)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
예제 #20
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.connected)))
    # Create list of mounted devices that are in our settings.config
    mounted_devices = [ name for name in topology.mounted_nodes() if name in settings.config['network_device'] ]
    if not mounted_devices:
        print('There are no devices mounted on the Controller.')
    else:
        device_name = mounted_devices[0]
        print('is_connected(%s):' % device_name, topology.connected(device_name))
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(interface_names)))
    mounted_list = inventory_mounted()
    connected_list = inventory_connected()
    device_list = list(set(connected_list) & set(mounted_list))
    for device_name in device_list:
        return demonstrate(device_name)
    print('There are no mounted, connected devices to examine. Demonstration cancelled.')
예제 #22
0
def main():
    """ Select a device and demonstrate."""
    print(plain(doc(device_control)))
    print("DeviceControl fields:", *DeviceControl._fields, sep="\n\t", end="\n\n")
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL
예제 #23
0
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(device_control)))
    print('DeviceControl fields:', *DeviceControl._fields, sep='\n\t', end='\n\n')
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
def main():
    print(plain(doc(device_dismount)))
    mounted_list = inventory_mounted()
    if not mounted_list:
        print("There are no mounted devices to dismount.")
    else:
        for device_name in mounted_list:
            print("device_dismount(" + device_name, end=")\n")
            device_dismount(device_name)
예제 #25
0
 def testHelp(self):
     from pydoc import text, plain
     s = plain(text.document(validators))
     self.assertTrue('Validator/Converters for use with FormEncode.' in s)
     self.assertTrue('class Bool' in s)
     self.assertTrue('Always Valid, returns True or False' in s)
     self.assertTrue('class Email' in s)
     self.assertTrue('Validate an email address.' in s)
     self.assertTrue('class FieldsMatch' in s)
     self.assertTrue('Tests that the given fields match' in s)
예제 #26
0
def main():
    ''' Select a device and demonstrate, repeat until one ACL found.'''
    print(plain(doc(acl_json_all)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return os.EX_OK
    return os.EX_TEMPFAIL
예제 #27
0
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_list)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return EX_OK
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate on potential routes, repeat until information found.'''
    print(plain(doc(static_route_json)))
    inventory = inventory_static_route()
    if not inventory:
        print("There are no 'static route' capable devices to examine. Demonstration cancelled.")
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return os.EX_OK
    return os.EX_TEMPFAIL
예제 #29
0
def main():
    print(plain(doc(inventory_json)))
    print('Summary of lengthy JSON response:')
    print(*[
        InventorySummary(
            item[name_field],
            connected_field in item and item[connected_field],
            len(item[capability_field]) if capability_field in item else 0
        )
        for item in inventory_json()
    ], sep='\n')
def main():
    ''' Select a device/interface and demonstrate.'''
    print(plain(doc(interface_configuration)))
    for device_name in inventory_connected():
        mgmt_name = management_interface(device_name)
        for interface_name in interface_names(device_name):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            return demonstrate(device_name, interface_name)
    print("There are no suitable network devices. Demonstration cancelled.")
예제 #31
0
def pydoc_pager(text):
    terminal.page(pydoc.plain(text))
예제 #32
0
def getspec(routine):
    """return a string with Python routine specification"""
    doc = pydoc.plain(pydoc.render_doc(routine))
    return doc.splitlines()[2]
예제 #33
0
 def _get_summary_line(o):
     text = pydoc.plain(pydoc.render_doc(o))
     lines = text.split('\n')
     assert len(lines) >= 2
     return lines[2]
예제 #34
0
def main():
    print(pydoc.plain(pydoc.render_doc(topology.connected)))
    print('connected:  ', topology.connected_nodes())
예제 #35
0
    discoveries = capability_discovery(capability_name, capability_namespace)
    print_table([(discovered.device_name, discovered.capability.revision)
                 for discovered in discoveries],
                headers=('device-name', 'capability-revision'))


def main():
    print(cleandoc(__doc__))
    discoveries = demonstrate_all()
    if discoveries:
        discovered = discoveries[0]
        demonstrate_by_capability(discovered.capability.name,
                                  discovered.capability.namespace)
        demonstrate_not_found()
        return EX_OK
    else:
        demonstrate_not_found()
        print()
        print(
            "There are no capable network devices. Demonstration incomplete.")
        return EX_TEMPFAIL


if __name__ == "__main__":
    try:
        sys_exit(main())
    finally:
        print()
        print('Function Reference:')
        print(plain(doc(capability_discovery)))