Skip to content
This repository

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

Merged
merged 1 commit into from about 1 year ago

3 participants

Michael McHugh Chris2048 Jeff Forcier
Michael McHugh

Also added a test for put and globs (foo1.txt + foo2.txt both get put with foo*.txt) since I didn't see one, in addition to the disabling glob test

Re #812

Jeff Forcier bitprophet referenced this pull request from a commit April 01, 2013
Jeff Forcier Remove env var checking behavior for use_glob.
There was no env var and I actually don't think it makes
sense for this to be globally true/false.

Re #869, #812
413234a
Jeff Forcier bitprophet merged commit 6cd3fc2 into from April 01, 2013
Jeff Forcier bitprophet closed this April 01, 2013
Chris2048

The docs say 'Changed in 1.7', is this right? Because those are the 1.6 docs.

Jeff Forcier
Owner

@Chris2048 It's in the master branch which will become 1.7 :)

Chris2048

Thanks :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 21, 2013
Michael McHugh adds flag use_glob to put, to allow raw file paths re: #812 6cd3fc2
This page is out of date. Refresh to see the latest.
16  fabric/operations.py
@@ -251,7 +251,7 @@ def prompt(text, key=None, default='', validate=None):
251 251
 
252 252
 @needs_host
253 253
 def put(local_path=None, remote_path=None, use_sudo=False,
254  
-    mirror_local_mode=False, mode=None):
  254
+    mirror_local_mode=False, mode=None, use_glob=None):
255 255
     """
256 256
     Upload one or more files to a remote host.
257 257
 
@@ -295,6 +295,9 @@ def put(local_path=None, remote_path=None, use_sudo=False,
295 295
     Alternately, you may use the ``mode`` kwarg to specify an exact mode, in
296 296
     the same vein as ``os.chmod`` or the Unix ``chmod`` command.
297 297
 
  298
+    In the case that a file contains glob characters (ie ``~/foo[bar].txt``),
  299
+    specify ``use_glob=False`` and put will not attempt to glob the local path.
  300
+
298 301
     `~fabric.operations.put` will honor `~fabric.context_managers.cd`, so
299 302
     relative values in ``remote_path`` will be prepended by the current remote
300 303
     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,
362 365
             if not os.path.isabs(local_path) and env.lcwd:
363 366
                 local_path = os.path.join(env.lcwd, local_path)
364 367
 
365  
-            # Glob local path
366  
-            names = glob(local_path)
  368
+            if use_glob or (use_glob is None and env.get('use_glob', True)):
  369
+                # Glob local path
  370
+                names = glob(local_path)
  371
+            else:
  372
+                # Check if file exists first so ValueError gets raised
  373
+                if os.path.exists(local_path):
  374
+                    names = [local_path]
  375
+                else:
  376
+                    names = []
367 377
         else:
368 378
             names = [local_path]
369 379
 
28  tests/test_operations.py
@@ -837,6 +837,34 @@ def test_put_return_value_failed_attribute(self):
837 837
         eq_(["<StringIO>"], retval.failed)
838 838
         assert not retval.succeeded
839 839
 
  840
+    @server()
  841
+    def test_put_sends_all_files_with_glob(self):
  842
+        """
  843
+        put() should send all items that match a glob.
  844
+        """
  845
+        paths = ['foo1.txt', 'foo2.txt']
  846
+        glob = 'foo*.txt'
  847
+        remote_directory = '/'
  848
+        for path in paths:
  849
+            self.mkfile(path, 'foo!')
  850
+
  851
+        with hide('everything'):
  852
+            retval = put(self.path(glob), remote_directory)
  853
+        eq_(sorted(retval), sorted([remote_directory + path for path in paths]))
  854
+
  855
+    @server()
  856
+    def test_put_sends_correct_file_with_globbing_off(self):
  857
+        """
  858
+        put() should send a file with a glob pattern in the path, when globbing disabled.
  859
+        """
  860
+        text = "globbed!"
  861
+        local = self.mkfile('foo[bar].txt', text)
  862
+        local2 = self.path('foo2.txt')
  863
+        with hide('everything'):
  864
+            put(local, '/', use_glob=False)
  865
+            get('/foo[bar].txt', local2)
  866
+        eq_contents(local2, text)
  867
+
840 868
     #
841 869
     # Interactions with cd()
842 870
     #
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.