Permalink
Browse files

Merge branch '869-int'

  • Loading branch information...
2 parents e2fad30 + 413234a commit e28e621fdc06fbe00a599dca336b43645c29b60f @bitprophet bitprophet committed Apr 2, 2013
Showing with 45 additions and 5 deletions.
  1. +3 −0 docs/changelog.rst
  2. +14 −5 fabric/operations.py
  3. +28 −0 tests/test_operations.py
View
@@ -25,6 +25,9 @@ would have also been included in the 1.2 line.
Changelog
=========
+* :feature:`812` Add ``use_glob`` option to `.put` so users trying to upload
+ real filenames containing glob patterns (``*``, ``[`` etc) can disable the
+ default globbing behavior. Thanks to Michael McHugh for the patch.
* :bug:`844` Allow users to disable Fabric's auto-escaping in `.run`/`.sudo`.
Thanks to Christian Long and Michael McHugh for the patch.
* :bug:`84` Fixed problem with missing -r flag in Mac OS X sed version.
View
@@ -251,7 +251,7 @@ def prompt(text, key=None, default='', validate=None):
@needs_host
def put(local_path=None, remote_path=None, use_sudo=False,
- mirror_local_mode=False, mode=None):
+ mirror_local_mode=False, mode=None, use_glob=True):
"""
Upload one or more files to a remote host.
@@ -263,8 +263,8 @@ def put(local_path=None, remote_path=None, use_sudo=False,
``local_path`` may be a relative or absolute local file or directory path,
and may contain shell-style wildcards, as understood by the Python ``glob``
- module. Tilde expansion (as implemented by ``os.path.expanduser``) is also
- performed.
+ module (give ``use_glob=False`` to disable this behavior). Tilde expansion
+ (as implemented by ``os.path.expanduser``) is also performed.
``local_path`` may alternately be a file-like object, such as the result of
``open('path')`` or a ``StringIO`` instance.
@@ -331,6 +331,8 @@ def put(local_path=None, remote_path=None, use_sudo=False,
also exhibits the ``.failed`` and ``.succeeded`` attributes.
.. versionchanged:: 1.5
Allow a ``name`` attribute on file-like objects for log output
+ .. versionchanged:: 1.7
+ Added ``use_glob`` option to allow disabling of globbing.
"""
# Handle empty local path
local_path = local_path or os.getcwd()
@@ -362,8 +364,15 @@ def put(local_path=None, remote_path=None, use_sudo=False,
if not os.path.isabs(local_path) and env.lcwd:
local_path = os.path.join(env.lcwd, local_path)
- # Glob local path
- names = glob(local_path)
+ if use_glob:
+ # Glob local path
+ names = glob(local_path)
+ else:
+ # Check if file exists first so ValueError gets raised
+ if os.path.exists(local_path):
+ names = [local_path]
+ else:
+ names = []
else:
names = [local_path]
View
@@ -837,6 +837,34 @@ def test_put_return_value_failed_attribute(self):
eq_(["<StringIO>"], retval.failed)
assert not retval.succeeded
+ @server()
+ def test_put_sends_all_files_with_glob(self):
+ """
+ put() should send all items that match a glob.
+ """
+ paths = ['foo1.txt', 'foo2.txt']
+ glob = 'foo*.txt'
+ remote_directory = '/'
+ for path in paths:
+ self.mkfile(path, 'foo!')
+
+ with hide('everything'):
+ retval = put(self.path(glob), remote_directory)
+ eq_(sorted(retval), sorted([remote_directory + path for path in paths]))
+
+ @server()
+ def test_put_sends_correct_file_with_globbing_off(self):
+ """
+ put() should send a file with a glob pattern in the path, when globbing disabled.
+ """
+ text = "globbed!"
+ local = self.mkfile('foo[bar].txt', text)
+ local2 = self.path('foo2.txt')
+ with hide('everything'):
+ put(local, '/', use_glob=False)
+ get('/foo[bar].txt', local2)
+ eq_contents(local2, text)
+
#
# Interactions with cd()
#

0 comments on commit e28e621

Please sign in to comment.