Permalink
Browse files

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

  • Loading branch information...
1 parent 572fd29 commit 2f2c299d6b21068830220d60df396cd1fddd4d71 @dvarrazzo committed Aug 29, 2012
Showing with 8 additions and 8 deletions.
  1. +3 −6 pgxnclient/commands/install.py
  2. +5 −2 pgxnclient/network.py
@@ -20,7 +20,7 @@
from pgxnclient.i18n import _, N_
from pgxnclient.utils import sha1, b
from pgxnclient.errors import BadChecksum, PgxnClientException, InsufficientPrivileges
-from pgxnclient.network import download, get_local_file_name
+from pgxnclient.network import download
from pgxnclient.commands import Command, WithDatabase, WithMake, WithPgConfig
from pgxnclient.commands import WithSpec, WithSpecLocal, WithSudo
from pgxnclient.utils.zip import unpack
@@ -54,8 +54,8 @@ def run(self):
"sha1 missing from the distribution meta")
with self.api.download(data['name'], SemVer(data['version'])) as fin:
- fn = self._get_local_file_name(fin.url)
- fn = download(fin, fn, rename=True)
+ fn = download(fin, self.opts.target)
+
self.verify_checksum(fn, chk)
return fn
@@ -79,9 +79,6 @@ def verify_checksum(self, fn, chk):
fn, sha, chk)
raise BadChecksum(_("bad sha1 in downloaded file"))
- def _get_local_file_name(self, url):
- return get_local_file_name(self.opts.target, url)
-
class InstallUninstall(WithMake, WithSpecLocal, Command):
"""
View
@@ -57,13 +57,16 @@ def get_local_file_name(target, url):
def download(f, fn, rename=True):
"""Download a file locally.
- :param f: open file read
- :param fn: name of the file to write
+ :param f: open file to read
+ :param fn: name of the file to write. If a dir, save into it.
:param rename: if true and a file *fn* exist, rename the downloaded file
adding a prefix ``-1``, ``-2``... before the extension.
Return the name of the file saved.
"""
+ if os.path.isdir(fn):
+ fn = get_local_file_name(fn, f.url)
+
if rename:
if os.path.exists(fn):
base, ext = os.path.splitext(fn)

0 comments on commit 2f2c299

Please sign in to comment.