def __init__(self): DBusGMainLoop(set_as_default=True) try: self.bus = dbus.SessionBus() except Exception as exception: print( 'Launcher-API-Daemon: Could not open dbus. Uncaught exception.' ) return bus_name = dbus.service.BusName( self.bus_name_str, self.bus, allow_replacement=True ) # allow Unity shell to take ownership of the bus name; we only want to register on the bus so that other applications know they can send message on the LauncherEntry interface print("Launcher-API-Daemon: registered as Unity:", bus_name) self.bus.add_signal_receiver(self.on_launcher_entry_signal, dbus_interface=self.bus_iface_str, member_keyword='member', sender_keyword='sender') self.dock = CairoDock() if g_bMainLoopInGObject: self.loop = gobject.MainLoop() else: self.loop = glib.MainLoop() self.loop.run()
def run(self, uri): def bus_cb(bus, msg): if gst.MESSAGE_TAG == msg.type: print dict(msg.structure) return True def test_cb(): if 'flat' == self.profile: self.profile = 'pop' else: self.profile = 'flat' return True glib.timeout_add(5000, test_cb) self.get_bus().add_watch(bus_cb) self.uri = uri self.volume = 0.5 self.set_state(gst.STATE_PLAYING) try: glib.MainLoop().run() except KeyboardInterrupt: pass
def main(): opts = get_config() #dbus.glib.threads_init() #glib.theads_init() bus_loop = DBusGMainLoop(set_as_default=True) main_loop = glib.MainLoop() bus = dbus.SystemBus() bluez_proxy = bus.get_object('org.bluez', '/') bluez_manager = dbus.Interface(bluez_proxy, 'org.bluez.Manager') if opts.adapter is not None: adapter = bluez_manager.FindAdapter(opts.adapter) else: adapter = bluez_manager.DefaultAdapter() bd_path = '%s/dev_%s' % (adapter, opts.bdaddr.upper().replace(':', '_')) def input_callback(*args): # print 'INPUT: %s' % repr(args) main_loop.quit() return True # What return value signifies what? glib.io_add_watch(sys.stdin, glib.IO_IN, input_callback) try: bluez_net_monitor = BluezNetMonitor(bus, bd_path, main_loop, opts.reconnect) except dbus.exceptions.DBusException as e: return 1 print 'Press enter to close connection' main_loop.run()
def _get_new_transaction(self): if self._loop is None: import glib self._loop = glib.MainLoop() if self._sysbus is None: import dbus.glib import dbus self._dbus = dbus self._sysbus = dbus.SystemBus() if self._pkdbus is None: self._pkdbus = dbus.Interface( self._sysbus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit'), 'org.freedesktop.PackageKit') properties = dbus.Interface(self._pkdbus, 'org.freedesktop.DBus.Properties') self._pk_major = properties.Get('org.freedesktop.PackageKit', 'VersionMajor') self._pk_minor = properties.Get('org.freedesktop.PackageKit', 'VersionMinor') if self._pk_major == 0 and self._pk_minor >= 8: txn_path = self._pkdbus.CreateTransaction() txn = self._sysbus.get_object('org.freedesktop.PackageKit', txn_path) else: tid = self._pkdbus.GetTid() txn = self._sysbus.get_object('org.freedesktop.PackageKit', tid) txn_tx = self._dbus.Interface( txn, 'org.freedesktop.PackageKit.Transaction') txn.connect_to_signal('Message', self._on_pk_message) txn.connect_to_signal('ErrorCode', self._on_pk_error) txn.connect_to_signal('Destroy', lambda *args: self._loop.quit()) return txn_tx, txn
def _create_connection(self, credentials=None): if credentials is None: user, password = self._parsed_url.user, self._parsed_url.password else: user, password = credentials try: connection = gio.File(self.url) mount = None try: mount = connection.find_enclosing_mount() except gio.Error as e: if (e.code == gio.ERROR_NOT_MOUNTED): self.loop = glib.MainLoop() ui.ui_factory.show_message('Mounting %s using GIO' % self.url) op = gio.MountOperation() if user: op.set_username(user) if password: op.set_password(password) op.connect('ask-password', self._auth_cb) m = connection.mount_enclosing_volume( op, self._mount_done_cb) self.loop.run() except gio.Error as e: raise errors.TransportError(msg="Error setting up connection:" " %s" % str(e), orig_error=e) return connection, (user, password)
def main(): mainloop = glib.MainLoop() def cb(): test_clipboard() mainloop.quit() glib.idle_add(cb) mainloop.run()
def _get_new_transaction(self): if self._loop is None: import glib self._loop = glib.MainLoop() if self._sysbus is None: import dbus.glib import dbus self._dbus = dbus self._sysbus = dbus.SystemBus() if self._pkdbus is None: self._pkdbus = dbus.Interface(self._sysbus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit'), 'org.freedesktop.PackageKit') if self._using_pk_0_8_1 is None: try: txn_path = self._pkdbus.CreateTransaction() txn = self._sysbus.get_object('org.freedesktop.PackageKit', txn_path) self._using_pk_0_8_1 = True except dbus.exceptions.DBusException: tid = self._pkdbus.GetTid() txn = self._sysbus.get_object('org.freedesktop.PackageKit', tid) self._using_pk_0_8_1 = False elif self._using_pk_0_8_1: txn_path = self._pkdbus.CreateTransaction() txn = self._sysbus.get_object('org.freedesktop.PackageKit', txn_path) else: tid = self._pkdbus.GetTid() txn = self._sysbus.get_object('org.freedesktop.PackageKit', tid) txn_tx = self._dbus.Interface(txn, 'org.freedesktop.PackageKit.Transaction') txn.connect_to_signal('Message', self._on_pk_message) txn.connect_to_signal('ErrorCode', self._on_pk_error) txn.connect_to_signal('Destroy', lambda *args: self._loop.quit()) return txn_tx, txn
def testSourcePrepare(self): # this test may not terminate if prepare() is wrapped incorrectly dispatched = [False] loop = glib.MainLoop() class CustomTimeout(glib.Source): def prepare(self): return (False, 10) def check(self): return True def dispatch(self, callback, args): dispatched[0] = True loop.quit() return False source = CustomTimeout() source.attach() source.set_callback(dir) loop.run() assert dispatched[0]
def run(self): # Using Dbus-python's default mainloop to listen to the events DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() # creating a salt caller object, this is used to push events using # salt's eventing framework caller = salt.client.Caller() cb = callBack.CallBack(caller) # this initializes/updates the interested signals # (read from config file) to be listened brom the bus update_listener(cb, bus) loop = glib.MainLoop() glib.threads_init() # create a thread to run the main loop which will listen to the dbus # and push the events to salt-master t = threading.Thread(target=mainSource, args=(loop, )) t.start() # this will continue and listent to external signals (sighup,sigterm) # if sighup, the signals to be listened is reread from the config file # if sigterm, the daemon will be terminated while RUN: signalHandler(loop, cb, bus)
def main(): target = sys.argv[1] opts = make_defaults_struct() MAX_CLIENTS = 10 clients = [] def start_try(): sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "trylogin") def stop_cb(client): try: clients.remove(client) except: pass if len(clients) < MAX_CLIENTS: start_try() def cracked_cb(password): sys.exit(0) tl = TryLogin(conn, opts, gen_password(), stop_cb, cracked_cb) clients.append(tl) tl.run() for _ in range(MAX_CLIENTS): glib.idle_add(start_try) glib_mainloop = glib.MainLoop() glib_mainloop.run()
def ensure_avahi_is_running(): bus = dbus.SystemBus() bus_obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') if bus_obj.NameHasOwner('org.freedesktop.Avahi', dbus_interface='org.freedesktop.DBus'): return loop = glib.MainLoop() def name_owner_changed_cb(name, old_owner, new_owner): loop.quit() noc = bus.add_signal_receiver(name_owner_changed_cb, signal_name='NameOwnerChanged', dbus_interface='org.freedesktop.DBus', arg0='org.freedesktop.Avahi') # Cannot use D-Bus activation because we have no way to pass to activated # clients the address of the system bus and we cannot host the service in # this process because we are going to make blocking calls and we would # deadlock. tests_dir = os.path.dirname(__file__) avahimock_path = os.path.join(tests_dir, 'avahimock.py') Popen([avahimock_path]) loop.run() noc.remove()
def _get_new_transaction(self): if self._loop is None: try: import glib except: try: from gi.repository import GLib as glib except: raise SystemExit( _('Error: python-gobject package not found.')) self._loop = glib.MainLoop() if self._sysbus is None: try: import dbus.glib except: raise SystemExit(_('Error: dbus-python package not found.')) import dbus self._dbus = dbus self._sysbus = dbus.SystemBus() if self._pkdbus is None: self._pkdbus = dbus.Interface( self._sysbus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit'), 'org.freedesktop.PackageKit') properties = dbus.Interface(self._pkdbus, 'org.freedesktop.DBus.Properties') txn_path = self._pkdbus.CreateTransaction() txn = self._sysbus.get_object('org.freedesktop.PackageKit', txn_path) txn_tx = self._dbus.Interface( txn, 'org.freedesktop.PackageKit.Transaction') txn.connect_to_signal('Message', self._on_pk_message) txn.connect_to_signal('ErrorCode', self._on_pk_error) txn.connect_to_signal('Destroy', lambda *args: self._loop.quit()) return txn_tx, txn
def player_thread(self): if self.__player is None: self.__player = gst.element_factory_make("playbin2", "player") self.__player.set_state(gst.STATE_NULL) bus = self.__player.get_bus() bus.add_signal_watch() bus.connect("message", self.handle_song_end) glib.MainLoop().run()
def main(): server = HCIPlayerServer(('0.0.0.0', 9090), HCIPlayerRequestHandler) thread = threading.Thread(target=server.serve_forever) thread.daemon = True thread.start() glib.MainLoop().run()
def launch(self): self.launcher.start() gobject.threads_init() self.loop = glib.MainLoop() try: self.loop.run() except KeyboardInterrupt: pass
def get_usb_devices(): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-event', device_event) monitor.start() glib.MainLoop().run()
def run(self): """Initialize controller start mainloop.""" # if no gui to control experiment is present, just start running the # experiment if len(self.gui) == 0 and self.play_callback is not None: self.play() self.ml = glib.MainLoop() self.ml.run()
def monitor(): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-removed', remove_event) observer.connect('device-added', add_event) monitor.start() glib.MainLoop().run()
def configure_device(self): # binding process starts here loop = glib.MainLoop() device_listener = DeviceListener(self, loop, 'add') client = gudev.Client(["usb/usb_device"]) client.connect("uevent", device_listener.callback, None) loop.run() return device_listener.device_info
def watch_removed_device(self): # look for removed device loop = glib.MainLoop() device_listener = DeviceListener(self, loop, "remove") client = gudev.Client(["usb/usb_device"]) client.connect("uevent", device_listener.callback, None) loop.run() return device_listener.device_found
def __start_monitoring(self): self.__monitor_list = {} self.__monitor_directory(self.__track_path) print u'Type ctrl-c to stop.' try: main_loop = glib.MainLoop() main_loop.run() except: print u'Monitoring stopped.'
def testChildWatch(self): self.data = None self.loop = glib.MainLoop() argv = [sys.executable, '-c', 'import sys'] pid, stdin, stdout, stderr = glib.spawn_async( argv, flags=glib.SPAWN_DO_NOT_REAP_CHILD) pid.close() glib.child_watch_add(pid, self._child_watch_cb, 12345) self.loop.run() self.assertEqual(self.data, 12345)
def main(): """ main() -- entry point for this program """ global SEND_SMS global DAEMONIZE global PID_FILE # Parse CLI options args = parse_cli() DAEMONIZE = args.daemonize PID_FILE = args.pid_file SEND_SMS = args.sms context = Context() # Populate list of current USB devices for device in context.list_devices(subsystem="usb"): busnum = get_device_info(device, "busnum") devnum = get_device_info(device, "devnum") id_product = get_device_info(device, "idProduct") id_vendor = get_device_info(device, "idVendor") manufacturer = get_device_info(device, "manufacturer") product = get_device_info(device, "product") if busnum: USB_DEVICES.append((device.device_path, busnum, devnum, id_vendor, id_product, manufacturer, product)) monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-event', device_event) monitor.start() if DAEMONIZE: usbwatch_pid = os.fork() if usbwatch_pid != 0: return os.EX_OK write_pid_file(PID_FILE, os.getpid()) xprint("[+] usb-watch by Daniel Roberson @dmfroberson Started. PID %s" % \ os.getpid()) try: glib.MainLoop().run() except KeyboardInterrupt: print "[-] Caught Control-C. Andross has ordered us to take you down." print "[-] Exiting." return os.EX_OK
def run(self): """ start the applet and enter the main loop; we never get out of this function """ self.begin() if not self._bEnded: # _bEnded can be true if the applet runs its own main loop, in which case we stay stuck in the 'begin' function until the end of the applet; in this case, we don't want to run a main loop again! if g_bMainLoopInGObject: self.loop = gobject.MainLoop() else: self.loop = glib.MainLoop() self.loop.run() print(">>> applet '"+self.cAppletName+"' terminated.") sys.exit(0)
def loopForDevices(): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='block',device_type='partition') # monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-event', device_event) monitor.start() glib.MainLoop().run()
def __init__(self): self.messages = MessageList() self.receiver = InputReceiver(self.input_handler) self.init_bus_connection() #MainLoop gobject.threads_init() mainloop = glib.MainLoop() mainloop.run()
def watch_added_device(self): loop = glib.MainLoop() device_listener = DeviceListener(self, loop, "add") client = gudev.Client(["usb/usb_device"]) # client = gudev.Client([]) # all types client.connect("uevent", device_listener.callback, None) loop.run() return device_listener.device_found
def main(): print u'豆瓣电台' doubanfm = DoubanFM_CLI() doubanfm.print_menu() while 1: loop = glib.MainLoop() thread.start_new_thread(doubanfm.start, (loop, )) gobject.threads_init() loop.run()
def testFlushAsync(self): def callback(stream, result): try: self.failUnless(stream.flush_finish(result)) finally: loop.quit() self.stream.flush_async(callback) loop = glib.MainLoop() loop.run()
def _testCloseAsync(self): def callback(stream, result): try: self.failUnless(stream.close_finish(result)) finally: loop.quit() self.stream.close_async(callback) loop = glib.MainLoop() loop.run()