def get_language_pack(lang_code, software_version, callback): """Download language pack for specified language""" lang_code = lcode_to_ietf(lang_code) logging.info("Retrieving language pack: %s" % lang_code) request_url = get_language_pack_url(lang_code, software_version) logging.debug("Downloading zip from %s" % request_url) path, response = download_file(request_url, callback=callback_percent_proxy(callback)) return path
def download_language_pack(lang): logging.debug("Downloading base language pack %s for creating the debugging language." % BASE_LANGUAGE_PACK) url = get_language_pack_url(lang) try: logging.debug("Downloading from {url}.".format(url=url)) resp = requests.get(url) resp.raise_for_status() except requests.ConnectionError as e: logging.error("Error downloading %s language pack: %s" % (lang, e)) sys.exit(1) logging.debug("Successfully downloaded base language pack %s" % lang) return zipfile.ZipFile(StringIO(resp.content))
def test_download_language_pack(self, get_method): # so the next n lines before a newline separator are all about # creating a dummy zipfile that is readable by zipfile.ZipFile dummy_file = StringIO() zf = zipfile.ZipFile(dummy_file, mode="w") zf.write(__file__) # write the current file into the zipfile, just so we have something in here zf.close() get_method.return_value.content = dummy_file.getvalue() # should still be convertible to a zipfile lang = "dummylanguage" result = mod.download_language_pack(lang) get_method.assert_called_once_with(get_language_pack_url(lang)) self.assertIsInstance(result, zipfile.ZipFile)
def get_language_pack(lang_code, software_version, callback): """Download language pack for specified language""" lang_code = lcode_to_ietf(lang_code) logging.info("Retrieving language pack: %s" % lang_code) request_url = get_language_pack_url(lang_code, software_version) logging.debug("Downloading zip from %s" % request_url) # aron: hack, download_file uses urllib.urlretrieve, which doesn't # return a status code. So before we make the full request, we # check first if the said lang pack url exists. If not, error out. if requests.head(request_url).status_code == 404: raise requests.exceptions.HTTPError("Language pack %s not found. Please double check that it exists." % lang_code) path, response = download_file(request_url, callback=callback_percent_proxy(callback)) return path
def test_download_language_pack(self, get_method): # so the next n lines before a newline separator are all about # creating a dummy zipfile that is readable by zipfile.ZipFile dummy_file = StringIO() zf = zipfile.ZipFile(dummy_file, mode="w") zf.write( __file__ ) # write the current file into the zipfile, just so we have something in here zf.close() get_method.return_value.content = dummy_file.getvalue( ) # should still be convertible to a zipfile lang = "dummylanguage" result = mod.download_language_pack(lang) get_method.assert_called_once_with(get_language_pack_url(lang)) self.assertIsInstance(result, zipfile.ZipFile)
def get_language_pack(lang_code, software_version, callback): """Download language pack for specified language""" lang_code = lcode_to_ietf(lang_code) logging.info("Retrieving language pack: %s" % lang_code) request_url = get_language_pack_url(lang_code, software_version) logging.debug("Downloading zip from %s" % request_url) # aron: hack, download_file uses urllib.urlretrieve, which doesn't # return a status code. So before we make the full request, we # check first if the said lang pack url exists. If not, error out. if requests.head(request_url).status_code == 404: raise requests.exceptions.HTTPError( "Language pack %s not found. Please double check that it exists." % lang_code) path, response = download_file(request_url, callback=callback_percent_proxy(callback)) return path