Beispiel #1
0
def _install_handler(sig):
    global _handlers, python_signal
    if sig in _handlers:
        # we are already installed for this signal
        return

    current = python_signal.getsignal(sig)
    if current is None or current == SIG_DFL or current == SIG_IGN:
        current = None
    _handlers[sig] = (current, [])
    log.log('signal', "Instaling generic signal handler for signal %r.", sig)
    python_signal.signal(sig, _handler_ext)
Beispiel #2
0
    def testDefaultLogging(self):
        keeper = DummyLogKeeper()
        log.set_default(keeper)

        log.log("foo", "1")
        log.debug("bar", "2", 42)
        log.info("spam", "3")
        log.warning("bacon", "4", 2, 3, 5)
        log.error("eggs", "4")

        self.assertEqual(keeper.entries,
                         [(LogLevel.log, None, 'foo', '1', (), 1),
                          (LogLevel.debug, None, 'bar', '2', (42, ), 1),
                          (LogLevel.info, None, 'spam', '3', (), 1),
                          (LogLevel.warning, None, 'bacon', '4', (2, 3, 5), 1),
                          (LogLevel.error, None, 'eggs', '4', (), 1)])
Beispiel #3
0
def get_pid(rundir, type=PROCESS_TYPE, name=None):
    """
    Get the pid from the pid file in the run directory, using the given
    process type and process name for the filename.

    @returns: pid of the process, or None if not running or file not found.
    """
    pidPath = _get_pidpath(rundir, type, name)
    log.log('run', 'pidfile for %s %s is %s' % (type, name, pidPath))

    if not os.path.exists(pidPath):
        return

    pidFile = open(pidPath, 'r')
    pid = pidFile.readline()
    pidFile.close()
    if not pid or int(pid) == 0:
        return

    return int(pid)
Beispiel #4
0
def load(module_name, name):
    log.log("application", "Importing application %s from module %s", name, module_name)
    module = sys.modules.get(module_name)
    if module:
        log.log("application", "Application module %s has already been loaded. ", module_name)
    else:
        module = reflect.named_module(module_name)
    application = getattr(module, name, None)
    if application is None:
        raise ValueError("Module %s has no attribute %s" % (module_name, name))
    if not IApplication.providedBy(application):
        raise ValueError("Variable %s.%s should provide IApplication interface" % (module_name, name))
    try:
        application.load()
    except Exception as e:
        error.handle_exception("application", e, "Error loading application: %s", application.name)
        application.unload()
        raise
    else:
        get_application_registry().register(application)
        log.debug("application", "Loading application %s complete.", name)
Beispiel #5
0
    def testDefaultLogging(self):
        keeper = DummyLogKeeper()
        current = log.get_default()
        log.set_default(keeper)
        self.addCleanup(log.set_default, current)

        log.log("foo", "1")
        log.debug("bar", "2", 42)
        log.info("spam", "3")
        log.warning("bacon", "4", 2, 3, 5)
        log.error("eggs", "4")

        self.assertEqual(
            keeper.entries,
            [
                (LogLevel.log, None, "foo", "1", (), 1),
                (LogLevel.debug, None, "bar", "2", (42,), 1),
                (LogLevel.info, None, "spam", "3", (), 1),
                (LogLevel.warning, None, "bacon", "4", (2, 3, 5), 1),
                (LogLevel.error, None, "eggs", "4", (), 1),
            ],
        )
Beispiel #6
0
def locate(connection, agent_id):
    """
    Return the hostname of the agency where given agent runs or None.
    """
    connection = IDatabaseClient(connection)
    log.log("locate", "Locate called for agent_id: %r", agent_id)
    try:
        desc = yield connection.get_document(agent_id)
        log.log("locate", "Got document %r", desc)
        if isinstance(desc, host.Descriptor):
            defer.returnValue(desc.hostname)
        elif isinstance(desc, descriptor.Descriptor):
            host_part = first(x for x in desc.partners if x.role == "host")
            if host_part is None:
                log.log("locate", "No host partner found in descriptor.")
                defer.returnValue(None)
            res = yield locate(connection, host_part.recipient.key)
            defer.returnValue(res)
    except NotFoundError:
        log.log("locate", "Host with id %r not found, returning None", agent_id)
        defer.returnValue(None)
Beispiel #7
0
 def error(self, error, code=http.Status.NOT_FOUND):
     log.log('web-hapi', error)
     return self._serializer.convert(error), code