Example #1
0
    def __init__(self, connection, mainloop):
        """ Creates a new status checker wrapper service, with the given DBUS
        connection.

        The mainloop argument is needed for process management (eg. calling
        Quit() for graceful exiting).

        @param connection: the DBUS connection (eg. session bus, system bus)
        @type connection: a DBUS connection object

        @param mainloop: the main loop that DBUS is using
        @type mainloop: any main loop with a quit() method
        """
        dbus.service.Object.__init__(self, connection, OBJECT_PATH)

        self.encoder = simplejson.JSONEncoder(default=encode_status,
                                              separators=(',', ':'))

        self.mainloop = mainloop

        # Start the status checking daemon so we can do requests in the
        # background
        self.status_checker = StatusChecker()
    def __init__(self, connection, mainloop):
        """ Creates a new status checker wrapper service, with the given DBUS
        connection.

        The mainloop argument is needed for process management (eg. calling
        Quit() for graceful exiting).

        @param connection: the DBUS connection (eg. session bus, system bus)
        @type connection: a DBUS connection object

        @param mainloop: the main loop that DBUS is using
        @type mainloop: any main loop with a quit() method
        """
        dbus.service.Object.__init__(self, connection, OBJECT_PATH)
        
        self.encoder = simplejson.JSONEncoder(default=encode_status,
                                              separators=(',', ':'))
        
        self.mainloop = mainloop

        # Start the status checking daemon so we can do requests in the
        # background
        self.status_checker = StatusChecker()
Example #3
0
class StatusCheckerService(dbus.service.Object):
    """ StatusCheckerService objects wrap a StatusCheckerPlus instance,
    exporting methods that can be called via DBUS.

    There should only be a single such object running in a separate process from
    the GUI (ie. do not create this in the Nautilus extension code, you should
    use a StatusCheckerStub there instead).
    """
    def __init__(self, connection, mainloop):
        """ Creates a new status checker wrapper service, with the given DBUS
        connection.

        The mainloop argument is needed for process management (eg. calling
        Quit() for graceful exiting).

        @param connection: the DBUS connection (eg. session bus, system bus)
        @type connection: a DBUS connection object

        @param mainloop: the main loop that DBUS is using
        @type mainloop: any main loop with a quit() method
        """
        dbus.service.Object.__init__(self, connection, OBJECT_PATH)

        self.encoder = simplejson.JSONEncoder(default=encode_status,
                                              separators=(',', ':'))

        self.mainloop = mainloop

        # Start the status checking daemon so we can do requests in the
        # background
        self.status_checker = StatusChecker()

    @dbus.service.method(INTERFACE)
    def ExtraInformation(self):
        return self.status_checker.extra_info()

    @dbus.service.method(INTERFACE)
    def MemoryUsage(self):
        own_mem = rabbitvcs.util.helper.process_memory(os.getpid())
        checker_mem = self.status_checker.get_memory_usage()

        return own_mem + checker_mem

    @dbus.service.method(INTERFACE)
    def PID(self):
        return os.getpid()

    @dbus.service.method(INTERFACE)
    def CheckerType(self):
        return self.status_checker.CHECKER_NAME

    @dbus.service.method(INTERFACE, in_signature='sbbb', out_signature='s')
    def CheckStatus(self,
                    path,
                    recurse=False,
                    invalidate=False,
                    summary=False):
        """ Requests a status check from the underlying status checker.
        """
        status = self.status_checker.check_status(six.text_type(path),
                                                  recurse=recurse,
                                                  summary=summary,
                                                  invalidate=invalidate)

        return self.encoder.encode(status)

    @dbus.service.method(INTERFACE, in_signature='as', out_signature='s')
    def GenerateMenuConditions(self, paths):
        upaths = []
        for path in paths:
            upaths.append(six.text_type(path))

        path_dict = self.status_checker.generate_menu_conditions(upaths)
        return simplejson.dumps(path_dict)

    @dbus.service.method(INTERFACE)
    def CheckVersionOrDie(self, version):
        """
        If the version passed does not match the version of RabbitVCS available
        when this service started, the service will exit. The return value is
        None if the versions match, else it's the PID of the service (useful for
        waiting for the process to exit).
        """
        if not self.CheckVersion(version):
            log.warning("Version mismatch, quitting checker service " \
                        "(service: %s, extension: %s)" \
                        % (SERVICE_VERSION, version))
            return self.Quit()

        return None

    @dbus.service.method(INTERFACE)
    def CheckVersion(self, version):
        """
        Return True iff the version of RabbitVCS imported by this service is the
        same as that passed in (ie. used by extension code).
        """
        return version == SERVICE_VERSION

    @dbus.service.method(INTERFACE)
    def Quit(self):
        """ Quits the service, performing any necessary cleanup operations.

        You can call this from the command line with:

        dbus-send --print-reply \
        --dest=org.google.code.rabbitvcs.RabbitVCS.Checker \
        /org/google/code/rabbitvcs/StatusChecker \
        org.google.code.rabbitvcs.StatusChecker.Quit

        If calling this programmatically, then you can do "os.waitpid(pid, 0)"
        on the returned PID to prevent a zombie process.
        """
        self.status_checker.quit()
        log.debug("Quitting main loop...")
        self.mainloop.quit()
        return self.PID()
class StatusCheckerService(dbus.service.Object):
    """ StatusCheckerService objects wrap a StatusCheckerPlus instance,
    exporting methods that can be called via DBUS.

    There should only be a single such object running in a separate process from
    the GUI (ie. do not create this in the Nautilus extension code, you should
    use a StatusCheckerStub there instead).
    """

    def __init__(self, connection, mainloop):
        """ Creates a new status checker wrapper service, with the given DBUS
        connection.

        The mainloop argument is needed for process management (eg. calling
        Quit() for graceful exiting).

        @param connection: the DBUS connection (eg. session bus, system bus)
        @type connection: a DBUS connection object

        @param mainloop: the main loop that DBUS is using
        @type mainloop: any main loop with a quit() method
        """
        dbus.service.Object.__init__(self, connection, OBJECT_PATH)
        
        self.encoder = simplejson.JSONEncoder(default=encode_status,
                                              separators=(',', ':'))
        
        self.mainloop = mainloop

        # Start the status checking daemon so we can do requests in the
        # background
        self.status_checker = StatusChecker()

    @dbus.service.method(INTERFACE)
    def ExtraInformation(self):
        return self.status_checker.extra_info()

    @dbus.service.method(INTERFACE)
    def MemoryUsage(self):
        own_mem = rabbitvcs.util.helper.process_memory(os.getpid())
        checker_mem = self.status_checker.get_memory_usage()

        return own_mem + checker_mem

    @dbus.service.method(INTERFACE)
    def PID(self):
        return os.getpid()

    @dbus.service.method(INTERFACE)
    def CheckerType(self):
        return self.status_checker.CHECKER_NAME

    @dbus.service.method(INTERFACE, in_signature='sbbb', out_signature='s')
    def CheckStatus(self, path, recurse=False, invalidate=False,
                      summary=False):
        """ Requests a status check from the underlying status checker.
        """
        status = self.status_checker.check_status(six.text_type(path),
                                                  recurse=recurse,
                                                  summary=summary,
                                                  invalidate=invalidate)
        
        return self.encoder.encode(status)

    @dbus.service.method(INTERFACE, in_signature='as', out_signature='s')
    def GenerateMenuConditions(self, paths):
        upaths = []
        for path in paths:
            upaths.append(six.text_type(path))
    
        path_dict = self.status_checker.generate_menu_conditions(upaths)
        return simplejson.dumps(path_dict)

    @dbus.service.method(INTERFACE)
    def CheckVersionOrDie(self, version):
        """
        If the version passed does not match the version of RabbitVCS available
        when this service started, the service will exit. The return value is
        None if the versions match, else it's the PID of the service (useful for
        waiting for the process to exit).
        """
        if not self.CheckVersion(version):
            log.warning("Version mismatch, quitting checker service " \
                        "(service: %s, extension: %s)" \
                        % (SERVICE_VERSION, version))
            return self.Quit()

        return None

    @dbus.service.method(INTERFACE)
    def CheckVersion(self, version):
        """
        Return True iff the version of RabbitVCS imported by this service is the
        same as that passed in (ie. used by extension code).
        """
        return version == SERVICE_VERSION

    @dbus.service.method(INTERFACE)
    def Quit(self):
        """ Quits the service, performing any necessary cleanup operations.

        You can call this from the command line with:

        dbus-send --print-reply \
        --dest=org.google.code.rabbitvcs.RabbitVCS.Checker \
        /org/google/code/rabbitvcs/StatusChecker \
        org.google.code.rabbitvcs.StatusChecker.Quit

        If calling this programmatically, then you can do "os.waitpid(pid, 0)"
        on the returned PID to prevent a zombie process.
        """
        self.status_checker.quit()
        log.debug("Quitting main loop...")
        self.mainloop.quit()
        return self.PID()