예제 #1
0
    def __init__(self, name, port):
        super(ServiceThread, self).__init__()

        self.serviceName = name
        self.servicePort = port
        self.serviceType = self.DefaultServiceType
        self.serviceTxt = self.DefaultServiceTxt
        self.domain = self.DefaultDomain
        self.host = self.DefaultHost
        self.group = None
        self.renameCount = 10
        self.attemptedRenames = 0

        glib.DBusGMainLoop(set_as_default=True)

        self.mainLoop = gobject.MainLoop()
        gobject.timeout_add(250, self.checkIfStopRequested)
        self.bus = dbus.SystemBus()

        self.stopLock = threading.Lock()
        self.stopRequested = False

        server_obj = self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER)
        self.server = dbus.Interface(server_obj, avahi.DBUS_INTERFACE_SERVER)
        self.server.connect_to_signal('StateChanged', self.serverStateChanged)
        self.serverStateChanged(self.server.GetState())
예제 #2
0
def test():
    import glib, gobject
    gobject.threads_init()
    import dbus.mainloop.glib as dbgl
    dbgl.DBusGMainLoop(set_as_default=True)

    global bus
    bus = dbus.SessionBus()

    for service in SERVICES:
        try:
            proxy = bus.get_object(service['bus_name'],
                                   service['path'],
                                   follow_name_owner_changes=True)
        except dbus.DBusException:
            continue
        break
    else:
        return None
    assert proxy
    interface = dbus.Interface(proxy, service['dbus_interface'])
    mainloop = glib.MainLoop()

    def active_changed(new_value):
        if not new_value:
            mainloop.quit()

    interface.connect_to_signal('ActiveChanged', screensaver_active_changed)

    # For some reason Lock never returns.
    interface.Lock(ignore_reply=True)

    mainloop.run()
예제 #3
0
def monitorDevices(device_array, ripper):
    # this is needed to ensure threading works:
    import gobject
    gobject.threads_init()

    # this is needed to monitor for callbacks:
    glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SystemBus()
    udisks = bus.get_object('org.freedesktop.UDisks',
                            '/org/freedesktop/UDisks')
    udisks = dbus.Interface(udisks, 'org.freedesktop.UDisks')

    for dev in device_array:
        try:
            dev_path = udisks.FindDeviceByDeviceFile(dev)
            dev_obj = bus.get_object("org.freedesktop.UDisks", dev_path)
            dev_ifc = dbus.Interface(dev_obj, "org.freedesktop.UDisks.Device")

            # We use a lambda to store the device name with the callback
            # so we can tell which drive was changed from inside the function
            cbak = lambda: deviceChangedCallback(bus, dev, dev_path, ripper)
            dev_ifc.connect_to_signal('Changed', cbak)
            Msg("Monitoring %s" % dev)
        except:
            Warn("Device %s not found; will not monitor events" % dev)

    # begin monitoring
    mainloop = gobject.MainLoop()
    try:
        mainloop.run()
    except KeyboardInterrupt:
        # For some reason, this is raised when the daemon terminates with a
        # SIGTERM. I don't understand why this happens.
        pass
예제 #4
0
def run():
    loop = MainLoop()
    bus = SystemBus(mainloop=dglib.DBusGMainLoop())
    dglib.threads_init()

    bat_object = bus.get_object(
        'org.freedesktop.UPower',
        '/org/freedesktop/UPower/devices/battery_BAT1')
    bat = Interface(bat_object, 'org.freedesktop.DBus.Properties')

    lemonbar = Feeder(i3, bat, bus, bar, display_title)
    lemonbar.render_all()

    pulse = Pulse('event-printer')
    pulse.event_mask_set('sink', 'server')
    pulse.event_callback_set(lemonbar.on_volume_event)
    pulse_thread = Thread(target=pulse.event_listen, args=[0])
    pulse_thread.daemon = True
    pulse_thread.start()

    bat_object.connect_to_signal(
        "PropertiesChanged",
        lemonbar.on_battery_event,
        dbus_interface='org.freedesktop.DBus.Properties')
    bat_thread = Thread(target=loop.run)
    bat_thread.daemon = True
    bat_thread.start()

    sched = BackgroundScheduler(daemon=True)
    sched.add_job(lemonbar.on_timedate_event, 'cron', second=0)
    sched.start()

    def shutdown(caller, e):
        bar.stop_bar(wbak, bar_pid)
        print(e.change)
        exit(0)

    def reload_bar(caller, data):
        global bar_pid
        bar.stop_bar(wbak, bar_pid)
        #print("reloading...")
        bar_pid = bar.start_bar()
        lemonbar.set_outputs()
        lemonbar.render_all(caller=caller, e=data)

    i3.on('workspace::urgent', lemonbar.on_workspace_event)
    i3.on('workspace::empty', lemonbar.on_workspace_event)
    if display_title:
        i3.on('window::title', lemonbar.on_window_title_change)
        i3.on('window::close', lemonbar.on_window_close)
        i3.on('window::focus', lemonbar.on_window_title_change)
        i3.on('workspace::focus', lemonbar.on_workspace_focus)
    else:
        i3.on('workspace::focus', lemonbar.on_workspace_event)
    i3.on('mode', lemonbar.on_binding_mode_change)
    i3.on('output', reload_bar)
    i3.on('shutdown', shutdown)
    i3.main()
예제 #5
0
def main():
    """Main loop for the dbus service.

  This creates an instance of the Privops object at the
  DBUS_OBJECT_PATH, connecting it to a service with DBUS_BUS_NAME on
  the system bus.
  """
    # If the daemon is started through a DBus service file, the value of
    # PATH is empty enough to cause problems, so we'll just set it to a
    # new value.
    os.environ[
        'PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

    glib.DBusGMainLoop(set_as_default=True)
    name = dbus.service.BusName(DBUS_BUS_NAME, dbus.SystemBus())
    dbus_obj = Privops(name, DBUS_OBJECT_PATH)
    loop = gobject.MainLoop()
    loop.run()
예제 #6
0
    @dbus.service.method('com.excid3.bothost')
    def new_bot(self, type, id, args):
        print "launching new bot %i..." % id
        running_bots[id] = BOT_MAP[type](*args)
        running_bots[id].start()

    @dbus.service.method('com.excid3.bothost')
    def delete_bot(self, id):
        print "deleting %i" % id
        running_bots[id].stop()


if __name__ == "__main__":
    # Initialize gtk threading
    gobject.threads_init()
    glib.DBusGMainLoop(set_as_default=True)
    glib.threads_init()

    # Connect to the database
    engine = create_engine('sqlite:///' + DATABASE)
    Session = sessionmaker()
    Session.configure(bind=engine)
    session = Session()

    # Create the bots
    print "starting bots"
    for bot in session.query(Bot).all():
        running_bots[bot.id] = BOT_MAP[bot.type](bot.server, bot.port,
                                                 bot.nick, bot.channels)
        running_bots[bot.id].start()
예제 #7
0
    def __init__(self):
        glib.DBusGMainLoop(set_as_default=True)

        self.bus = dbus.SystemBus()
        self.adapter = self.find_adapter()