[node-patches] Change in ovirt-node[master]: fs: Improve File.sed

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Apr 23 15:11:16 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: fs: Improve File.sed
......................................................................

fs: Improve File.sed

Change-Id: I9d2e4abbb1bdc0f1542dc4562f232790cf2a2400
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/utils/fs.py
1 file changed, 13 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/19/27019/1

diff --git a/src/ovirt/node/utils/fs.py b/src/ovirt/node/utils/fs.py
index 48d1bab..99f173b 100644
--- a/src/ovirt/node/utils/fs.py
+++ b/src/ovirt/node/utils/fs.py
@@ -127,12 +127,22 @@
 
     def sed(self, expr, inplace=True):
         """Run a sed expression on the file
+
+        >>> f = File("/tmp/afile")
+        >>> f.write("Woot")
+        >>> f.sed("s/oo/ha/", False)
+        u'What'
+        >>> f.sed("s/oo/alle/")
+        >>> f.read()
+        'Wallet'
+        >>> f.delete()
         """
-        cmd = ["sed", "-c"]
+        cmd = ["sed"]
         if inplace:
-            cmd.append("-i")
+            cmd.append("-ci")
         cmd += ["-e", expr, self.filename]
-        return process.pipe(cmd)
+        stdout = process.check_output(cmd)
+        return None if inplace else stdout
 
     def sub(self, pat, repl, count=0, inplace=True):
         """Run a regexp subs. on each lien of the file


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

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