Hello community,

here is the log from the commit of package python-killswitch for 
openSUSE:Factory
checked in at Fri Mar 25 14:42:48 CET 2011.



--------
--- python-killswitch/python-killswitch.changes 2010-04-01 00:33:45.000000000 
+0200
+++ /mounts/work_src_done/STABLE/python-killswitch/python-killswitch.changes    
2011-03-11 13:46:16.000000000 +0100
@@ -1,0 +2,11 @@
+Fri Mar 11 13:47:52 CET 2011 - [email protected]
+
+- update to version 0.3: python-killswitch now supports both HAL
+  and/or URfkill as backends
+
+-------------------------------------------------------------------
+Sat Apr 10 00:43:07 CEST 2010 - [email protected]
+
+- bump to version 0.2: Only enumerate static and real killswitches
+
+-------------------------------------------------------------------

calling whatdependson for head-i586


Old:
----
  python-killswitch-0.1.tar.gz

New:
----
  python-killswitch-0.3.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-killswitch.spec ++++++
--- /var/tmp/diff_new_pack.gUhIVx/_old  2011-03-25 14:42:33.000000000 +0100
+++ /var/tmp/diff_new_pack.gUhIVx/_new  2011-03-25 14:42:33.000000000 +0100
@@ -1,7 +1,7 @@
 #
-# spec file for package python-killswitch (Version 0.1)
+# spec file for package python-killswitch
 #
-# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -18,7 +18,7 @@
 
 
 Name:           python-killswitch
-Version:        0.1
+Version:        0.3
 Release:        1
 License:        WTFPL
 Summary:        Python module providing functions for killswitches
@@ -53,4 +53,5 @@
 
 %files -f INSTALLED_FILES
 %defattr(-,root,root)
+
 %changelog

++++++ python-killswitch-0.1.tar.gz -> python-killswitch-0.3.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/python-killswitch-0.1/PKG-INFO 
new/python-killswitch-0.3/PKG-INFO
--- old/python-killswitch-0.1/PKG-INFO  2010-03-30 10:47:34.000000000 +0200
+++ new/python-killswitch-0.3/PKG-INFO  2011-03-11 13:42:38.000000000 +0100
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: python-killswitch
-Version: 0.1
+Version: 0.3
 Summary: Python module providing functions for killswitches
 Home-page: http://blog.homac.de
 Author: Holger Macht
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/python-killswitch-0.1/killswitch.py 
new/python-killswitch-0.3/killswitch.py
--- old/python-killswitch-0.1/killswitch.py     2009-10-07 15:49:04.000000000 
+0200
+++ new/python-killswitch-0.3/killswitch.py     2011-03-11 13:14:35.000000000 
+0100
@@ -1,3 +1,12 @@
+#!/usr/bin/python
+#
+# python-killswitch -- Convenient Functions for Managing Killswitches
+#
+# Copyright (C) 2009,2010,2011 Holger Macht <[email protected]>
+#
+# This file is released under the WTFPL (http://sam.zoy.org/wtfpl/)
+#
+
 """python-killswitch provides a python module called killswitch. It
 provides convenient function/methods for other applications to manage all
 the killswitches found in the system.
@@ -16,202 +25,387 @@
       print "\tName: %s" % ks.name()
       print "\tType: %s" % ks.type()
       print "\tPower: %d" % ks.get_state()
+
+python-killswitch supports both HAL and URfkill as backend.
 """
 
 import dbus
 
-class _Hal():
-    "convenient function for querying the HAL daemon"
-    def __init__(self, bus):
-        "bus: bus object to a properly initializes connection to the D-Bus 
system bus"
-        self.bus = bus
-
-    def _hal_get_property(self, udi, key):
-        manager = self.bus.get_object('org.freedesktop.Hal',
-                                      udi)
-        iface = dbus.Interface(manager,
-                               dbus_interface='org.freedesktop.Hal.Device')
-        if not iface.PropertyExists(key):
-            return False
-        return iface.GetProperty(key)
+_URFKILL_SERVICE="org.freedesktop.URfkill"
+_URFKILL_PATH="/org/freedesktop/URfkill"
 
-    def _hal_has_capability(self, udi, capability):
-        manager = self.bus.get_object('org.freedesktop.Hal',
-                                      udi)
-        iface = dbus.Interface(manager,
-                               dbus_interface='org.freedesktop.Hal.Device')
-        return iface.QueryCapability(capability)
+_HAL_SERVICE="org.freedesktop.Hal"
+_HAL_MANAGER_PATH="/org/freedesktop/Hal/Manager"
+_HAL_DEVICE_SERVICE="org.freedesktop.Hal.Device"
+_HAL_MANAGER_SERVICE="org.freedesktop.Hal.Manager"
+
+def _message(message):
+    print "python-killswich: %s" % message
+
+_dbus_is_set_up = 0
+def _setup_dbus():
+    global _dbus_is_set_up
+
+    if not _dbus_is_set_up:
+        from dbus.mainloop.glib import DBusGMainLoop
 
-    def _hal_get_killswitches(self):
-        manager = self.bus.get_object('org.freedesktop.Hal',
-                                      '/org/freedesktop/Hal/Manager')
+        dbus_loop = DBusGMainLoop()
+        dbus.set_default_main_loop(dbus_loop)
+        _dbus_is_set_up = 1
 
-        iface = dbus.Interface(manager,
-                               dbus_interface='org.freedesktop.Hal.Manager')
+    return dbus.SystemBus()
 
-        return iface.FindDeviceByCapability("killswitch")
+def _have_urfkill():
+    bus = _setup_dbus()
+
+    if bus.name_has_owner(_URFKILL_SERVICE):
+        return 1
+    else:
+        _message("URfkill not running, trying to start it...")
+
+    try:
+        manager = bus.get_object(_URFKILL_SERVICE, _URFKILL_PATH)
+    except dbus.exceptions.DBusException, e:
+        if e.get_dbus_name() == "org.freedesktop.DBus.Error.ServiceUnknown":
+            _message("Service URfkill not available")
+            return 0
+
+    if bus.name_has_owner(_URFKILL_SERVICE):
+        return 1
+
+    return 0
 
-class Killswitch(_Hal):
+def _have_hal():
+    if _setup_dbus().name_has_owner(_HAL_SERVICE):
+        return 1
+    return 0
+
+class Killswitch():
     "class representing one single killswitch object"
-    def __init__(self, bus, udi=None, name=None, type=None):
+    def __init__(self, bus, udi=None, name=None, type=None, is_urfkill=0):
         """Initialize a new Killswitch object. Usually you should not need
         to create objects of this class because the KillswitchManager does
         it.
         bus: a properly initiated object to a D-Bus system bus
-        udi: unique device itendifier (HAL)
-        name: name returned by the HAL killswitch.name property
-        type: type returned by the HAL killswitch.type property (wlan, 
bluetooth, etc.)"""
+        udi: unique device itendifier
+        name: a proper name for the killswitch
+        type: a killswitch type, such as wlan, bluetooth, gps, wwan, etc."""
+
+        if is_urfkill:
+            self.k = _KillswitchUrfkill(bus, udi, name, type)
+        else:
+            self.k = _KillswitchHal(bus, udi, name, type)
+
+    def name(self):
+        "return the name of the killswitch"
+        return self.k.name()
+
+    def udi(self):
+        "return the unique device identifier (udi) of the killswitch object"
+        return self.k.udi()
+
+    def type(self):
+        "return the type of the killswitch object (bluetooth, wlan, etc...)"
+        return self.k.type()
+
+    def get_state(self):
+        """returns the current state of the killswitch object.
+        0: Killswitch is on, device is disabled via software
+        1: Killswitch is off, device operational
+        2: Killswitch is on, device disabled via hardware switch"""
+
+        return self.k.get_state()
+
+    def set_state(self, state):
+        """sets the killswitch state, either to true or to false. true
+        enables the killswitch, thus disables the device"""
 
-        _Hal.__init__(self, bus)
+        return self.k.set_state(state)
 
-        self.bus = bus
+class _KillswitchAbstract():
+    def __init__(self, bus, udi=None, name=None, type=None):
+        self._bus = bus
         self.__name = name
         self.__type = type
         self.__udi = udi
 
-        manager = self.bus.get_object('org.freedesktop.Hal',
-                                      self.__udi)
-        self.manager_interface = dbus.Interface(manager,
-                                                
dbus_interface='org.freedesktop.Hal.Device.KillSwitch')
-
     def name(self):
-        "return the name of the killswitch"
         return self.__name
 
     def udi(self):
-        "return the unique device identifier (udi) of the killswitch object"
         return self.__udi
 
     def type(self):
-        "return the type of the killswitch object (bluetooth, wlan, etc...)"
         return self.__type
 
-    def get_state(self):
-        """returns the current state of the killswitch object.
-        0: Killswitch is on,  device is disabled via software
-        1: Killswitch is off, device operational
-        2: Killswitch is on, device disabled via hardware switch"""
+class _KillswitchHal(_KillswitchAbstract):
+    def __init__(self, bus, udi=None, name=None, type=None):
+        _KillswitchAbstract.__init__(self, bus, udi, name, type)
 
+        manager = self._bus.get_object(_HAL_SERVICE, udi)
+        self.manager_interface = dbus.Interface(manager,
+                                                
dbus_interface='org.freedesktop.Hal.Device.KillSwitch')
+
+    def get_state(self):
         return self.manager_interface.GetPower()
 
     def set_state(self, state):
-        "sets the killswitch state, either to true or to false"
-        return self.manager_interface.SetPower(state)        
+        return self.manager_interface.SetPower(state)
+
+class _KillswitchUrfkill(_KillswitchAbstract):
+    def __init__(self, bus, udi=None, name=None, type=None):
+        _KillswitchAbstract.__init__(self, bus, udi, name, type)
+
+        manager = self._bus.get_object(_URFKILL_SERVICE, _URFKILL_PATH)
+        self.manager_interface = dbus.Interface(manager, 
dbus_interface=_URFKILL_SERVICE)
 
+    def get_state(self):
+        return not self.manager_interface.GetKillswitch(self.udi())[2]
+
+    def set_state(self, state):
+        if state == 1:
+            return self.manager_interface.UnblockIdx(self.udi())
+        elif state == 0:
+            return self.manager_interface.BlockIdx(self.udi())
+        else:
+            _message("Unknown state")
 
-class KillswitchManager(_Hal):
+class KillswitchManager():
     """Base class providing convenient function to keep track of the state
     of all the killswitches in the system"""
+
     def __init__(self):
-        """Initialize the connection to the HAL daemon and update the list
+        if _have_urfkill():
+            _message("Using URfkill")
+            self.k = _KillswitchManagerUrfkill();
+        elif _have_hal():
+            _message("Using HAL")
+            self.k = _KillswitchManagerHal();
+        else:
+            _message("Neither urfkill nor HAL found, bailing out...")
+
+    def set_state_changed_cb(self, cb):
+        """Set the callback function which is called as soon as a
+        killswitch changes its state.  See the get_state() function of the
+        Killswitch class for the exact values"""
+        
+        self.k.set_state_changed_cb(cb)
+
+    def get_killswitches(self):
+        "Returns an array of all killswitches (Killswitch objects) which are 
found"
+        return self.k._switches
+
+    def enable_all(self):
+        "Enable all killswitches at once"
+        for ks in self.k._switches:
+            ks.set_state(1)
+
+    def disable_all(self):
+        "Disable all killswitches at once"
+        for ks in self.k._switches:
+            ks.set_state(0)
+
+    def set_killswitch_added_cb(self, cb):
+        """Set the callback function which is called when a new killswitch
+        is found. A new Killswitch object will be passed to the callback
+        function"""
+        self.k.set_killswitch_added_cb(cb)
+
+    def set_killswitch_removed_cb(self, cb):
+        """Set the callback function which is called when a killswitch
+        vanishes. The Killswitch object which was removed will be passed
+        to the callback function"""
+        self.k.set_killswitch_removed_cb(cb)
+
+class _KillswitchManagerAbstract():
+    def __init__(self):
+        """Initialize the connection to a backend daemon and update the list
         of killswitches found in the system"""
 
-        from dbus.mainloop.glib import DBusGMainLoop
+        self._bus = _setup_dbus()
+        self._switches = []
+        self._state_changed_cb = None
+        self._killswitch_added_cb = None
+        self._killswitch_removed_cb = None
 
-        dbus_loop = DBusGMainLoop()
-        dbus.set_default_main_loop(dbus_loop)
-        self.bus = dbus.SystemBus()
+    def set_state_changed_cb(self, cb):
+        self._state_changed_cb = cb
+
+    def set_killswitch_added_cb(self, cb):
+        self._killswitch_added_cb = cb
+
+    def set_killswitch_removed_cb(self, cb):
+        self._killswitch_removed_cb = cb
+
+class _KillswitchManagerUrfkill(_KillswitchManagerAbstract):
+    def __init__(self):
+        """Initialize the connection to the URfkill daemon and update the list
+        of killswitches found in the system"""
+
+        _KillswitchManagerAbstract.__init__(self)
 
-        _Hal.__init__(self, self.bus)
+        for ks in self.__get_killswitches():
+            ks = Killswitch(self._bus, ks[0], ks[5], 
self.__get_name_for_type(ks[1]), 1); 
+            name = ks.name()
+            _message("found ks with name %s and type %s" % (name, ks.type()))
+            self._switches.append(ks)
+
+        self._bus.add_signal_receiver(self.__killswitch_modified_cb,
+                                      "RfkillChanged",
+                                      _URFKILL_SERVICE, _URFKILL_SERVICE, 
_URFKILL_PATH)
+        self._bus.add_signal_receiver(self.__killswitch_added_cb,
+                                      "RfkillAdded",
+                                      _URFKILL_SERVICE, _URFKILL_SERVICE, 
_URFKILL_PATH)
+        self._bus.add_signal_receiver(self.__killswitch_removed_cb,
+                                      "RfkillRemoved",
+                                      _URFKILL_SERVICE, _URFKILL_SERVICE, 
_URFKILL_PATH)
+
+    def __get_killswitches(self):
+        manager = self._bus.get_object(_URFKILL_SERVICE, _URFKILL_PATH)
+        iface = dbus.Interface(manager, dbus_interface=_URFKILL_SERVICE)
 
-        self.__switches = []
-        self.__state_changed_cb = None
-        self.__killswitch_added_cb = None
-        self.__killswitch_removed_cb = None
+        return iface.GetAll()
+                         
+    def __killswitch_modified_cb(self, index, type, state, soft, hard, name):
+        for item in self._switches:
+            if index == item.udi():
+                state = item.get_state()
+                _message("new state of %s is %s" % (item.udi(), state))
+                self._state_changed_cb(item, state)
 
+    def __killswitch_added_cb(self, index, type, state, soft, hard, name):
+        for item in self._switches:
+            if index == item.udi():
+                _message("killswitch already in list")
+                return
+
+        ks = Killswitch(self._bus, index, name, 
self.__get_name_for_type(type), 1); 
+        name = ks.name()
+        type = ks.type()
+
+        _message("adding %s with name %s and type %s" % (index, name, 
self.__get_name_for_type(type)))
+
+        self._switches.append(ks)
+        self._killswitch_added_cb(ks)
+
+    def __killswitch_removed_cb(self, index):
+        for item in self._switches:
+            if index == item.udi():
+                _message("removing killswitch %s" % item.udi())
+                self._killswitch_removed_cb(item)
+                self._switches.remove(item)
+
+    def __get_name_for_type(self, type):
+            if type == 0:
+                return "type all"
+            elif type == 1:
+                return "wlan"
+            elif type == 2:
+                return "bluetooth"
+            elif type == 3:
+                return "uwb"
+            elif type == 4:
+                return "wimax"
+            elif type == 5:
+                return "wwan"
+            elif type == 6:
+                return "gps"
+            elif type == 7:
+                return "fm"
+            else:
+                return "unknown type"
+
+class _KillswitchManagerHal(_KillswitchManagerAbstract):
+    def __init__(self):
+        """Initialize the connection to the HAL daemon and update the list
+        of killswitches found in the system"""
 
-        for udi in self._hal_get_killswitches():
-            name = self._hal_get_property(udi, "killswitch.name")
+        _KillswitchManagerAbstract.__init__(self)
+
+        for udi in self.__hal_get_killswitches():
+            name = self.__hal_get_property(udi, "killswitch.name")
             if name == False:
-                name = self._hal_get_property(udi, "info.product")
+                name = self.__hal_get_property(udi, "info.product")
                 if name == False:
-                    print "Killswitch has no killswitch.name nor a 
info.product"
+                    _message("Killswitch has no killswitch.name nor a 
info.product")
                     continue
 
-            type = self._hal_get_property(udi, "killswitch.type")
+            type = self.__hal_get_property(udi, "killswitch.type")
 
-            self.__switches.append(Killswitch(self.bus, udi, name, type))
+            self._switches.append(Killswitch(self._bus, udi, name, type, 0))
 
-            self.bus.add_signal_receiver(self.__property_modified_cb,
+            self._bus.add_signal_receiver(self.__property_modified_cb,
                                                "PropertyModified",
-                                               "org.freedesktop.Hal.Device",
-                                               "org.freedesktop.Hal",
+                                               _HAL_DEVICE_SERVICE,
+                                               _HAL_SERVICE,
                                                udi, path_keyword="path")
 
-        self.bus.add_signal_receiver(self.__device_added_cb,
+        self._bus.add_signal_receiver(self.__device_added_cb,
                                            "DeviceAdded",
-                                           "org.freedesktop.Hal.Manager",
-                                           "org.freedesktop.Hal",
-                                           "/org/freedesktop/Hal/Manager")
-        self.bus.add_signal_receiver(self.__device_removed_cb,
+                                           _HAL_MANAGER_SERVICE,
+                                           _HAL_SERVICE,
+                                           _HAL_MANAGER_PATH)
+        self._bus.add_signal_receiver(self.__device_removed_cb,
                                            "DeviceRemoved",
-                                           "org.freedesktop.Hal.Manager",
-                                           "org.freedesktop.Hal",
-                                           "/org/freedesktop/Hal/Manager")
+                                           _HAL_MANAGER_SERVICE,
+                                           _HAL_SERVICE,
+                                           _HAL_MANAGER_PATH)
+
+        _message("name: %s" % self._switches)
                          
     def __property_modified_cb(self, num_changes, change_list, path):
-        for item in self.__switches:
+        for item in self._switches:
             if path == item.udi():
                 state = item.get_state()
-                self.__state_changed_cb(item, state)
+                self._state_changed_cb(item, state)
 
     def __device_added_cb(self, path):
-        if self._hal_has_capability(path, "killswitch"):
-            print "new killswitch %s  " % (path)
-
-            for item in self.__switches:
+        if self.__hal_has_capability(path, "killswitch"):
+            for item in self._switches:
                 if path == item.udi():
-                    print "killswitch already in list"
+                    _message("killswitch already in list")
                     return
             
-            name = self._hal_get_property(path, "killswitch.name")
+            name = self.__hal_get_property(path, "killswitch.name")
             if name == False:
-                name = self._hal_get_property(path, "info.product")
+                name = self.__hal_get_property(path, "info.product")
                 if name == False:
-                    print "Killswitch has no killswitch.name nor a 
info.product"
+                    _message("Killswitch has no killswitch.name nor a 
info.product")
                     return
-            type = self._hal_get_property(path, "killswitch.type")
-            print "adding %s with name %s and type %s" % (path, name, type)
-            ks = Killswitch(path, name, type)
-            self.__switches.append(ks)
-            self.__killswitch_added_cb(ks)
+
+            _message("new killswitch %s  " % (path))
+
+            type = self.__hal_get_property(path, "killswitch.type")
+            _message("adding %s with name %s and type %s" % (path, name, type))
+            ks = Killswitch(self._bus, path, name, type, 0)
+            self._switches.append(ks)
+            self._killswitch_added_cb(ks)
 
     def __device_removed_cb(self, path):
-        for item in self.__switches:
+        for item in self._switches:
             if path == item.udi():
-                print "removing killswitch %s" % item.udi()
-                self.__killswitch_removed_cb(item)
-                self.__switches.remove(item)
+                _message("removing killswitch %s" % item.udi())
+                self._killswitch_removed_cb(item)
+                self._switches.remove(item)
 
-    def get_killswitches(self):
-        "Returns an array of all killswitches (Killswitch objects) which are 
found"
-        return self.__switches
-
-    def set_state_changed_cb(self, cb):
-        """Set the callback function which is called as soon as a
-        killswitch changes its state.  See the get_state() function of the
-        Killswitch class for the exact values"""
-        
-        self.__state_changed_cb = cb
+    def __hal_get_property(self, udi, key):
+        manager = self._bus.get_object(_HAL_SERVICE, udi)
+        iface = dbus.Interface(manager,
+                               dbus_interface=_HAL_DEVICE_SERVICE)
+        if not iface.PropertyExists(key):
+            return False
+        return iface.GetProperty(key)
 
-    def set_killswitch_added_cb(self, cb):
-        """Set the callback function which is called when a new killswitch
-        is found. A new Killswitch object will be passed to the callback
-        function"""
-        self.__killsiwtch_added_cb = cb
+    def __hal_has_capability(self, udi, capability):
+        manager = self._bus.get_object(_HAL_SERVICE, udi)
+        iface = dbus.Interface(manager,
+                               dbus_interface=_HAL_DEVICE_SERVICE)
+        return iface.QueryCapability(capability)
 
-    def set_killswitch_removed_cb(self, cb):
-        """Set the callback function which is called when a killswitch
-        vanishes. The Killswitch object which was removed will be passed
-        to the callback function"""
-        self.__killswitch_removed_cb = cb
+    def __hal_get_killswitches(self):
+        manager = self._bus.get_object(_HAL_SERVICE, _HAL_MANAGER_PATH)
 
-    def enable_all(self):
-        "Enable all killswitches at once"
-        for ks in self.__switches:
-            ks.set_state(1)
+        iface = dbus.Interface(manager,
+                               dbus_interface=_HAL_MANAGER_SERVICE)
 
-    def disable_all(self):
-        "Disable all killswitches at once"
-        for ks in self.__switches:
-            ks.set_state(0)
+        return iface.FindDeviceByCapability("killswitch")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/python-killswitch-0.1/setup.py 
new/python-killswitch-0.3/setup.py
--- old/python-killswitch-0.1/setup.py  2010-03-30 10:47:29.000000000 +0200
+++ new/python-killswitch-0.3/setup.py  2011-03-10 13:36:47.000000000 +0100
@@ -2,7 +2,7 @@
 
 from distutils.core import setup
 
-PYTHON_KILLSWITCH_VERSION='0.1'
+PYTHON_KILLSWITCH_VERSION='0.3'
 
 dist = setup(name='python-killswitch',
     version=PYTHON_KILLSWITCH_VERSION,


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



Remember to have fun...

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to