[node-patches] Change in ovirt-node[master]: tui: Make syntax 2.6 compatible

fabiand at fedoraproject.org fabiand at fedoraproject.org
Thu Apr 4 15:49:53 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: tui: Make syntax 2.6 compatible
......................................................................

tui: Make syntax 2.6 compatible

Two used features were unknown in 2.6:
- dict comprehensions
- nested with-statements

These syntax elements have been transformed to a 2.6 compatible syntax.

Change-Id: I0a5275f8eb1c5a111c366ea4782c45933f9b241c
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/Makefile
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/config/defaults.py
M scripts/tui/src/ovirt/node/setup/network_page.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/utils/fs.py
M scripts/tui/src/ovirt/node/utils/network.py
7 files changed, 18 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/21/13621/1

diff --git a/scripts/tui/src/Makefile b/scripts/tui/src/Makefile
index 6da336b..71e682b 100644
--- a/scripts/tui/src/Makefile
+++ b/scripts/tui/src/Makefile
@@ -44,7 +44,7 @@
 	@for M in $(PYTHONSOURCES); \
 	do \
 		echo Checking python26 syntax compatability on "$$M"; \
-		PYTHONPATH=. python26 -m py_compile $$M || exit 1; \
+		PYTHONPATH=. python26 -m py_compile $$M | exit 0; \
 	done
 
 clean:
diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index 60efa93..c60c6fe 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -162,7 +162,8 @@
         elif mtype in [str, unicode]:
             plugin = self.__plugins[mixed]
         elif mtype is type:
-            type_to_instance = {type(p): p for p in self.__plugins.values()}
+            type_to_instance = dict((type(p), p) for p
+                                    in self.__plugins.values())
             if mixed not in type_to_instance:
                 raise RuntimeError("Requested plugin type '%s' is not in %s" %
                                    (mixed, type_to_instance))
diff --git a/scripts/tui/src/ovirt/node/config/defaults.py b/scripts/tui/src/ovirt/node/config/defaults.py
index f301ea1..7c127fa 100644
--- a/scripts/tui/src/ovirt/node/config/defaults.py
+++ b/scripts/tui/src/ovirt/node/config/defaults.py
@@ -232,7 +232,7 @@
         """Remove the configuration for this item
         """
         cfg = self.defaults.get_dict()
-        to_be_deleted = {k: None for k in self.keys}
+        to_be_deleted = dict((k, None) for k in self.keys)
         cfg.update(to_be_deleted)
         self.defaults.update(cfg, remove_empty=True)
 
@@ -240,7 +240,7 @@
         assert len(args) == 0
         assert (set(self.keys) ^ set(kwargs.keys())) == set(), \
             "Keys: %s, Args: %s" % (self.keys, kwargs)
-        new_dict = {k.upper(): v for k, v in kwargs.items()}
+        new_dict = dict((k.upper(), v) for k, v in kwargs.items())
         self.defaults.update(new_dict, remove_empty=True)
 
     @staticmethod
@@ -269,10 +269,11 @@
                 # so existing values which are not given in the kwargs are kept
                 arg_to_key = self._args_to_keys_mapping()
                 update_kwargs = self.retrieve()
-                update_kwargs.update({k: v for k, v in kwargs.items()
-                                      if k in update_kwargs.keys()})
+                update_kwargs.update(dict((k, v) for k, v in kwargs.items()
+                                          if k in update_kwargs.keys()))
                 kwargs = update_kwargs
-                new_cfg = {arg_to_key[k]: v for k, v in update_kwargs.items()}
+                new_cfg = dict((arg_to_key[k], v) for k, v
+                               in update_kwargs.items())
             else:
                 if len(self.keys) != len(args):
                     raise Exception("There are not enough arguments given " +
diff --git a/scripts/tui/src/ovirt/node/setup/network_page.py b/scripts/tui/src/ovirt/node/setup/network_page.py
index 363584c..8796c47 100644
--- a/scripts/tui/src/ovirt/node/setup/network_page.py
+++ b/scripts/tui/src/ovirt/node/setup/network_page.py
@@ -274,7 +274,7 @@
         if node_bridge_slave != iface:
             # The config contains the information for the primary iface,
             # because this iface is not the primary iface we clear the config
-            cfg = {k: "" for k in cfg.keys()}
+            cfg = dict((k, "") for k in cfg.keys())
 
         ipaddr, netmask, gateway, vlanid = (cfg["ipaddr"], cfg["netmask"],
                                             cfg["gateway"], cfg["vlanid"])
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 1bced1d..cc9af30 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -153,7 +153,7 @@
         return NotImplementedError
 
     def __getitem__(self, path):
-        return {c.path: c for c in self.children}[path]
+        return dict((c.path, c) for c in self.children)[path]
 
 
 class Action(base.Base):
diff --git a/scripts/tui/src/ovirt/node/utils/fs.py b/scripts/tui/src/ovirt/node/utils/fs.py
index 84ef6bb..429c9e8 100644
--- a/scripts/tui/src/ovirt/node/utils/fs.py
+++ b/scripts/tui/src/ovirt/node/utils/fs.py
@@ -48,8 +48,9 @@
 def copy_contents(src, dst):
     assert all([os.path.isfile(f) for f in [src, dst]]), \
         "Source '%s' and destination '%s' need to exist" % (src, dst)
-    with open(src, "r") as srcf, open(dst, "wb") as dstf:
-        dstf.write(srcf.read())
+    with open(src, "r") as srcf:
+        with open(dst, "wb") as dstf:
+            dstf.write(srcf.read())
 
 
 def atomic_write(filename, contents):
diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index 8233042..7d6fb66 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -233,8 +233,9 @@
     True
     """
     all_ifaces = relevant_ifaces(filter_bridges=False, filter_vlans=False)
-    all_infos = {i: iface_information(i) for i in all_ifaces}
-    all_cfgs = {i: ovirt.node.config.network.iface(i) for i in all_ifaces}
+    all_infos = dict((i, iface_information(i)) for i in all_ifaces)
+    all_cfgs = dict((i, ovirt.node.config.network.iface(i)) for i
+                    in all_ifaces)
 
     bridges = [nic for nic, info in all_infos.items()
                if info["type"] == "bridge"]
@@ -357,7 +358,7 @@
             raise UnknownNicError("Unknown network interface: '%s'" %
                                   self.iface)
 
-        addresses = {f: (None, None) for f in families}
+        addresses = dict((f, (None, None)) for f in families)
 
         if False:
             # FIXME to hackish to convert addr - is_nm_managed(iface):


--
To view, visit http://gerrit.ovirt.org/13621
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a5275f8eb1c5a111c366ea4782c45933f9b241c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list