示例#1
0
    def run(self):
        #Set up the logger
        logger = logging.getLogger('wiseserver')
        logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
        handler = logging.handlers.TimedRotatingFileHandler('wise_daemon.log', 'midnight', backupCount = 15)
        handler.setLevel(logging.DEBUG)
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        #Fetch the data
        try:
            credFile = open('credentials.txt', 'r')
            usr, passwd = credFile.readline().split(' ')
            credFile.close()
        except IOError:
            sys.exit(0)

        df = dataFetcher(usr, passwd[0:-1], 'extractor_data.o', logger)

        if os.path.exists('extractor_data.o'):
            df.fetchSerialized()
        else:
            df.fetchNetData()
            df.serialize()

        cherrypy.log.access_log.addHandler(handler)
        cherrypy.log.error_log.addHandler(handler)
        cherrypy.log.screen = False
        cherrypy.config.update({'server.socket_port': 8080, 'server.socket_host': '0.0.0.0', })
        conf = {'/favicon.ico':{'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(os.getcwd(), 'favicon.ico')}}
        cherrypy.quickstart(WiseMLServer(df, logger), '/', conf)
示例#2
0
def main():
    usage = 'usage: extractor.py [options] username password'
    aparser = OptionParser(usage, version="visor 0.9.6")
    aparser.add_option('-n', '--net', action='store_true', default=False, dest='net', help='Fetches the data from the net.')
    aparser.add_option('-s', '--serialize', action='store_true', default=False, dest='serialize', help='Serializes the net fetched data. Doesn\'t start the web server.')
    aparser.add_option('-f', '--serialize_from', default='extractor_data.o', dest='fromFile', help='Defines the name of file where the serialized data will be recovered from.')
    aparser.add_option('-t', '--serialize_to', default='extractor_data.o', dest='toFile', help='Defines the name of file where the data will be serialized to.')
    aparser.add_option('-p', '--port', default='8080', dest='port', help='Defines the port in which to start up the server.')

    (options, args) = aparser.parse_args()
    if len(args) != 2:
        aparser.error('Incorrect usage')
        sys.exit(0)

    logger = logging.getLogger('wiseserver')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    console = logging.StreamHandler()
    console.setLevel(logging.DEBUG)
    console.setFormatter(formatter)
    logger.addHandler(console)

    df = dataFetcher(args[0], args[1], serializedFile = options.toFile, logger = logger)
    if options.net:
        log(logger, logging.INFO, 'Fetching data from the net.')
        df.fetchNetData()
    else:
        log(logger, logging.INFO, 'Fetching data from a serialized file.')
        df.fetchSerialized(options.fromFile)
    if options.serialize:
        df.serialize(options.toFile)
    else:
        cherrypy.log.access_log.addHandler(console)
        cherrypy.log.error_log.addHandler(console)
        cherrypy.log.screen = False
        cherrypy.config.update({'server.socket_port':int(options.port), 'server.socket_host': '0.0.0.0', })
        conf = {'/favicon.ico':{'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(os.getcwd(), 'favicon.ico')}}
        cherrypy.quickstart(WiseMLServer(df, logger), '/', conf)