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

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Feb 19 14:14:04 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, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/58/24758/1

diff --git a/src/ovirt/node/utils/fs.py b/src/ovirt/node/utils/fs.py
index 2043463..33b40f7 100644
--- a/src/ovirt/node/utils/fs.py
+++ b/src/ovirt/node/utils/fs.py
@@ -123,6 +123,38 @@
         """
         return os.access(self.filename, mode)
 
+    def sed(self, expr, inplace=True):
+        """Run a sed expression on the file
+        """
+        cmd = ["sed", "-c"]
+        if inplace:
+            cmd.append("-i")
+        cmd += ["-e", expr, self.filename]
+        return process.pipe(cmd)
+
+    def sub(self, pat, repl, count=0, inplace=True):
+        """Run a regexp subs. on each lien of the file
+
+        Args:
+            inplace: If the contents shall be directly replaced
+        Returns:
+            The new value
+        """
+        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 all lines of the file
+        """
+        matches = []
+        for line in self:
+            matches += re.findall(pat, line, flags)
+        return matches
+
     def __iter__(self):
         with open(self.filename, "r") as src:
             for line in 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/24758
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icce28f96c4af490dc5ade9b09699e753c9d898dd
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