Skip to content
This repository
Browse code

download() can have a dir specified instead of a file

  • Loading branch information...
commit 2f2c299d6b21068830220d60df396cd1fddd4d71 1 parent 572fd29
Daniele Varrazzo authored August 30, 2012
9  pgxnclient/commands/install.py
@@ -20,7 +20,7 @@
20 20
 from pgxnclient.i18n import _, N_
21 21
 from pgxnclient.utils import sha1, b
22 22
 from pgxnclient.errors import BadChecksum, PgxnClientException, InsufficientPrivileges
23  
-from pgxnclient.network import download, get_local_file_name
  23
+from pgxnclient.network import download
24 24
 from pgxnclient.commands import Command, WithDatabase, WithMake, WithPgConfig
25 25
 from pgxnclient.commands import WithSpec, WithSpecLocal, WithSudo
26 26
 from pgxnclient.utils.zip import unpack
@@ -54,8 +54,8 @@ def run(self):
54 54
                 "sha1 missing from the distribution meta")
55 55
 
56 56
         with self.api.download(data['name'], SemVer(data['version'])) as fin:
57  
-            fn = self._get_local_file_name(fin.url)
58  
-            fn = download(fin, fn, rename=True)
  57
+            fn = download(fin, self.opts.target)
  58
+
59 59
         self.verify_checksum(fn, chk)
60 60
         return fn
61 61
 
@@ -79,9 +79,6 @@ def verify_checksum(self, fn, chk):
79 79
                 fn, sha, chk)
80 80
             raise BadChecksum(_("bad sha1 in downloaded file"))
81 81
 
82  
-    def _get_local_file_name(self, url):
83  
-        return get_local_file_name(self.opts.target, url)
84  
-
85 82
 
86 83
 class InstallUninstall(WithMake, WithSpecLocal, Command):
87 84
     """
7  pgxnclient/network.py
@@ -57,13 +57,16 @@ def get_local_file_name(target, url):
57 57
 def download(f, fn, rename=True):
58 58
     """Download a file locally.
59 59
 
60  
-    :param f: open file read
61  
-    :param fn: name of the file to write
  60
+    :param f: open file to read
  61
+    :param fn: name of the file to write. If a dir, save into it.
62 62
     :param rename: if true and a file *fn* exist, rename the downloaded file
63 63
         adding a prefix ``-1``, ``-2``... before the extension.
64 64
     
65 65
     Return the name of the file saved.
66 66
     """
  67
+    if os.path.isdir(fn):
  68
+        fn = get_local_file_name(fn, f.url)
  69
+
67 70
     if rename:
68 71
         if os.path.exists(fn):
69 72
             base, ext = os.path.splitext(fn)

0 notes on commit 2f2c299

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