Fix update_3rdparty on windows

You cannot open a file twice on windows, so the call to
urllib.request.urlretrieve was invalid, since we already opened the
temporary file. urlretrieve without a filename will automatically create
and return a temp-file, so we're fine.
This commit is contained in:
Daniel Schadt 2015-11-28 12:38:01 +01:00
parent 384a9ad923
commit a072cf0175

View File

@ -47,14 +47,15 @@ def update_pdfjs():
version, url = get_latest_pdfjs_url() version, url = get_latest_pdfjs_url()
target_path = os.path.join('qutebrowser', '3rdparty', 'pdfjs') target_path = os.path.join('qutebrowser', '3rdparty', 'pdfjs')
print("=> Downloading pdf.js {}".format(version)) print("=> Downloading pdf.js {}".format(version))
with tempfile.NamedTemporaryFile(prefix='qute-pdfjs-') as archive: (archive_path, _headers) = urllib.request.urlretrieve(url)
urllib.request.urlretrieve(url, archive.name) if os.path.isdir(target_path):
if os.path.isdir(target_path): print("Removing old version in {}".format(target_path))
print("Removing old version in {}".format(target_path)) shutil.rmtree(target_path)
shutil.rmtree(target_path) os.makedirs(target_path)
os.makedirs(target_path) print("Extracting new version")
print("Extracting new version") with open(archive_path, 'rb') as archive:
shutil.unpack_archive(archive, target_path, 'zip') shutil.unpack_archive(archive, target_path, 'zip')
urllib.request.urlcleanup()
def main(): def main():