def start_component_update(self): if not os.path.exists(config.ext_bin_path): os.makedirs(config.ext_bin_path) d = Main.WebParser.WebServices.get_components_data() for i, component in enumerate(self.components): urls, archive_hash, file_to_extract, file_hash = d[component] fn = urls[0].split('/')[-1] log.debug("Downloading Component %s [%d/%d]..." % (component, i + 1, len(self.components))) self.label1.setText(tr("Downloading %s...") % component) self.label2.setText( tr("File: <i>%s</i> [%d/%d]") % (fn, i + 1, len(self.components))) obj = SmartDL(urls, logger=log) obj.add_hash_verification('sha256', archive_hash) obj.start(blocking=False) b = True while not obj.isFinished(): if b: self.label1.setText( tr("Downloading %s (%.2f MB)...") % (component, obj.filesize / 1024.0**2)) b = False QtGui.QApplication.processEvents() self.prg_bar.setValue(int(obj.get_progress() * 100)) time.sleep(0.1) if obj._failed: QtGui.QMessageBox.critical( self, tr("Error"), tr("The download has failed. It may be a network connection problem. Please try to rerun this application and try again." ), QtGui.QMessageBox.Ok) self.close() self.prg_bar.setValue(100) self.label1.setText(tr("Unpacking %s...") % component) ext = os.path.splitext(obj.get_dest())[1].lower() if ext == '.zip': zipObj = zipfile.ZipFile(obj.get_dest()) zipObj.extract(file_to_extract, config.ext_bin_path) elif ext == '.7z': cmd = r'"%s\7za.exe" e "%s" -ir!%s -y -o"%s"' % ( config.ext_bin_path, obj.get_dest(), file_to_extract, config.ext_bin_path) subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) else: log.error('could not extract %s archive.' % ext) self.close()
def test_get_packages_data(): d = Main.WebParser.WebServices.get_packages_data() assert d for name, t in d.items(): urls, file_hash, install_param = t for url in urls: obj = SmartDL(url) obj.add_hash_verification('sha256', file_hash) obj.start() assert obj.isSuccessful() os.unlink(obj.get_dest())
def test_get_components_data(): d = Main.WebParser.WebServices.get_components_data() assert d for name, t in d.items(): urls, archive_hash, file_to_extract, file_hash = t for url in urls: obj = SmartDL(url) obj.add_hash_verification('sha256', archive_hash) obj.start() assert obj.isSuccessful() os.unlink(obj.get_dest())
def test_hash(self): obj = SmartDL(self.default_7za920_mirrors, progress_bar=False) obj.add_hash_verification('sha256' ,'2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac') # good hash obj.start(blocking=False) # no exceptions obj.wait() self.assertTrue(obj.isSuccessful()) obj = SmartDL(self.default_7za920_mirrors, progress_bar=False) obj.add_hash_verification('sha256' ,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') # bad hash obj.start(blocking=False) # no exceptions obj.wait() self.assertFalse(obj.isSuccessful()) self.assertTrue(isinstance(obj.get_errors()[-1], HashFailedException))
def start_component_update(self): if not os.path.exists(config.ext_bin_path): os.makedirs(config.ext_bin_path) d = Main.WebParser.WebServices.get_components_data() for i, component in enumerate(self.components): urls, archive_hash, file_to_extract, file_hash = d[component] fn = urls[0].split('/')[-1] log.debug("Downloading Component %s [%d/%d]..." % (component, i+1, len(self.components))) self.label1.setText(tr("Downloading %s...") % component) self.label2.setText(tr("File: <i>%s</i> [%d/%d]") % (fn, i+1, len(self.components))) obj = SmartDL(urls, logger=log) obj.add_hash_verification('sha256', archive_hash) obj.start(blocking=False) b = True while not obj.isFinished(): if b: self.label1.setText(tr("Downloading %s (%.2f MB)...") % (component, obj.filesize/1024.0**2)) b = False QtGui.QApplication.processEvents() self.prg_bar.setValue(int(obj.get_progress()*100)) time.sleep(0.1) if obj._failed: QtGui.QMessageBox.critical(self, tr("Error"), tr("The download has failed. It may be a network connection problem. Please try to rerun this application and try again."), QtGui.QMessageBox.Ok) self.close() self.prg_bar.setValue(100) self.label1.setText(tr("Unpacking %s...") % component) ext = os.path.splitext(obj.get_dest())[1].lower() if ext == '.zip': zipObj = zipfile.ZipFile(obj.get_dest()) zipObj.extract(file_to_extract, config.ext_bin_path) elif ext == '.7z': cmd = r'"%s\7za.exe" e "%s" -ir!%s -y -o"%s"' % (config.ext_bin_path, obj.get_dest(), file_to_extract, config.ext_bin_path) subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) else: log.error('could not extract %s archive.' % ext) self.close()