[node-patches] Change in ovirt-node[node-3.0]: utils: Fix File.sub()

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Feb 19 14:15:48 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: utils: Fix File.sub()
......................................................................

utils: Fix File.sub()

There are mutliline differences between python 2.6 and 2.7. To have the
same behavior, the sub() is now executed on each line - not on the whole
contents.

Change-Id: Icce28f96c4af490dc5ade9b09699e753c9d898dd
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=960833
Signed-off-by: Fabian Deutsch <fabiand at redhat.com>
---
M src/ovirt/node/utils/fs.py
M src/ovirt/node/utils/storage.py
2 files changed, 14 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/78/24778/1

diff --git a/src/ovirt/node/utils/fs.py b/src/ovirt/node/utils/fs.py
index a3955a6..2064a8f 100644
--- a/src/ovirt/node/utils/fs.py
+++ b/src/ovirt/node/utils/fs.py
@@ -135,23 +135,27 @@
         return process.pipe(cmd)
 
     def sub(self, pat, repl, count=0, inplace=True):
-        """Run a regexp subs. on the file contents
+        """Run a regexp subs. on each lien of the file
+
         Args:
             inplace: If the contents shall be directly replaced
         Returns:
             The new value
         """
-        # flags |= re.MULTILINE  # py2.7+
-        newval = re.sub(pat, repl, self.read(), count)
+        newval = ""
+        for line in self:
+            newval += re.sub(pat, repl, line, count)
         if inplace:
             self.write(newval)
         return newval
 
     def findall(self, pat, flags=0):
-        """Find all regexps in the contents
+        """Find all regexps in all lines of the file
         """
-        flags |= re.MULTILINE
-        return re.findall(pat, self.read(), flags)
+        matches = []
+        for line in self:
+            matches += re.findall(pat, line, flags)
+        return matches
 
     def __iter__(self):
         with open(self.filename, "r") as src:
diff --git a/src/ovirt/node/utils/storage.py b/src/ovirt/node/utils/storage.py
index 07e5700..da98012 100644
--- a/src/ovirt/node/utils/storage.py
+++ b/src/ovirt/node/utils/storage.py
@@ -41,7 +41,11 @@
 class NFSv4(base.Base):
     """A class to deal some external NFSv4 related functionality
 
+    >>> import shutil
+    >>> tmpcfg = "/tmp/idmapd.conf"
+    >>> shutil.copy(NFSv4.configfilename, tmpcfg)
     >>> n = NFSv4()
+    >>> n.configfilename = tmpcfg
     >>> n.domain("")
     >>> n.domain()
     >>> n.domain("abc")


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

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



More information about the node-patches mailing list