Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds flag use_glob to put, to allow raw file paths re: #812

  • Loading branch information...
commit 6cd3fc2c4c428e33f8a3c40083cb39723d87f08c 1 parent 2d13a1c
@mmchugh mmchugh authored
Showing with 41 additions and 3 deletions.
  1. +13 −3 fabric/operations.py
  2. +28 −0 tests/test_operations.py
View
16 fabric/operations.py
@@ -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=None):
"""
Upload one or more files to a remote host.
@@ -295,6 +295,9 @@ def put(local_path=None, remote_path=None, use_sudo=False,
Alternately, you may use the ``mode`` kwarg to specify an exact mode, in
the same vein as ``os.chmod`` or the Unix ``chmod`` command.
+ In the case that a file contains glob characters (ie ``~/foo[bar].txt``),
+ specify ``use_glob=False`` and put will not attempt to glob the local path.
+
`~fabric.operations.put` will honor `~fabric.context_managers.cd`, so
relative values in ``remote_path`` will be prepended by the current remote
working directory, if applicable. Thus, for example, the below snippet
@@ -362,8 +365,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 or (use_glob is None and env.get('use_glob', True)):
+ # 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
28 tests/test_operations.py
@@ -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()
#
Please sign in to comment.
Something went wrong with that request. Please try again.