Beispiel #1
0
    def __init__(self, bus=None, backend_dir=None):
        log.info('starting daemon')

        signal.signal(signal.SIGQUIT, self._quit_handler)
        signal.signal(signal.SIGTERM, self._quit_handler)

        if not bus:
            bus = dbus.SystemBus()
        self.bus = bus
        if not backend_dir:
            backend_dir = mdvpkg.DEFAULT_BACKEND_DIR
        self._loop = gobject.MainLoop()
        try:
            bus_name = dbus.service.BusName(mdvpkg.SERVICE,
                                            self.bus,
                                            do_not_queue=True)
        except dbus.exceptions.NameExistsException:
            log.critical('someone is using %s service name',
                         mdvpkg.SERVICE)
            sys.exit(1)
        dbus.service.Object.__init__(self, bus_name, mdvpkg.PATH)

        self.urpmi = UrpmiDB(backend_dir=backend_dir)
        self.urpmi.connect('task-queued', self.TaskQueued)
        self.urpmi.connect('task-running', self.TaskRunning)
        self.urpmi.connect('task-progress', self.TaskProgress)
        self.urpmi.connect('task-done', self.TaskDone)
        self.urpmi.configure_medias()
        self.urpmi.load_packages()

        log.info('daemon is ready')
Beispiel #2
0
class MdvPkgDaemon(dbus.service.Object):
    """Represents the daemon, which provides the dbus interface (by
    default at the system bus)."""

    def __init__(self, bus=None, backend_dir=None):
        log.info('starting daemon')

        signal.signal(signal.SIGQUIT, self._quit_handler)
        signal.signal(signal.SIGTERM, self._quit_handler)

        if not bus:
            bus = dbus.SystemBus()
        self.bus = bus
        if not backend_dir:
            backend_dir = mdvpkg.DEFAULT_BACKEND_DIR
        self._loop = gobject.MainLoop()
        try:
            bus_name = dbus.service.BusName(mdvpkg.SERVICE,
                                            self.bus,
                                            do_not_queue=True)
        except dbus.exceptions.NameExistsException:
            log.critical('someone is using %s service name',
                         mdvpkg.SERVICE)
            sys.exit(1)
        dbus.service.Object.__init__(self, bus_name, mdvpkg.PATH)

        self.urpmi = UrpmiDB(backend_dir=backend_dir)
        self.urpmi.connect('task-queued', self.TaskQueued)
        self.urpmi.connect('task-running', self.TaskRunning)
        self.urpmi.connect('task-progress', self.TaskProgress)
        self.urpmi.connect('task-done', self.TaskDone)
        self.urpmi.configure_medias()
        self.urpmi.load_packages()

        log.info('daemon is ready')

    def run(self):
        try:
            self._loop.run()
        except KeyboardInterrupt:
            self.Quit(None)

    #
    # Media related signals
    #

    @dbus.service.signal(dbus_interface=mdvpkg.IFACE,
                         signature='sbb')
    def Media(self, media_name, update, ignore):
        """A media found during media listing."""
        log.debug('Media(%s, %s, %s)', media_name, update, ignore)

    #
    # Task related signals
    # 

    @dbus.service.signal(dbus_interface=mdvpkg.IFACE,
                         signature='s')
    def TaskQueued(self, task_id):
        log.debug('TaskQueued(%s)', task_id)
        
    @dbus.service.signal(dbus_interface=mdvpkg.IFACE,
                         signature='s')
    def TaskRunning(self, task_id):
        log.debug('TaskRunning(%s)', task_id)

    @dbus.service.signal(dbus_interface=mdvpkg.IFACE,
                         signature='suu')
    def TaskProgress(self, task_id, count, total):
        log.debug('TaskProgress(%s, %s, %s)', task_id, count, total)

    @dbus.service.signal(dbus_interface=mdvpkg.IFACE,
                         signature='s')
    def TaskDone(self, task_id):
        log.debug('TaskDone(%s)', task_id)

    #
    # Daemon methods
    #

    @dbus.service.method(mdvpkg.IFACE,
                         in_signature='',
                         out_signature='o',
                         sender_keyword='sender')
    def GetList(self, sender):
        log.info('GetList() called')
        list = DBusPackageList(self.urpmi, sender, self.bus)
        return list.path

    @dbus.service.method(mdvpkg.IFACE,
                         in_signature='',
                         out_signature='',
                         sender_keyword='sender')
    def Quit(self, sender):
        """Request a shutdown of the service."""
        log.info('shutdown was requested')
        log.debug('quitting main loop ...')
        self._loop.quit()

    def _quit_handler(self, signum, frame):
        """Handler for quiting signals."""
        self.Quit(None)