[master] [PATCH] Rewrite isWirelessDevice to Python and DBus calls (#862801)

Radek Vykydal rvykydal at redhat.com
Thu Oct 11 16:37:09 UTC 2012


Looks good to me, I can't think of any case where we would
want to use the C version of the function from isys.

On 10/11/2012 05:29 AM, Vratislav Podzimek wrote:
> Using libnm-glib from a separate thread results in a hang, probably
> because libnm-glib has to do some "loops magic" for its internal use
> of DBus.
>
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>   pyanaconda/isys/__init__.py | 19 +++++++++++++++++--
>   pyanaconda/isys/iface.c     | 33 ---------------------------------
>   pyanaconda/isys/iface.h     |  5 -----
>   pyanaconda/isys/isys.c      | 16 ----------------
>   4 files changed, 17 insertions(+), 56 deletions(-)
>
> diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
> index 8195f0d..ca72438 100755
> --- a/pyanaconda/isys/__init__.py
> +++ b/pyanaconda/isys/__init__.py
> @@ -66,6 +66,7 @@ NM_STATE_CONNECTED_LOCAL = 50
>   NM_STATE_CONNECTED_SITE = 60
>   NM_STATE_CONNECTED_GLOBAL = 70
>   NM_DEVICE_STATE_ACTIVATED = 100
> +NM_DEVICE_TYPE_WIFI = 2
>   
>   DBUS_PROPS_IFACE = "org.freedesktop.DBus.Properties"
>   
> @@ -362,8 +363,22 @@ def getNetDevDesc(dev):
>       return desc
>   
>   # Determine if a network device is a wireless device.
> -def isWirelessDevice(dev):
> -    return _isys.isWirelessDevice(dev)
> +def isWirelessDevice(dev_name):
> +    bus = dbus.SystemBus()
> +    nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH)
> +    devlist = nm.get_dbus_method("GetDevices")()
> +
> +    for path in devlist:
> +        device = bus.get_object(NM_SERVICE, path)
> +        device_props_iface = dbus.Interface(device, DBUS_PROPS_IFACE)
> +
> +        iface = device_props_iface.Get(NM_DEVICE_IFACE, "Interface")
> +        if iface == dev_name:
> +            device_type = device_props_iface.Get(NM_DEVICE_IFACE, "DeviceType")
> +            return device_type == NM_DEVICE_TYPE_WIFI
> +
> +    return False
> +
>   
>   # Get IP addresses for a network device.
>   # Returns list of ipv4 or ipv6 addresses, depending
> diff --git a/pyanaconda/isys/iface.c b/pyanaconda/isys/iface.c
> index 7d11600..af64264 100644
> --- a/pyanaconda/isys/iface.c
> +++ b/pyanaconda/isys/iface.c
> @@ -620,36 +620,3 @@ ifacemtu_error1:
>       return ret;
>   }
>   
> -/*
> - * Checks if interface is wireless
> - */
> -int is_wireless_device(char *ifname){
> -    NMClient *client = NULL;
> -    NMDevice *candidate = NULL;
> -    const GPtrArray *devices;
> -    const char *iface;
> -    int i;
> -
> -    g_type_init();
> -
> -    client = nm_client_new();
> -    if (!client) {
> -        return 0;
> -    }
> -
> -    devices = nm_client_get_devices(client);
> -    for (i = 0; devices && (i < devices->len); i++) {
> -        candidate = g_ptr_array_index(devices, i);
> -        if (NM_IS_DEVICE_WIFI (candidate)) {
> -            iface = nm_device_get_iface(candidate);
> -            if (!strcmp(ifname, iface)) {
> -                g_object_unref(client);
> -                return 1;
> -            }
> -        }
> -
> -    }
> -    g_object_unref(client);
> -    return 0;
> -}
> -
> diff --git a/pyanaconda/isys/iface.h b/pyanaconda/isys/iface.h
> index b249394..c4167b0 100644
> --- a/pyanaconda/isys/iface.h
> +++ b/pyanaconda/isys/iface.h
> @@ -171,11 +171,6 @@ int iface_restart_NetworkManager(void);
>   int iface_set_interface_mtu(char *ifname, int mtu);
>   
>   /*
> - * Checks if interface is wireless
> - */
> -int is_wireless_device(char *ifname);
> -
> -/*
>    * Checks if the state means nm is connected
>    */
>   int is_connected_state(NMState state);
> diff --git a/pyanaconda/isys/isys.c b/pyanaconda/isys/isys.c
> index e6c56de..ba2d324 100644
> --- a/pyanaconda/isys/isys.c
> +++ b/pyanaconda/isys/isys.c
> @@ -109,7 +109,6 @@ static PyObject * doIsCapsLockEnabled(PyObject * s, PyObject * args);
>   static PyObject * doGetLinkStatus(PyObject * s, PyObject * args);
>   static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args);
>   static PyObject * doInitLog(PyObject * s);
> -static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args);
>   static PyObject * doTotalMemory(PyObject * s);
>   
>   static PyMethodDef isysModuleMethods[] = {
> @@ -138,7 +137,6 @@ static PyMethodDef isysModuleMethods[] = {
>       { "getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, NULL },
>       { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS, NULL },
>       { "initLog", (PyCFunction) doInitLog, METH_VARARGS, NULL },
> -    { "isWirelessDevice", (PyCFunction) doIsWirelessDevice, METH_VARARGS, NULL },
>       { "total_memory", (PyCFunction) doTotalMemory, METH_NOARGS, NULL },
>       { NULL, NULL, 0, NULL }
>   } ;
> @@ -606,20 +604,6 @@ static PyObject * doInitLog(PyObject * s) {
>       return Py_None;
>   }
>   
> -static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args) {
> -    char *dev = NULL;
> -
> -    if (!PyArg_ParseTuple(args, "s", &dev)) {
> -        return NULL;
> -    }
> -
> -    if (is_wireless_device(dev) == 1) {
> -        return PyBool_FromLong(1);
> -    }
> -
> -    return PyBool_FromLong(0);
> -}
> -
>   static PyObject * doTotalMemory(PyObject * s) {
>       unsigned long long tm = totalMemory();
>       return PyLong_FromUnsignedLongLong(tm);



More information about the anaconda-patches mailing list