This is a fixed release of the patch, sorry for the mistake.

Any comment is welcome.

Le 15/02/2011 23:47, Travis Swicegood a écrit :
FWIW: sed on BSD (at least a Darwin) does support inline editing via -i,
but I think the syntax is slightly different.

I'm also not familiar with platform.system() -- is it going to be aware
of the other OS?  I routinely execute code on Ubuntu from my Mac.
  Wouldn't this code use the BSD syntax rather than the remote system's
syntax?

-T


On Tue, Feb 15, 2011 at 3:59 PM, Morgan LEFIEUX <[email protected]
<mailto:[email protected]>> wrote:

    Hello,

    I've made a little modification of the 'files.py' code to handle
    correctly sed versions without '-i' option like on NetBSD and OpenBSD.

    thanks !

    Bye

    _______________________________________________
    Fab-user mailing list
    [email protected] <mailto:[email protected]>
    http://lists.nongnu.org/mailman/listinfo/fab-user


>From fe94ab9c0d561d7c5a7395a87051601532a7e0b8 Mon Sep 17 00:00:00 2001
From: Morgan LEFIEUX <[email protected]>
Date: Wed, 16 Feb 2011 00:40:06 +0100
Subject: [PATCH] Test the remote OS to handle some BSD sed versions without '-i' option

---
 fabric/contrib/files.py |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fabric/contrib/files.py b/fabric/contrib/files.py
index 6662722..66f07ba 100644
--- a/fabric/contrib/files.py
+++ b/fabric/contrib/files.py
@@ -130,7 +130,6 @@ def sed(filename, before, after, limit='', use_sudo=False, backup='.bak'):
     with many nested levels of quotes and backslashes.
     """
     func = use_sudo and sudo or run
-    expr = r"sed -i%s -r -e '%ss/%s/%s/g' %s"
     # Characters to be escaped in both
     for char in "/'":
         before = before.replace(char, r'\%s' % char)
@@ -141,7 +140,14 @@ def sed(filename, before, after, limit='', use_sudo=False, backup='.bak'):
         after = after.replace(char, r'\%s' % char)
     if limit:
         limit = r'/%s/ ' % limit
-    command = expr % (backup, limit, before, after, filename)
+    # Test the OS because of differences between sed versions
+    platform = run("uname") 
+    if platform == 'NetBSD' or platform == 'OpenBSD':
+        expr = r"sed -r -e '%ss/%s/%s/g' %s > /tmp/newfile.tmp && cp %s %s%s && mv /tmp/newfile.tmp %s"
+        command = expr % (limit, before, after, filename, filename, filename, backup, filename)
+    else:
+        expr = r"sed -i%s -r -e '%ss/%s/%s/g' %s"
+        command = expr % (backup, limit, before, after, filename)
     return func(command, shell=False)
 
 
-- 
1.7.4.1

_______________________________________________
Fab-user mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to