コード例 #1
0
def Main(fetcherclass, url, argv=None):
    """
    main() function. Parse command line arguments, fetch information from a device, 
    parsing it into a memory structure (specified by pynt.elements) and 
    write that to files in multiple formats
    """
    (options, args) = pynt.input.commandline.GetOptions(argv)
    if len(args) > 0:
        # override url
        url = args[0]

    pynt.logger.SetLogLevel(options.verbosity)
    logger = logging.getLogger()

    identifier = "schemareader"
    errorfile = os.path.join(options.outputdir,
                             "%s-error.log" % identifier)  # log of errors
    debugfile = os.path.join(options.outputdir, "%s-debug.txt" %
                             identifier)  # human readable memory dump
    errorlog = pynt.logger.Logger(errorfile, verbosity=options.verbosity)

    try:
        fetcher = fetcherclass(url)
        logger.debug("Reading from RDF")
        fetcher.fetch()  # fetches data from RDF schema
        ethns = pynt.xmlns.GetCreateNamespace(
            "http://www.science.uva.nl/research/sne/ndl/ethernet#")
        out = pynt.output.debug.DebugOutput(debugfile)
        out.output()

    except:  # *any* kind of exception, including user-interupts, etc.
        # the write functions are atomic, so those will be fine when an exception occurs
        errorlog.logException()
        (exceptionclass, exception, traceback) = sys.exc_info()
        logger.exception("")
コード例 #2
0
ファイル: __init__.py プロジェクト: jeroenh/Pynt
 def fetch(self):
     """login, retrieve and disconnect"""
     try:
         if self.threadsafe: # First acquire the thread lock
             self.lock.acquire()
         success = False
         logger = logging.getLogger("pynt.input")
         self.open()
         
         logger.debug("Parsing information using %s input" % (type(self).__name__))
         self.retrieve()
         
         # We only record the fetching *after* storing all info in RDFobjects.
         # So AlreadyFetched() only returns True if all information is stored.
         global visitedsources
         visitedsources.append(self.getSource())
         
         success = True
     finally:
         if self.threadsafe: # First release the thread lock
             self.lock.release()
         
         # if success is still False, an exception was raised. close, 
         # and raise original, even if close gives a new exception.
         if success:
             self.close()
         else:
             logger.debug("Caught exception; Closing connection before reporting the error.")
             try:
                 self.close()
             except Exception:  # any exception except keyboard interrupts and system errors
                 pass # ignore later exceptions
コード例 #3
0
ファイル: devicereader.py プロジェクト: jeroenh/Pynt
def Main(fetcherclass, url, argv=None):
    """
    main() function. Parse command line arguments, fetch information from a device, 
    parsing it into a memory structure (specified by pynt.elements) and 
    write that to files in multiple formats
    """
    (options, args) = pynt.input.commandline.GetOptions(argv)
    if len(args) > 0:
        # override url
        url = args[0]
    
    pynt.logger.SetLogLevel(options.verbosity)
    logger = logging.getLogger()
    
    if options.simulate:
        pynt.input.rdf.setWorkOnline(False)
    
    identifier = "devicereader"
    errorfile  = os.path.join(options.outputdir, "%s-error.log"      % identifier)  # log of errors
    debugfile  = os.path.join(options.outputdir, "%s-debug.txt"      % identifier)  # human readable memory dump
    errorlog = pynt.logger.Logger(errorfile, verbosity=options.verbosity)
    
    try:
        fetcher = fetcherclass(url)
        logger.debug("Reading from RDF")
        fetcher.fetch()  # fetches data from RDF schema
        #ethns = pynt.xmlns.GetCreateNamespace("http://www.science.uva.nl/research/sne/ndl/ethernet#")
        out = pynt.output.debug.DebugOutput(debugfile)
        out.output()
        
    except:  # *any* kind of exception, including user-interupts, etc.
        # the write functions are atomic, so those will be fine when an exception occurs
        errorlog.logException()
        (exceptionclass, exception, traceback) = sys.exc_info()
        logger.exception("")
コード例 #4
0
ファイル: __init__.py プロジェクト: vanceinc/Pynt
    def fetch(self):
        """login, retrieve and disconnect"""
        try:
            if self.threadsafe:  # First acquire the thread lock
                self.lock.acquire()
            success = False
            logger = logging.getLogger("pynt.input")
            self.open()

            logger.debug("Parsing information using %s input" %
                         (type(self).__name__))
            self.retrieve()

            # We only record the fetching *after* storing all info in RDFobjects.
            # So AlreadyFetched() only returns True if all information is stored.
            global visitedsources
            visitedsources.append(self.getSource())

            success = True
        finally:
            if self.threadsafe:  # First release the thread lock
                self.lock.release()

            # if success is still False, an exception was raised. close,
            # and raise original, even if close gives a new exception.
            if success:
                self.close()
            else:
                logger.debug(
                    "Caught exception; Closing connection before reporting the error."
                )
                try:
                    self.close()
                except Exception:  # any exception except keyboard interrupts and system errors
                    pass  # ignore later exceptions
コード例 #5
0
ファイル: __init__.py プロジェクト: jeroenh/Pynt
    def queueSource(self, source, fetcherclass=None, prepend=False):
        """Add a related source to a (seeAlso) queue. The given URL will be fetched after the current
        fetcher is finished."""
        if fetcherclass == None:
            fetcherclass = self.__class__
        logger = logging.getLogger("pynt.input")

        if self.sourceInList(source):
            pass
            # This statement will generate a lot of clutter 
            #logger.debug("This source is already in the sourcelist of source %s" % self.url)
        elif prepend:
            self.sourcelist.insert(0, (source, fetcherclass))
            logger.debug("Prepended source %s found in source %s" % (source, self.url))
        else:
            self.sourcelist.append((source, fetcherclass))
            logger.debug("Appended source %s found in source %s" % (source, self.url))
コード例 #6
0
ファイル: __init__.py プロジェクト: vanceinc/Pynt
    def queueSource(self, source, fetcherclass=None, prepend=False):
        """Add a related source to a (seeAlso) queue. The given URL will be fetched after the current
        fetcher is finished."""
        if fetcherclass == None:
            fetcherclass = self.__class__
        logger = logging.getLogger("pynt.input")

        if self.sourceInList(source):
            pass
            # This statement will generate a lot of clutter
            #logger.debug("This source is already in the sourcelist of source %s" % self.url)
        elif prepend:
            self.sourcelist.insert(0, (source, fetcherclass))
            logger.debug("Prepended source %s found in source %s" %
                         (source, self.url))
        else:
            self.sourcelist.append((source, fetcherclass))
            logger.debug("Appended source %s found in source %s" %
                         (source, self.url))
コード例 #7
0
ファイル: pathwalk-lmon.py プロジェクト: jeroenh/Pynt
def Main(fetcherclass, url, argv=None):
    """
    main() function. Parse command line arguments, fetch information from a device, 
    parsing it into a memory structure (specified by pynt.elements) and 
    write that to files in multiple formats
    """
    (options, args) = pynt.input.commandline.GetOptions(argv)
    if len(args) > 0:
        # override url
        url = args[0]
    
    pynt.logger.SetLogLevel(options.verbosity)
    logger = logging.getLogger()
    
    identifier = "networkreader"
    errorfile  = os.path.join(options.outputdir, "%s-error.log"      % identifier)  # log of errors
    debugfile  = os.path.join(options.outputdir, "%s-debug.txt"      % identifier)  # human readable memory dump
    errorlog = pynt.logger.Logger(errorfile, verbosity=options.verbosity)
    
    try:
        #fetcher = pynt.input.rdf.GetCreateRDFFetcher(fetcherclass, url)
        fetcher = fetcherclass(url)
        logger.debug("Reading from RDF")
        
        fetcher.fetch()  # fetches data from RDF schema
        #ethns = pynt.xmlns.GetCreateNamespace("http://www.science.uva.nl/research/sne/ndl/ethernet#")
        out = pynt.output.debug.DebugOutput(debugfile)
        out.output()
        
    except:  # *any* kind of exception, including user-interupts, etc.
        # the write functions are atomic, so those will be fine when an exception occurs
        errorlog.logException()
        (exceptionclass, exception, traceback) = sys.exc_info()
        logger.exception("")

    # Do the pathwalk 
    pw = lmon.ie.pathwalk.PathWalk()
    # Retrieve connection point http://rembrandt0.uva.netherlight.nl#Rembrandt0:eth2
    (namespace, identifier) = pynt.xmlns.splitURI('http://speculaas.uva.netherlight.nl#intf51')
    #(namespace, identifier) = pynt.xmlns.splitURI('http://rembrandt0.uva.netherlight.nl#Rembrandt0:eth2')
    startif = pynt.elements.GetCreateInterface(identifier, namespace)
    print identifier, namespace
    print startif.getName()
    # Retrieve connection point http://rembrandt7.uva.netherlight.nl#Rembrandt7:eth2
    (namespace, identifier) = pynt.xmlns.splitURI('http://speculaas.uva.netherlight.nl#intf11')
    #(namespace, identifier) = pynt.xmlns.splitURI('http://rembrandt7.uva.netherlight.nl#Rembrandt7:eth2')
    endif = pynt.elements.GetCreateInterface(identifier, namespace)
    print identifier, namespace
    print endif.getName()

    logger.setLevel(logging.DEBUG)
    
    pw.setEndpoints(startif, endif)
    #pw.setPrinter(pynt.algorithm.output.TextProgressPrinter())

    solutions = pw.findPaths()

    namespaces = []
    for solution in solutions:
        #print solution
        for hop in solution:
            if hop.cp.getNamespace() not in namespaces:
                namespaces.append(hop.cp)
    #print namespaces

    output = pynt.output.dot.InterfaceGraphOutput('foo.dot')
    dotprinter = pynt.algorithm.output.SingleFilePrinter(output, namespaces)
    dotprinter.printSolution(solutions)
コード例 #8
0
ファイル: pathwalk-lmon.py プロジェクト: vanceinc/Pynt
def Main(fetcherclass, url, argv=None):
    """
    main() function. Parse command line arguments, fetch information from a device, 
    parsing it into a memory structure (specified by pynt.elements) and 
    write that to files in multiple formats
    """
    (options, args) = pynt.input.commandline.GetOptions(argv)
    if len(args) > 0:
        # override url
        url = args[0]

    pynt.logger.SetLogLevel(options.verbosity)
    logger = logging.getLogger()

    identifier = "networkreader"
    errorfile = os.path.join(options.outputdir,
                             "%s-error.log" % identifier)  # log of errors
    debugfile = os.path.join(options.outputdir, "%s-debug.txt" %
                             identifier)  # human readable memory dump
    errorlog = pynt.logger.Logger(errorfile, verbosity=options.verbosity)

    try:
        #fetcher = pynt.input.rdf.GetCreateRDFFetcher(fetcherclass, url)
        fetcher = fetcherclass(url)
        logger.debug("Reading from RDF")

        fetcher.fetch()  # fetches data from RDF schema
        #ethns = pynt.xmlns.GetCreateNamespace("http://www.science.uva.nl/research/sne/ndl/ethernet#")
        out = pynt.output.debug.DebugOutput(debugfile)
        out.output()

    except:  # *any* kind of exception, including user-interupts, etc.
        # the write functions are atomic, so those will be fine when an exception occurs
        errorlog.logException()
        (exceptionclass, exception, traceback) = sys.exc_info()
        logger.exception("")

    # Do the pathwalk
    pw = lmon.ie.pathwalk.PathWalk()
    # Retrieve connection point http://rembrandt0.uva.netherlight.nl#Rembrandt0:eth2
    (namespace, identifier
     ) = pynt.xmlns.splitURI('http://speculaas.uva.netherlight.nl#intf51')
    #(namespace, identifier) = pynt.xmlns.splitURI('http://rembrandt0.uva.netherlight.nl#Rembrandt0:eth2')
    startif = pynt.elements.GetCreateInterface(identifier, namespace)
    print identifier, namespace
    print startif.getName()
    # Retrieve connection point http://rembrandt7.uva.netherlight.nl#Rembrandt7:eth2
    (namespace, identifier
     ) = pynt.xmlns.splitURI('http://speculaas.uva.netherlight.nl#intf11')
    #(namespace, identifier) = pynt.xmlns.splitURI('http://rembrandt7.uva.netherlight.nl#Rembrandt7:eth2')
    endif = pynt.elements.GetCreateInterface(identifier, namespace)
    print identifier, namespace
    print endif.getName()

    logger.setLevel(logging.DEBUG)

    pw.setEndpoints(startif, endif)
    #pw.setPrinter(pynt.algorithm.output.TextProgressPrinter())

    solutions = pw.findPaths()

    namespaces = []
    for solution in solutions:
        #print solution
        for hop in solution:
            if hop.cp.getNamespace() not in namespaces:
                namespaces.append(hop.cp)
    #print namespaces

    output = pynt.output.dot.InterfaceGraphOutput('foo.dot')
    dotprinter = pynt.algorithm.output.SingleFilePrinter(output, namespaces)
    dotprinter.printSolution(solutions)