Skip to content
Browse files

Merge branch '863-int' into 1.6

Conflicts:
	docs/changelog.rst
  • Loading branch information...
2 parents bbf131d + 77e0d85 commit 3f75202614d0d22b6017f160b6d014ec04aae627 @bitprophet bitprophet committed Mar 19, 2013
Showing with 11 additions and 6 deletions.
  1. +1 −0 docs/changelog.rst
  2. +10 −6 fabric/contrib/files.py
View
1 docs/changelog.rst
@@ -25,6 +25,7 @@ would have also been included in the 1.2 line.
Changelog
=========
+* :bug:`84` Fixed problem with missing -r flag in Mac OS X sed version.
* :bug:`861` Gracefully handle situations where users give a single string
literal to ``env.hosts``. Thanks to Bill Tucker for catch & patch.
* :bug:`367` Expand paths with tilde inside (``contrib.files``).
View
16 fabric/contrib/files.py
@@ -168,6 +168,11 @@ def sed(filename, before, after, limit='', use_sudo=False, backup='.bak',
after = after.replace(char, r'\%s' % char)
if limit:
limit = r'/%s/ ' % limit
+ context = {
+ 'script': r"'%ss/%s/%s/%sg'" % (limit, before, after, flags),
+ 'filename': _expand_path(filename),
+ 'backup': backup
+ }
# Test the OS because of differences between sed versions
with hide('running', 'stdout'):
@@ -177,17 +182,16 @@ def sed(filename, before, after, limit='', use_sudo=False, backup='.bak',
hasher = hashlib.sha1()
hasher.update(env.host_string)
hasher.update(filename)
- tmp = "/tmp/%s" % hasher.hexdigest()
- filename = _expand_path(filename)
+ context['tmp'] = "/tmp/%s" % hasher.hexdigest()
# Use temp file to work around lack of -i
expr = r"""cp -p %(filename)s %(tmp)s \
-&& sed -r -e '%(limit)ss/%(before)s/%(after)s/%(flags)sg' %(filename)s > %(tmp)s \
+&& sed -r -e %(script)s %(filename)s > %(tmp)s \
&& cp -p %(filename)s %(filename)s%(backup)s \
&& mv %(tmp)s %(filename)s"""
- command = expr % locals()
else:
- expr = r"sed -i%s -r -e '%ss/%s/%s/%sg' %s"
- command = expr % (backup, limit, before, after, flags, _expand_path(filename))
+ context['extended_regex'] = '-E' if platform == 'Darwin' else '-r'
+ expr = r"sed -i%(backup)s %(extended_regex)s -e %(script)s %(filename)s"
+ command = expr % context
return func(command, shell=shell)

0 comments on commit 3f75202

Please sign in to comment.
Something went wrong with that request. Please try again.