Python cherrypy 模块,log() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用cherrypy.log()

项目:0ops.exed    作者:whisperaven    | 项目源码 | 文件源码
def handle(self, *args, **kwargs):
        """ Handle api request by invoke `runner.handle()`. 

        All exception raised by runner will be catched here, and convert them
        into cherrypy `HTTPError()` with corresponding status code and message.
        """
        try:
            return self._runner.handle(*args, **kwargs)
        except JobDeleteError:
            raise cherrypy.HTTPError(status.BAD_REQUEST, excinst().message)
        except JobConflictError:
            raise cherrypy.HTTPError(status.CONFLICT, excinst().message)
        except JobNotSupportedError:
            raise cherrypy.HTTPError(status.INTERNAL_SERVER_ERROR, excinst().message)
        except (JobNotExistsError, ExecutorNoMatchError):
            raise cherrypy.HTTPError(status.NOT_FOUND, excinst().message)
        except:
            cherrypy.log("error response 500", traceback=True)
            raise cherrypy.HTTPError(status.INTERNAL_SERVER_ERROR)
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def getListOfModels(comFolder):
    '''
    This function creates a list with all the community models that will be used in the analysis. It creates this list by listing the metabolic models in SBML format present in the user specified folder that contains the community models.

    :param comFolder: path to the folder that contains the community metabolic models.
    :return listOfModels: list object containing the filenames for all the models that will be analysed in the function calculateGR
    '''

    import os
    cherrypy.log('We will first get the full list of community models from the %s folder' %comFolder)

    path = comFolder
    listOfFiles = os.listdir(path)

    listOfModels = []

    for file in listOfFiles:
        if file.endswith('.sbml'):
            pathToFile = path + file
            listOfModels.append(pathToFile)

    cherrypy.log('There are %s community models what will be analyzed.'%listOfModels)

    return listOfModels
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def replaceRxns(model,modelID):    
    '''
    This function adds the tag specified in the parameter modelID to the beginning of the reaction IDs for a particular Model object. We are doing this so that we know which reactions come from one species or the other. This is the same as assigning each species to a different compartment. This is important because the two species have common reactions and metabolites, but are not sharing these metabolites in their biology, since the cells are closed compartments. They only share the metabolites that are transported in and out of the cell, hence the creation of an extra external compartment.

    :param model: Model object containing the metabolic model of a particular species
    :param modelID: Tag to add to the beginning of the reaction IDs of the model.
    :return model: same model but with updated reactions IDs
    '''


    cherrypy.log('Started function to replace the reaction IDs in the species models')


    for i in range(len(model.reactions)):
        old_rxns = str(model.reactions[i])
        new_rxns = 'model' + modelID + '_' + old_rxns
        model.reactions[i].id = new_rxns

    cherrypy.log('Finished changing the reaction IDs in the species models')
项目:sql_python_deep_learning    作者:Azure    | 项目源码 | 文件源码
def run_server():
    # Enable WSGI access logging via Paste
    app_logged = TransLogger(app)

    # Mount the WSGI callable object (app) on the root directory
    cherrypy.tree.graft(app_logged, '/')

    # Set the configuration of the web server
    cherrypy.config.update({
        'engine.autoreload_on': True,
        'log.screen': True,
        'log.error_file': "cherrypy.log",
        'server.socket_port': 5000,
        'server.socket_host': '0.0.0.0',
        'server.thread_pool': 50, # 10 is default
    })

    # Start the CherryPy WSGI web server
    cherrypy.engine.start()
    cherrypy.engine.block()

# Connection
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def _attempt(filename, content_types, debug=False):
    if debug:
        cherrypy.log('Attempting %r (content_types %r)' %
                     (filename, content_types), 'TOOLS.STATICDIR')
    try:
        # you can set the content types for a
        # complete directory per extension
        content_type = None
        if content_types:
            r, ext = os.path.splitext(filename)
            content_type = content_types.get(ext[1:], None)
        serve_file(filename, content_type=content_type, debug=debug)
        return True
    except cherrypy.NotFound:
        # If we didn't find the static file, continue handling the
        # request. We might find a dynamic handler instead.
        if debug:
            cherrypy.log('NotFound', 'TOOLS.STATICFILE')
        return False
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def _load(self, path=None):
        assert self.locked, ('The session load without being locked.  '
                             "Check your tools' priority levels.")
        if path is None:
            path = self._get_file_path()
        try:
            f = open(path, 'rb')
            try:
                return pickle.load(f)
            finally:
                f.close()
        except (IOError, EOFError):
            e = sys.exc_info()[1]
            if self.debug:
                cherrypy.log('Error loading the session pickle: %s' %
                             e, 'TOOLS.SESSIONS')
            return None
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def acquire_lock(self, path=None):
        """Acquire an exclusive lock on the currently-loaded session data."""
        if path is None:
            path = self._get_file_path()
        path += self.LOCK_SUFFIX
        checker = locking.LockChecker(self.id, self.lock_timeout)
        while not checker.expired():
            try:
                self.lock = lockfile.LockFile(path)
            except lockfile.LockError:
                time.sleep(0.1)
            else:
                break
        self.locked = True
        if self.debug:
            cherrypy.log('Lock acquired.', 'TOOLS.SESSIONS')
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def digest_auth(realm, users, debug=False):
    """If auth fails, raise 401 with a digest authentication header.

    realm
        A string containing the authentication realm.
    users
        A dict of the form: {username: password} or a callable returning
        a dict.
    """
    if check_auth(users, realm=realm):
        if debug:
            cherrypy.log('Auth successful', 'TOOLS.DIGEST_AUTH')
        return

    # inform the user-agent this path is protected
    cherrypy.serving.response.headers[
        'www-authenticate'] = httpauth.digestAuth(realm)

    raise cherrypy.HTTPError(
        401, 'You are not authorized to access that resource')
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append('    %s:' % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append('        %r' % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), 'HTTP')
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def flatten(debug=False):
    """Wrap response.body in a generator that recursively iterates over body.

    This allows cherrypy.response.body to consist of 'nested generators';
    that is, a set of generators that yield generators.
    """
    def flattener(input):
        numchunks = 0
        for x in input:
            if not is_iterator(x):
                numchunks += 1
                yield x
            else:
                for y in flattener(x):
                    numchunks += 1
                    yield y
        if debug:
            cherrypy.log('Flattened %d chunks' % numchunks, 'TOOLS.FLATTEN')
    response = cherrypy.serving.response
    response.body = flattener(response.body)
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def autovary(ignore=None, debug=False):
    """Auto-populate the Vary response header based on request.header access.
    """
    request = cherrypy.serving.request

    req_h = request.headers
    request.headers = MonitoredHeaderMap()
    request.headers.update(req_h)
    if ignore is None:
        ignore = set(['Content-Disposition', 'Content-Length', 'Content-Type'])

    def set_response_header():
        resp_h = cherrypy.serving.response.headers
        v = set([e.value for e in resp_h.elements('Vary')])
        if debug:
            cherrypy.log(
                'Accessed headers: %s' % request.headers.accessed_headers,
                'TOOLS.AUTOVARY')
        v = v.union(request.headers.accessed_headers)
        v = v.difference(ignore)
        v = list(v)
        v.sort()
        resp_h['Vary'] = ', '.join(v)
    request.hooks.attach('before_finalize', set_response_header, 95)
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def run(self, point):
        """Execute all registered Hooks (callbacks) for the given point."""
        exc = None
        hooks = self[point]
        hooks.sort()
        for hook in hooks:
            # Some hooks are guaranteed to run even if others at
            # the same hookpoint fail. We will still log the failure,
            # but proceed on to the next hook. The only way
            # to stop all processing from one of these hooks is
            # to raise SystemExit and stop the whole server.
            if exc is None or hook.failsafe:
                try:
                    hook()
                except (KeyboardInterrupt, SystemExit):
                    raise
                except (cherrypy.HTTPError, cherrypy.HTTPRedirect,
                        cherrypy.InternalRedirect):
                    exc = sys.exc_info()[1]
                except:
                    exc = sys.exc_info()[1]
                    cherrypy.log(traceback=True, severity=40)
        if exc:
            raise exc
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + '.' + name] = vtype

        traverse(cherrypy.request, 'request')
        traverse(cherrypy.response, 'response')
        traverse(cherrypy.server, 'server')
        traverse(cherrypy.engine, 'engine')
        traverse(cherrypy.log, 'log')
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def _attempt(filename, content_types, debug=False):
    if debug:
        cherrypy.log('Attempting %r (content_types %r)' %
                     (filename, content_types), 'TOOLS.STATICDIR')
    try:
        # you can set the content types for a
        # complete directory per extension
        content_type = None
        if content_types:
            r, ext = os.path.splitext(filename)
            content_type = content_types.get(ext[1:], None)
        serve_file(filename, content_type=content_type, debug=debug)
        return True
    except cherrypy.NotFound:
        # If we didn't find the static file, continue handling the
        # request. We might find a dynamic handler instead.
        if debug:
            cherrypy.log('NotFound', 'TOOLS.STATICFILE')
        return False
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def _load(self, path=None):
        assert self.locked, ("The session load without being locked.  "
                             "Check your tools' priority levels.")
        if path is None:
            path = self._get_file_path()
        try:
            f = open(path, "rb")
            try:
                return pickle.load(f)
            finally:
                f.close()
        except (IOError, EOFError):
            e = sys.exc_info()[1]
            if self.debug:
                cherrypy.log("Error loading the session pickle: %s" %
                             e, 'TOOLS.SESSIONS')
            return None
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def acquire_lock(self, path=None):
        """Acquire an exclusive lock on the currently-loaded session data."""
        if path is None:
            path = self._get_file_path()
        path += self.LOCK_SUFFIX
        checker = locking.LockChecker(self.id, self.lock_timeout)
        while not checker.expired():
            try:
                self.lock = lockfile.LockFile(path)
            except lockfile.LockError:
                time.sleep(0.1)
            else:
                break
        self.locked = True
        if self.debug:
            cherrypy.log('Lock acquired.', 'TOOLS.SESSIONS')
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def digest_auth(realm, users, debug=False):
    """If auth fails, raise 401 with a digest authentication header.

    realm
        A string containing the authentication realm.
    users
        A dict of the form: {username: password} or a callable returning
        a dict.
    """
    if check_auth(users, realm=realm):
        if debug:
            cherrypy.log('Auth successful', 'TOOLS.DIGEST_AUTH')
        return

    # inform the user-agent this path is protected
    cherrypy.serving.response.headers[
        'www-authenticate'] = httpauth.digestAuth(realm)

    raise cherrypy.HTTPError(
        401, "You are not authorized to access that resource")
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append("    %s:" % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append("        %r" % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), "HTTP")
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def flatten(debug=False):
    """Wrap response.body in a generator that recursively iterates over body.

    This allows cherrypy.response.body to consist of 'nested generators';
    that is, a set of generators that yield generators.
    """
    def flattener(input):
        numchunks = 0
        for x in input:
            if not is_iterator(x):
                numchunks += 1
                yield x
            else:
                for y in flattener(x):
                    numchunks += 1
                    yield y
        if debug:
            cherrypy.log('Flattened %d chunks' % numchunks, 'TOOLS.FLATTEN')
    response = cherrypy.serving.response
    response.body = flattener(response.body)
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def autovary(ignore=None, debug=False):
    """Auto-populate the Vary response header based on request.header access.
    """
    request = cherrypy.serving.request

    req_h = request.headers
    request.headers = MonitoredHeaderMap()
    request.headers.update(req_h)
    if ignore is None:
        ignore = set(['Content-Disposition', 'Content-Length', 'Content-Type'])

    def set_response_header():
        resp_h = cherrypy.serving.response.headers
        v = set([e.value for e in resp_h.elements('Vary')])
        if debug:
            cherrypy.log(
                'Accessed headers: %s' % request.headers.accessed_headers,
                'TOOLS.AUTOVARY')
        v = v.union(request.headers.accessed_headers)
        v = v.difference(ignore)
        v = list(v)
        v.sort()
        resp_h['Vary'] = ', '.join(v)
    request.hooks.attach('before_finalize', set_response_header, 95)
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def run(self, point):
        """Execute all registered Hooks (callbacks) for the given point."""
        exc = None
        hooks = self[point]
        hooks.sort()
        for hook in hooks:
            # Some hooks are guaranteed to run even if others at
            # the same hookpoint fail. We will still log the failure,
            # but proceed on to the next hook. The only way
            # to stop all processing from one of these hooks is
            # to raise SystemExit and stop the whole server.
            if exc is None or hook.failsafe:
                try:
                    hook()
                except (KeyboardInterrupt, SystemExit):
                    raise
                except (cherrypy.HTTPError, cherrypy.HTTPRedirect,
                        cherrypy.InternalRedirect):
                    exc = sys.exc_info()[1]
                except:
                    exc = sys.exc_info()[1]
                    cherrypy.log(traceback=True, severity=40)
        if exc:
            raise exc
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + "." + name] = vtype

        traverse(cherrypy.request, "request")
        traverse(cherrypy.response, "response")
        traverse(cherrypy.server, "server")
        traverse(cherrypy.engine, "engine")
        traverse(cherrypy.log, "log")
项目:solaris-ips    作者:oracle    | 项目源码 | 文件源码
def catalog_1(self, *tokens):
                """Outputs the contents of the specified catalog file, using the
                name in the request path, directly to the client."""

                try:
                        name = tokens[0]
                except IndexError:
                        raise cherrypy.HTTPError(http_client.FORBIDDEN,
                            _("Directory listing not allowed."))

                try:
                        fpath = self.repo.catalog_1(name,
                            pub=self._get_req_pub())
                except srepo.RepositoryError as e:
                        # Treat any remaining repository error as a 404, but
                        # log the error and include the real failure
                        # information.
                        cherrypy.log("Request failed: {0}".format(str(e)))
                        raise cherrypy.HTTPError(http_client.NOT_FOUND, str(e))

                self.__set_response_expires("catalog", 86400, 86400)
                return serve_file(fpath, "text/plain; charset=utf-8")
项目:solaris-ips    作者:oracle    | 项目源码 | 文件源码
def _tar_stream_close(**kwargs):
                """This is a special function to finish a tar_stream-based
                request in the event of an exception."""

                tar_stream = cherrypy.request.tar_stream
                if tar_stream:
                        try:
                                # Attempt to close the tar_stream now that we
                                # are done processing the request.
                                tar_stream.close()
                        except Exception:
                                # All exceptions are intentionally caught as
                                # this is a failsafe function and must happen.

                                # tarfile most likely failed trying to flush
                                # its internal buffer.  To prevent tarfile from
                                # causing further exceptions during __del__,
                                # we have to lie and say the fileobj has been
                                # closed.
                                tar_stream.fileobj.closed = True
                                cherrypy.log("Request aborted: ",
                                    traceback=True)

                        cherrypy.request.tar_stream = None
项目:solaris-ips    作者:oracle    | 项目源码 | 文件源码
def file_0(self, *tokens):
                """Outputs the contents of the file, named by the SHA-1 hash
                name in the request path, directly to the client."""

                try:
                        fhash = tokens[0]
                except IndexError:
                        fhash = None

                try:
                        fpath = self.repo.file(fhash, pub=self._get_req_pub())
                except srepo.RepositoryFileNotFoundError as e:
                        raise cherrypy.HTTPError(http_client.NOT_FOUND, str(e))
                except srepo.RepositoryError as e:
                        # Treat any remaining repository error as a 404, but
                        # log the error and include the real failure
                        # information.
                        cherrypy.log("Request failed: {0}".format(str(e)))
                        raise cherrypy.HTTPError(http_client.NOT_FOUND, str(e))

                self.__set_response_expires("file", 86400*365, 86400*365)
                return serve_file(fpath, "application/data")
项目:solaris-ips    作者:oracle    | 项目源码 | 文件源码
def run(self):
                """Run any background task scheduled for execution."""
                while self.__running:
                        try:
                                try:
                                        # A brief timeout here is necessary
                                        # to reduce CPU usage and to ensure
                                        # that shutdown doesn't wait forever
                                        # for a new task to appear.
                                        task, args, kwargs = \
                                            self.__q.get(timeout=.5)
                                except queue.Empty:
                                        continue
                                task(*args, **kwargs)
                                if hasattr(self.__q, "task_done"):
                                        # Task is done; mark it so.
                                        self.__q.task_done()
                        except:
                                self.bus.log("Failure encountered executing "
                                    "background task {0!r}.".format(self),
                                    traceback=True)
项目:plugin.audio.spotify    作者:marcelveldt    | 项目源码 | 文件源码
def __init__(self, spotty):
        self.__root = Root(spotty)
        log = cherrypy.log
        log.access_file = ''
        log.error_file = ''
        log.screen = False
        cherrypy.config.update({
            'server.socket_host': '0.0.0.0',
            'server.socket_port': PROXY_PORT,
            'engine.timeout_monitor.frequency': 5,
            'server.shutdown_timeout': 1
        })
        self.__server = cherrypy.server.httpserver = CPHTTPServer(cherrypy.server)
        threading.Thread.__init__(self)
项目:arduino-ciao-meteor-ddp-connector    作者:andrea689    | 项目源码 | 文件源码
def start(self):
        self.bus.log("Starting WebSocket processing")
        self.bus.subscribe('stop', self.cleanup)
        self.bus.subscribe('handle-websocket', self.handle)
        self.bus.subscribe('websocket-broadcast', self.broadcast)
        self.manager.start()
项目:arduino-ciao-meteor-ddp-connector    作者:andrea689    | 项目源码 | 文件源码
def stop(self):
        self.bus.log("Terminating WebSocket processing")
        self.bus.unsubscribe('stop', self.cleanup)
        self.bus.unsubscribe('handle-websocket', self.handle)
        self.bus.unsubscribe('websocket-broadcast', self.broadcast)
项目:arduino-ciao-meteor-ddp-connector    作者:andrea689    | 项目源码 | 文件源码
def index(self):
            cherrypy.log("Handler created: %s" % repr(cherrypy.request.ws_handler))
项目:xtdpy    作者:psycofdj    | 项目源码 | 文件源码
def listen(cls,
             p_socket,
             p_nbThreads=10,
             p_tls=False,
             p_cacert=None,
             p_cert=None,
             p_key=None):

    if not cls.ms_initialized:
      raise XtdError(__name__, "you must initialize server manager first")

    l_server = cherrypy._cpserver.Server()
    p_socket = urlparse(p_socket)
    if p_socket.scheme == "tcp":
      l_server.socket_host = p_socket.hostname
      l_port = p_socket.port
      if not l_port:
        l_port = 8080
      l_server.socket_port = l_port
    elif p_socket.scheme == "unix":
      l_server.bind_addr = p_socket.path
    l_server.thread_pool           = p_nbThreads
    if p_tls:
      cherrypy.log("Enabling TLS support")
      l_server.ssl_module            = "builtin"
      #l_server.ssl_certificate_chain = p_cacert
      l_server.ssl_certificate       = p_cert
      l_server.ssl_private_key       = p_key
    l_server.subscribe()
    return l_server
项目:xtdpy    作者:psycofdj    | 项目源码 | 文件源码
def initialize(cls, p_logger):
    if cls.ms_initialized:
      return None

    cherrypy.tools.counter_start = \
      cherrypy._cptools.Tool("on_start_resource", tools.perf_begin())
    cherrypy.tools.counter_stop = \
      cherrypy._cptools.Tool("on_end_request", tools.perf_end())
    cherrypy.tools.log_request = \
      cherrypy._cptools.Tool('on_start_resource', tools.request_logger())
    cherrypy.tools.log_response = \
      cherrypy._cptools.Tool('on_end_resource', tools.response_logger())

    cherrypy.server.unsubscribe()

    l_filterAccess = cls.LoggerFilter(p_logger + ".access", True)
    l_filterError  = cls.LoggerFilter(p_logger + ".error", True)
    logging.getLogger("cherrypy.acccess").addFilter(l_filterAccess)
    logging.getLogger("cherrypy.error").addFilter(l_filterError)

    cherrypy.config.update({
      "environment"                   : "production",
      "engine.autoreload.on"          : False,
      "log.screen"                    : True,
      "log.access_file"               : "",
      "log.error_file"                : ""
    })
    cherrypy.engine.signals.subscribe()
    cls.ms_initialized = True
项目:xtdpy    作者:psycofdj    | 项目源码 | 文件源码
def mount(cls, p_handler, p_path, p_conf=None, p_logger="cherrypy"):
    if p_conf is None:
      p_conf = {}

    if not cls.ms_initialized:
      raise XtdError(__name__, "you must initialize server manager first")

    l_res = mergedicts({
      '/' : {
        "tools.log_request.on"           : True,
        "tools.log_request.module"       : p_logger + ".error",
        "tools.log_request.level"        : "debug",
        "tools.log_response.on"          : True,
        "tools.log_response.module"      : p_logger + ".error",
        "tools.log_response.level"       : "debug",
        "tools.counter_start.on"         : True,
        "tools.counter_start.ns"         : p_logger,
        "tools.counter_start.name"       : "rtt",
        "tools.counter_stop.on"          : True,
        "tools.counter_stop.ns"          : p_logger,
        "tools.counter_stop.name"        : "rtt",
      }
    }, p_conf)
    l_app = cherrypy.tree.mount(p_handler, p_path, dict(l_res))
    l_filterAccess = cls.LoggerFilter(p_logger + ".access")
    l_filterError  = cls.LoggerFilter(p_logger + ".error")
    l_loggerAccess = logging.getLogger(p_logger + ".access")
    l_loggerError  = logging.getLogger(p_logger + ".error")
    l_loggerError.addFilter(l_filterError)
    l_loggerAccess.addFilter(l_filterAccess)
    l_app.log.error_log  = l_loggerError
    l_app.log.access_log = l_loggerAccess
    return l_app
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def createJSONforD3(node_value,link_value):
    '''
    This function takes the variables created in the functions nodes() and links() and creates a json file that contains all the necessary information for plotting the netwrok of associations between the different OTUs with the color of the links reflecting the prediction of the types of interactions occurring between pairs of OTUs.

    :param node_value: list of dictionaries returned from function nodes
    :param link_value: list of dictionaries returned from function links
    :return data4plot_json: file in json format in site folder that contains the information required for plotting network of associations between OTUs and the predicted interactions occurring between pairs of species.
    '''

    import json
    cherrypy.log('Finally, we will dump the information about the nodes and links of our network to a json file.')

    '''
    @summary: put the nodes values and the links values into the final dataset that is in the dictionary format
    ''' 
    dataDict = {'nodes': node_value, 'links': link_value}


    '''
    @summary: dump the new data into a json file
    '''

    with open('data4plot_json','w') as outfile:
        cherrypy.log('The information will be dumped into the file %s' %outfile)
        json.dump(dataDict, outfile)

    cherrypy.log('We finished creating the json file.')
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def createEXmodel(EXreactions): 
    '''
    This function takes the list of exchange reactions created using the function totalEXRxns and creates a Model object using cobrapy composed of those reactions with the upper bound flux values of 1000, lower bound flux values of -1000, and objective coefficient of 0, and one metabolite as being uptaken by the reaction (stoichiometric coefficient of -1). This is a model composed solely of exchange reactions and it's the model for the extra compartment created for the full community model

    :param EXreactions: list of reactions that are the output of the function totalEXRxns (above)
    :return exchange_model: cobrapy Model object for the compartment that will serve as an extra compartment in the full community model.
    '''


    cherrypy.log("Started the function that creates the exchange reactions for the community model")

    exchange_model = cobra.Model('Model with the exchange reactions only')

    cherrypy.log("Created the base exchange model object")

    for i in EXreactions: 
        new_i = str(i)
        new_i = new_i[3:]
        new_met = cobra.Metabolite(new_i)

        rxn = cobra.Reaction(i)
        rxn.lower_bound = -1000.000
        rxn.upper_bound = 1000.000
        rxn.objective_coefficient = 0.000
        rxn.add_metabolites({new_met:-1.0}) 

        exchange_model.add_reaction(rxn)


    cherrypy.log('Finished adding all exchange reactions in exchange model object. There are %d of them' %(len(exchange_model.reactions)))

    return exchange_model
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def createReverseEXmodel(EXreactions): 
    '''
    This function takes the list of exchange reactions created using the function totalEXRxns and creates a Model object using cobrapy composed of those reactions with the upper bound flux values of 1000, lower bound flux values of -1000, and objective coefficient of 0, and one metabolite as being produced by the reaction (stoichiometric coefficient of 1). This is a model composed solely of exchange reactions. The metabolite information for these reactions will be used to update the metabolites of the exchange reactions for models A and B.

    :param EXreactions: list of reactions that are the output of the function totalEXRxns (above)
    :return exchange_modelRev: cobrapy Model object containing only exchange reactions with the production of their respective metabolites
    '''

    cherrypy.log("Started the function that creates the reverse exchange reactions for the community model")

    exchange_modelRev = cobra.Model('Model with the exchange reactions only with reversed stoi coefficient')

    cherrypy.log("Created the base reverse exchange model object")

    for i in EXreactions: 
        new_i = str(i)
        new_i = new_i[3:]
        new_met = cobra.Metabolite(new_i)

        rxn = cobra.Reaction(i)
        rxn.lower_bound = -1000.000
        rxn.upper_bound = 1000.000
        rxn.objective_coefficient = 0.000
        rxn.add_metabolites({new_met:1.0})

        exchange_modelRev.add_reaction(rxn)

    cherrypy.log('Finished adding all exchange reactions in reverse exchange model object. There are %d of them' %(len(exchange_modelRev.reactions)))

    return exchange_modelRev
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def addEXMets2SpeciesEX(reverseEXmodel,speciesModel):
    '''
    This function takes the model with exchange reactions where the metabolite is produced (output from function createReverseEXmodel) and a species model, and adds the metabolite from the reverse model to the exhange reactions of the species model. For instance:

    Reaction :  modelB_EX_cpd11588_e0 got the cpd11588_e0[u] added.
                'model_B_cpd11588_e0 <=> cpd11588_e0[u]'

    This way, when a compound is exported to the extracellular environment, it is automatically transformed into a form that is common to all members in the community.

    :param reverseEXmodel: cobrapy Model object containing only exchange reactions with the production of their respective metabolites
    :param speciesModel: Model object of a particular species.
    :return speciesModel: Model object of a particular species with updated exchange reactions are updated.
    '''

    cherrypy.log('Started function to add metabolites to the exchange reactions of the reverse exchange model') #not right

    for j in range(len(reverseEXmodel.reactions)):
        exRxn = str(reverseEXmodel.reactions[j])

        for i in range(len(speciesModel.reactions)):
            rxn = str(speciesModel.reactions[i])
            if rxn in exRxn:
                new_met = reverseEXmodel.reactions[j].metabolites 
                speciesModel.reactions[i].add_metabolites(new_met)
                speciesModel.reactions[i].lower_bound = -1000.000
                speciesModel.reactions[i].upper_bound = 1000.000

    cherrypy.log('Finished adding metabolites to the exchange reactions of the reverse exchange model')
    return speciesModel
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def getUniqueOTU(corrs):
    '''

    In this function we use a file with three columns: columns 1 and 2 are lists of identifiers of OTUs from the microbiome study the user is interested in exploring. The third column has some value of associaltion between each pair of OTUs. The usual measure is correlation or co-occurrence, but it can be any measure of association really. This function goes through all the identifiers and creates a list of unique identifiers in the table, that is, all the different OTUs that are going to be part of the analsysi.

    :param corrs: file with the values of association between pairs of OTUs
    :returns uniqueOTUs: list with unique identifiers of OTUs
    '''

    cherrypy.log('We started the function to get the list of all unique OTUs from the file that lists how pairs of OTUs are correlated. The file we are using is %s .' %corrs)


    correlations = open(corrs,'r')
    correlations.readline()

    OTUs = []
    for line in correlations:
        line = line.rstrip().split()
        OTUs.append(line[0])
        OTUs.append(line[1])

    uniqueOTUs = list(set(OTUs))

    cherrypy.log('We created a list with %d unique OTUS.' %len(uniqueOTUs))


    return uniqueOTUs
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def getSeqs(sequences):

    '''
    In this function, we "clean up" a FASTA file. The input is a FASTA file containing the 16S rDNA sequences of all the OTUs in the microbiome study the user is exploring. This function makes sure that each genomic sequence only spans one line in the file.

    :param sequences: FASTA file with 16S dRNA sequences spanning multiple lines in addition to the sequence identifier line.
    :returns seqs: list of 16s dRNA sequences in the FASTA format spanning only one line in addition to the sequence identifier line.
    '''


    cherrypy.log("We are now going to clean up the FASTA file given (%s) so that each DNA sequence does not span multiple lines."%sequences)

    userSeqs = open(sequences,'r')

    seq = ''

    for line in userSeqs:
        if line.startswith('>'):
            seq += '+++++\n'
            seq += line
        else:
            seq += line.rstrip()


    seqs = seq.split('+++++\n')

    userSeqs.close()


    cherrypy.log("Clean up is finished.  We are ready to fetch only the representative OTU sequences that we are interested in using in the rest of our analysis." )

    return seqs
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def workingOTUs(uniqueOTUs,seqs, output):
    '''
    This function takes the outputs of the functions getUniqueOTU() and getSeqs(). It then creates a FASTA file that contains the 16S dRNA sequences for only the OTUs that are listed in the file with the association values between OTUs. This reduces the size of the files to ge used in further analysis in MMinte.


    :param uniqueOTUs: list of OTUs present in the dataset with association information, output of getUniqueOTU()
    :param seqs: set of sequences in a FASTA file where the sequences themselves only take one line and do not span multiple lines
    :param output: FASTA file with only the sequences that are needed for running Widget 2
    :returns output: FASTA file with only the sequences that are needed for running Widget 2

    '''

    cherrypy.log('Finally, we are going to create a FASTA file with only the representative OTUs that we will use in our analysis.')
    cherrypy.log('The full path to the FASTA file created is %s .' %output)

    reprOtusForAnalysis = open(output,'w')
    counter = 0
    for line in seqs:
        for item in uniqueOTUs:
            new_item = '>'+item+' '
            if line.startswith(new_item):
                counter += 1
                print>>reprOtusForAnalysis, line

    reprOtusForAnalysis.close() 


    cherrypy.log("There are a total of %d sequences to BLAST against the local database. The path to this file is %s"%(counter,output))
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def blastSeqs(seqsToBlast):
    '''
    This function uses an input FASTA file with genomic sequences of 16S dRNA and BLASTs each sequence against a local database (found in supportFiles/db/) that contains the 16S dRNA sequences of all the bacterial species in the PATRIC database that have a whole genome sequence available. It output only the top hit to a tab-delimeted text file. The 16S sequences present in the database were provided by Maulik Shukla on the 3rd of November of 2015.

    :param seqsToBlast: FASTA file containing the sequences that will be matched to the sequences in the local database. Called in blastn from parameter query.
    :param dbase: local database on ../supportFiles/db/16Sdb. Called in blastn from parameter db.
    :param tempOutputFile:  global variable defined by file on '../tempFiles/blastOutput.txt'. Raw BLAST results are temporarily stored in this file and will be processed in function listTaxId4ModelSEED(). Called in blastn from parameter out.
    :returns tempOutputFile


    '''



    from Bio.Blast.Applications import NcbiblastnCommandline
    import os

    cherrypy.log('We will blast the sequences in the FASTA file provided, %s, against a local custom database that contains the 16S sequences of the species in the NCBI that have whole genome sequences.' %(seqsToBlast))

    dbase = '../supportFiles/db/16Sdb'


    '''
    @summary: run a local blast of the user's representative OTUs, the output format is tabular, only one match is shown
    '''

    blastn_cline = NcbiblastnCommandline(cmd='../ncbi-blast-2.2.22+/bin/blastn', query= seqsToBlast, db= dbase, outfmt= 6, out= tempOutputFile, max_target_seqs = 1, num_threads = 5)

    cherrypy.log('The BLAST command that will be run is: %s' %blastn_cline)

    os.system(str(blastn_cline))


    #check if the tempOutputFile file was created. if not, shout out an error.

    if os.stat(tempOutputFile).st_size != 0:
        cherrypy.log('The %s was created and it is not empty' %tempOutputFile)
    else:
        cherrypy.log('Something is wrong because the %s appears to be empty' %tempOutputFile)
        exit()
项目:MMinte    作者:mendessoares    | 项目源码 | 文件源码
def data4plot_json(self):
        ROOT_DIR = os.path.dirname(os.path.realpath('data4plot_json'))
        full_path = ROOT_DIR + '/data4plot_json'
        with open(full_path) as data:
            return data.read()


#cherrypy.config.update({"response.timeout":1000000,'log.access_file': '../fullRun/supportFiles/logs/logAccess_file.txt','log.error_file': '../fullRun/supportFiles/logs/logError_file.txt','log.screen':True})
项目:wptagent    作者:WPO-Foundation    | 项目源码 | 文件源码
def start(self):
        self.bus.log("Starting WebSocket processing")
        self.bus.subscribe('stop', self.cleanup)
        self.bus.subscribe('handle-websocket', self.handle)
        self.bus.subscribe('websocket-broadcast', self.broadcast)
        self.manager.start()
项目:wptagent    作者:WPO-Foundation    | 项目源码 | 文件源码
def stop(self):
        self.bus.log("Terminating WebSocket processing")
        self.bus.unsubscribe('stop', self.cleanup)
        self.bus.unsubscribe('handle-websocket', self.handle)
        self.bus.unsubscribe('websocket-broadcast', self.broadcast)
项目:wptagent    作者:WPO-Foundation    | 项目源码 | 文件源码
def index(self):
            cherrypy.log("Handler created: %s" % repr(cherrypy.request.ws_handler))
项目:sql_python_deep_learning    作者:Azure    | 项目源码 | 文件源码
def index():
    cherrypy.log("CHERRYPY LOG: /")
    return render_template('index.html')
项目:sql_python_deep_learning    作者:Azure    | 项目源码 | 文件源码
def patient_gif(patient_index):
    patient_index = int(patient_index)
    if patient_index > NUMBER_PATIENTS:
        abort(BAD_REQUEST)
    cherrypy.log("CHERRYPY LOG: /gif/<patient_index>")
    gif_url = manage_gif(patient_index)
    return make_response(jsonify({'status': STATUS_OK, 'gif_url': gif_url}), STATUS_OK)
项目:sql_python_deep_learning    作者:Azure    | 项目源码 | 文件源码
def predict_patient(patient_index):
    patient_index = int(patient_index)
    if patient_index > NUMBER_PATIENTS:
        abort(BAD_REQUEST)
    cherrypy.log("CHERRYPY LOG: /predict/<patient_index>")
    prob = manage_prediction(patient_index)
    return make_response(jsonify({'status': STATUS_OK, 'prob': prob}), STATUS_OK)
项目:sql_python_deep_learning    作者:Azure    | 项目源码 | 文件源码
def patient_info():
    cherrypy.log("CHERRYPY LOG: /patient_info")
    patient_index = manage_request_patient_index(request.form['patient_index'])
    gif_url = manage_gif(patient_index)
    return render_template('patient.html', patient_index=patient_index, gif_url=gif_url)
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def reopen_files(self):
        """Close and reopen all file handlers."""
        for log in (self.error_log, self.access_log):
            for h in log.handlers:
                if isinstance(h, logging.FileHandler):
                    h.acquire()
                    h.stream.close()
                    h.stream = open(h.baseFilename, h.mode)
                    h.release()