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
>From cecd8cf8b20fd5fb6cd55df72042857003f59306 Mon Sep 17 00:00:00 2001
From: Morgan LEFIEUX <[email protected]>
Date: Tue, 15 Feb 2011 22:38:44 +0100
Subject: [PATCH] Add a test for the OS to handle BSD sed version 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..b40b256 100644
--- a/fabric/contrib/files.py
+++ b/fabric/contrib/files.py
@@ -7,6 +7,7 @@ from __future__ import with_statement
import tempfile
import re
import os
+import platform
from fabric.api import *
@@ -130,7 +131,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 +141,13 @@ 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 sed doesn't have '-i' option on some systems
+ if platform.system() == 'NetBSD' or '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