[PATCH] Use GDBus also for connection settings update.
Brian C. Lane
bcl at redhat.com
Mon Feb 25 20:37:58 UTC 2013
On Fri, Feb 22, 2013 at 03:04:01PM +0100, Radek Vykydal wrote:
> ---
> pyanaconda/nm.py | 108 ++++++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 71 insertions(+), 37 deletions(-)
> +def _gvariant_settings(settings, key1, key2, value, value_type_str=None):
> +
> + # build copy of GVariant settings as mutable python object
> + new_settings = {}
> + dict1 = settings.get_child_value(0)
> + for key1_idx in range(dict1.n_children()):
> + key_dict2 = dict1.get_child_value(key1_idx)
> + key1_ = key_dict2.get_child_value(0).unpack()
> + new_settings[key1_] = {}
> + dict2 = key_dict2.get_child_value(1)
> + for key2_idx in range(dict2.n_children()):
> + key_val = dict2.get_child_value(key2_idx)
> + key2_ = key_val.get_child_value(0).unpack()
> + val = key_val.get_child_value(1)
> + # get type string of updated value
> + if key1_ == key1 and key2_ == key2:
> + value_type_str = val.get_child_value(0).get_type_string()
> + val = val.get_child_value(0)
> + new_settings[key1_][key2_] = val
These loops are a bit hard to read, maybe add some whitespace? I'd also
recommend changing the loop key values to key1 instead of key1_ and call
the arguments new_key1 and new_key2 to make it more obvious what's
happening.
> +
> + if value_type_str is None:
> + # infer the new value type for string and boolean
> + if type(value) is type(True):
> + value_type_str = 'b'
> + if type(value) is type(''):
> + value_type_str = 's'
> +
> + if value_type_str is not None:
> + if key1 not in new_settings:
> + new_settings[key1] = {}
> + new_settings[key1][key2] = GLib.Variant(value_type_str, value)
You may want to make a note in the docstring(s) that any value_type_str
passed in will be overridden by existing type if found. And maybe rename
it to default_type_str.
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 482 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/anaconda-patches/attachments/20130225/30cde2b5/attachment.sig>
More information about the anaconda-patches
mailing list