def _scan_devices(self): self.devices = {} indices = {} if os.path.exists(DEVICES_PATH): for device in os.listdir(DEVICES_PATH): # Only want devices with leds device_path = os.path.join(DEVICES_PATH, device) leds_path = os.path.join(device_path, "leds") if os.path.exists(leds_path): # Extract the USB ID a = device.split(":") usb_id = ( int("0x%s" % a[1], 16), int("0x%s" % a[2].split(".")[0], 16) ) logger.info("Testing if device %04x:%04x is supported by Gnome15", usb_id[0], usb_id[1]) # Look for a matching Gnome15 device for device in g15devices.find_all_devices(): if device.controls_usb_id == usb_id: # Found a device we want logger.info("Found device %s", str(device)) # Work out UID # TODO this is not quite right - if there is more than one device of same type, indexs might not match index = 0 if not device.model_id in indices else indices[device.model_id] keyboard_device = KeyboardDevice(device, device_path, index) self.devices[device.uid] = keyboard_device indices[device.model_id] = index + 1 else: logger.info("No devices found at %s", DEVICES_PATH)
def __init__(self, service): AbstractG15DBUSService.__init__(self) self._service = service logger.debug("Getting Session DBUS") self._bus = dbus.SessionBus() self._page_sequence_number = 1 self._acquire_sequence_number = 1 logger.debug("Exposing service") self._bus_name = dbus.service.BusName(BUS_NAME, bus=self._bus, replace_existing=False, allow_replacement=False, do_not_queue=True) dbus.service.Object.__init__(self, self._bus_name, NAME) self._service.service_listeners.append(self) logger.debug("DBUS service ready") self._dbus_screens = {} self._dbus_devices = [] self._dbus_device_map = {} for device in g15devices.find_all_devices(): dbus_device = G15DBUSDeviceService(self, device) self._dbus_devices.append(dbus_device) self._dbus_device_map[device.uid] = dbus_device g15devices.device_added_listeners.append(self._device_added) g15devices.device_removed_listeners.append(self._device_removed) self._bus.add_signal_receiver(self._name_owner_changed, dbus_interface='org.freedesktop.DBus', signal_name='NameOwnerChanged')
def _scan_devices(self): self.devices = {} indices = {} if os.path.exists(DEVICES_PATH): for device in os.listdir(DEVICES_PATH): # Only want devices with leds device_path = os.path.join(DEVICES_PATH, device) leds_path = os.path.join(device_path, "leds") if os.path.exists(leds_path): # Extract the USB ID a = device.split(":") usb_id = (int("0x%s" % a[1], 16), int("0x%s" % a[2].split(".")[0], 16)) logger.info( "Testing if device %04x:%04x is supported by Gnome15", usb_id[0], usb_id[1]) # Look for a matching Gnome15 device for device in g15devices.find_all_devices(): if device.controls_usb_id == usb_id: # Found a device we want logger.info("Found device %s", str(device)) # Work out UID # TODO this is not quite right - if there is more than one device of # same type, indexs might not match index = 0 if not device.model_id in indices else indices[ device.model_id] keyboard_device = KeyboardDevice( device, device_path, index) self.devices[device.uid] = keyboard_device indices[device.model_id] = index + 1 else: logger.info("No devices found at %s", DEVICES_PATH)
def __init__(self, service_host, no_trap=False): self.exit_on_no_devices = False self.active_plugins = {} self.session_active = True self.service_host = service_host self.active_window = None self.shutting_down = False self.starting_up = True self.conf_client = gconf.Client.get_default() self.screens = [] self.started = False self.service_listeners = [] self.notify_handles = [] self.device_notify_handles = {} self.font_faces = {} self.stopping = False self.window_title_listener = None self.active_application_name = None self.active_window_title = None self.ignore_next_sigint = False self.debug_svg = False self.devices = g15devices.find_all_devices() self.macro_handler = MacroHandler() self.global_plugins = None # Expose Gnome15 functions via DBus logger.debug("Starting the DBUS service") self.dbus_service = g15dbus.G15DBUSService(self) # Watch for signals if not no_trap: signal.signal(signal.SIGINT, self.sigint_handler) signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGUSR1, self.sigusr1_handler) g15desktop.G15AbstractService.__init__(self) self.name = "DesktopService"
def __init__(self, service_host, no_trap=False): self.exit_on_no_devices = False self.active_plugins = {} self.session_active = True self.service_host = service_host self.active_window = None self.shutting_down = False self.starting_up = True self.conf_client = gconf.client_get_default() self.screens = [] self.started = False self.service_listeners = [] self.notify_handles = [] self.device_notify_handles = {} self.font_faces = {} self.stopping = False self.window_title_listener = None self.active_application_name = None self.active_window_title = None self.ignore_next_sigint = False self.debug_svg = False self.devices = g15devices.find_all_devices() self.macro_handler = MacroHandler() self.global_plugins = None # Expose Gnome15 functions via DBus logger.debug("Starting the DBUS service") self.dbus_service = g15dbus.G15DBUSService(self) # Watch for signals if not no_trap: signal.signal(signal.SIGINT, self.sigint_handler) signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGUSR1, self.sigusr1_handler) g15desktop.G15AbstractService.__init__(self) self.name = "DesktopService"
def version_0_x_0_to_0_7_0(): """ First version to upgrade configuration. This is the version where multiple device support was introduced, pushing configuration into sub-directories """ macros_dir = os.path.join(g15globals.user_config_dir, "macro_profiles") if os.path.exists(os.path.join(macros_dir, "0.macros")): logger.info("Upgrading macros and configuration to 0.7.x format") """ If the default macro profile exists at the root of the macro_profiles directory, then conversion hasn't yet occurred. So, copy all profiles into all device sub-directories """ devices = g15devices.find_all_devices() for file in os.listdir(macros_dir): if file.endswith(".macros"): profile_file = os.path.join(macros_dir, file) for device in devices: device_dir = os.path.join(macros_dir, device.uid) if not os.path.exists(device_dir): logger.info("Creating macro_profile directory for %s", device.uid) os.mkdir(device_dir) logger.info("Copying macro_profile %s to %s ", file, device.uid) shutil.copyfile(profile_file, os.path.join(device_dir, file)) os.remove(profile_file) """ Copy the GConf folders. """ gconf_dir = os.path.expanduser("~/.gconf/apps/gnome15") gconf_file = os.path.join(gconf_dir, "%gconf.xml") gconf_plugins_dir = os.path.join(gconf_dir, "plugins") for device in devices: device_dir = os.path.join(gconf_dir, device.uid) if not os.path.exists(device_dir): logger.info("Creating GConf directory for %s", device.uid) os.mkdir(device_dir) logger.info("Copying settings %s to %s", gconf_file, device.uid) shutil.copyfile(gconf_file, os.path.join(device_dir, "%gconf.xml")) logger.info("Copying plugin settings %s to %s", gconf_plugins_dir, device.uid) target_plugins_path = os.path.join(device_dir, "plugins") if not os.path.exists(target_plugins_path): shutil.copytree(gconf_plugins_dir, target_plugins_path ) logger.info("Clearing current settings root") shutil.rmtree(gconf_plugins_dir) f = open(gconf_file, 'w') try: f.write('<?xml version="1.0">\n') f.write('<gconf>\n') f.write('</gconf>\n') finally: f.close() """ Tell GConf to reload it caches by finding it's process ID and sending it SIGHUP """ if sys.version_info > (2, 6): process_info = subprocess.check_output(["sh", "-c", "ps -U %d|grep gconfd|head -1" % os.getuid()]) else: import commands process_info = commands.getstatusoutput("sh -c \"ps -U %d|grep gconfd|head -1\"" % os.getuid()) if process_info: pid = g15pythonlang.split_args(process_info)[0] logger.info("Sending process %s SIGHUP", pid) subprocess.check_call([ "kill", "-SIGHUP", pid ])
def _device_removed(self, device): self.devices = g15devices.find_all_devices() self._check_device_state(device) self.conf_client.notify_remove(self.device_notify_handles[device.uid]) del self.device_notify_handles[device.uid]
def _device_added(self, device): self.devices = g15devices.find_all_devices() self._check_device_state(device) self.device_notify_handles[device.uid] = self.conf_client.notify_add("/apps/gnome15/%s/enabled" % device.uid, self._device_enabled_configuration_changed, device)