def check_apk(self, apk_file, checksum_file): self.info("The checksum for the APK is being checked....") checksum = ScriptMixin.read_from_file(self, checksum_file, False) checksum = re.sub("\s(.*)", "", checksum.splitlines()[0]) apk_checksum = self.file_sha512sum(apk_file) if checksum == apk_checksum: self.info("APK checksum check succeeded!") self.download_complete(apk_file, checksum_file) else: ScriptMixin.rmtree(self, self.download_dir) self.fatal("Downloading " + apk_file + " failed!")
def test(self): ScriptMixin.mkdir_p(self, self.download_dir) testfile = os.path.join(self.download_dir, "testfile") testchecksums = os.path.join(self.download_dir, "testchecksums") ScriptMixin.write_to_file(self, testfile, "This is a test file!") ScriptMixin.write_to_file(self, testchecksums, self.file_sha512sum(testfile)) self.check_apk(testfile, testchecksums) self.download_complete(testfile, testchecksums) if os.path.isfile(testchecksums): self.fatal("download_complete test failed!") self.cleanup() if os.path.isdir(self.download_dir): self.fatal("cleanup test failed") url = self.generate_url("43.0", "2", "multi", "x86", "i386") correcturl = "https://ftp.mozilla.org/pub/mozilla.org/mobile/candidates/43.0-candidates/build2/"\ + self.android_prefix + "x86/multi/fennec-43.0.multi." + self.android_prefix + "i386" if not url == correcturl: self.fatal("get_url test failed!") if not self.get_api_suffix(self.multi_api_archs[0]) == self.multi_apis: self.fatal("get_api_suffix test failed!") if not self.get_arch_file("x86") == "i386": self.fatal("get_arch_file test failed!") if not self.get_common_file_name("43.0", "multi") == "fennec-43.0.multi." + self.android_prefix: self.fatal("get_common_file_name test failed!")
def download(self, version, build, arch, locale): ScriptMixin.mkdir_p(self, self.download_dir) common_filename = self.get_common_file_name(version, locale) arch_file = self.get_arch_file(arch) for api_suffix in self.get_api_suffix(arch): url = self.generate_url(version, build, locale, api_suffix, arch_file) apk_url = url + self.apk_ext checksum_url = url + self.checksums_ext if arch in self.multi_api_archs: filename = common_filename + arch_file + "-" + api_suffix else: filename = common_filename + arch_file filename_apk = os.path.join(self.download_dir, filename + self.apk_ext) filename_checksums = os.path.join(self.download_dir, filename + self.checksums_ext) retry_config = {'attempts': 1, 'cleanup': self.download_error} ScriptMixin.download_file(self, apk_url, filename_apk, retry_config=retry_config) retry_config = {'attempts': 1, 'cleanup': self.download_error} ScriptMixin.download_file(self, checksum_url, filename_checksums, retry_config=retry_config) self.check_apk(filename_apk, filename_checksums)
def test(self): ScriptMixin.mkdir_p(self, self.download_dir) testfile = os.path.join(self.download_dir, "testfile") testchecksums = os.path.join(self.download_dir, "testchecksums") ScriptMixin.write_to_file(self, testfile, "This is a test file!") ScriptMixin.write_to_file(self, testchecksums, self.file_sha512sum(testfile)) self.check_apk(testfile, testchecksums) self.download_complete(testfile, testchecksums) if os.path.isfile(testchecksums): self.fatal("download_complete test failed!") self.cleanup() if os.path.isdir(self.download_dir): self.fatal("cleanup test failed") url = self.generate_url("43.0", "2", "multi", "x86", "i386") correcturl = "https://ftp.mozilla.org/pub/mozilla.org/mobile/candidates/43.0-candidates/build2/"\ + self.android_prefix + "x86/multi/fennec-43.0.multi." + self.android_prefix + "i386" if not url == correcturl: self.fatal("get_url test failed!") if not self.get_api_suffix(self.multi_api_archs[0]) == self.multi_apis: self.fatal("get_api_suffix test failed!") if not self.get_arch_file("x86") == "i386": self.fatal("get_arch_file test failed!") if not self.get_common_file_name( "43.0", "multi") == "fennec-43.0.multi." + self.android_prefix: self.fatal("get_common_file_name test failed!")
def download_complete(self, apk_file, checksum_file): self.info(apk_file + " has been downloaded successfully") ScriptMixin.rmtree(self, checksum_file)
def cleanup(self): ScriptMixin.rmtree(self, self.download_dir) self.info("Download directory cleaned")