From 4fccba2750cf5964c3b99b4c37b2a33519ddcf1f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 24 Dec 2019 11:13:51 -0300 Subject: [PATCH] [web] checking if the electron files exist before downloading --- bauh/gems/web/controller.py | 8 ++++---- bauh/gems/web/environment.py | 17 +++++++++++++++++ bauh/view/qt/apps_table.py | 2 +- bauh/view/resources/locale/ca | 4 +++- bauh/view/resources/locale/de | 4 +++- bauh/view/resources/locale/en | 4 +++- bauh/view/resources/locale/es | 4 +++- bauh/view/resources/locale/it | 4 +++- bauh/view/resources/locale/pt | 4 +++- 9 files changed, 40 insertions(+), 11 deletions(-) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index d6aa8a33..3ca0ed3d 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -255,7 +255,7 @@ class WebApplicationManager(SoftwareManager): if local_config['environment']['electron']['version']: for app in res.new: - app.version = local_config['environment']['electron']['version'] + app.version = str(local_config['environment']['electron']['version']) app.latest_version = app.version return res @@ -605,10 +605,10 @@ class WebApplicationManager(SoftwareManager): watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier'))) - electron_version = next((c for c in env_components if c.id == 'electron')).version + electron_version = str(next((c for c in env_components if c.id == 'electron')).version) installed = handler.handle_simple(nativefier.install(url=pkg.url, name=app_id, output_dir=app_dir, electron_version=electron_version, - system=local_config['environment']['system'], + system=bool(local_config['environment']['system']), cwd=INSTALLED_PATH, extra_options=install_options)) @@ -838,7 +838,7 @@ class WebApplicationManager(SoftwareManager): thread_config.join() if local_config and local_config['environment']['electron']['version']: for s in res: - s.package.version = local_config['environment']['electron']['version'] + s.package.version = str(local_config['environment']['electron']['version']) s.package.latest_version = s.package.version return res diff --git a/bauh/gems/web/environment.py b/bauh/gems/web/environment.py index c17b6453..7193dc52 100644 --- a/bauh/gems/web/environment.py +++ b/bauh/gems/web/environment.py @@ -11,6 +11,7 @@ import yaml from bauh.api.abstract.download import FileDownloader from bauh.api.abstract.handler import ProcessWatcher +from bauh.api.abstract.view import MessageType from bauh.api.http import HttpClient from bauh.commons import system from bauh.commons.html import bold @@ -193,11 +194,27 @@ class EnvironmentUpdater: Path(ELECTRON_PATH).mkdir(parents=True, exist_ok=True) self.logger.info("Downloading Electron {}".format(version)) electron_path = '{}/{}'.format(ELECTRON_PATH, url.split('/')[-1]) + + if not self.http_client.exists(url): + self.logger.warning("The file {} seems not to exist".format(url)) + watcher.show_message(title=self.i18n['message.file.not_exist'], + body=self.i18n['message.file.not_exist.body'].format(bold(url)), + type_=MessageType.ERROR) + return False + return self.file_downloader.download(file_url=url, watcher=watcher, output_path=electron_path, cwd=ELECTRON_PATH) def download_electron_sha256(self, version: str, url: str, watcher: ProcessWatcher) -> bool: self.logger.info("Downloading Electron {} sha526".format(version)) sha256_path = '{}/{}'.format(ELECTRON_PATH, url.split('/')[-1]) + '-{}'.format(version) + + if not self.http_client.exists(url): + self.logger.warning("The file {} seems not to exist".format(url)) + watcher.show_message(title=self.i18n['message.file.not_exist'], + body=self.i18n['message.file.not_exist.body'].format(bold(url)), + type_=MessageType.ERROR) + return False + return self.file_downloader.download(file_url=url, watcher=watcher, output_path=sha256_path, cwd=ELECTRON_PATH) def _get_electron_url(self, version: str, is_x86_x64_arch: bool) -> str: diff --git a/bauh/view/qt/apps_table.py b/bauh/view/qt/apps_table.py index 92f98e76..2a68cda1 100644 --- a/bauh/view/qt/apps_table.py +++ b/bauh/view/qt/apps_table.py @@ -299,7 +299,7 @@ class AppsTable(QTableWidget): self.setCellWidget(pkg.table_index, col, item) def _set_col_version(self, col: int, pkg: PackageView): - label_version = QLabel(pkg.model.version if pkg.model.version else '?') + label_version = QLabel(str(pkg.model.version if pkg.model.version else '?')) label_version.setAlignment(Qt.AlignCenter) item = QWidget() diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca index 0a38acc7..965fe179 100644 --- a/bauh/view/resources/locale/ca +++ b/bauh/view/resources/locale/ca @@ -215,4 +215,6 @@ address=adreça view.components.file_chooser.placeholder=Feu clic aquí per seleccionar files=fitxers all_files=tots els fitxers -file_chooser.title=Selector de fitxers \ No newline at end of file +file_chooser.title=Selector de fitxers +message.file.not_exist=Fitxer no existeix +message.file.not_exist.body=El fitxer {} sembla no existir \ No newline at end of file diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index b79ac678..f4387ad2 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -169,4 +169,6 @@ address=Adresse view.components.file_chooser.placeholder=Klicken Sie hier, um auszuwählen files=Dateien all_files=Alle Dateien -file_chooser.title=Dateiauswahl \ No newline at end of file +file_chooser.title=Dateiauswahl +message.file.not_exist=Datei existiert nicht +message.file.not_exist.body=Die Datei {} scheint nicht zu existieren \ No newline at end of file diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index 51a13092..baf28c65 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -173,4 +173,6 @@ address=address view.components.file_chooser.placeholder=Click here to select files=files all_files=all files -file_chooser.title=File selector \ No newline at end of file +file_chooser.title=File selector +message.file.not_exist=File does not exist +message.file.not_exist.body=The file {} seems not to exist \ No newline at end of file diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index 93401a81..ba5dfe81 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -214,4 +214,6 @@ address=dirección view.components.file_chooser.placeholder=Pulse aquí para seleccionar files=archivos all_files=todos los archivos -file_chooser.title=Selector de archivos \ No newline at end of file +file_chooser.title=Selector de archivos +message.file.not_exist=Archivo no existe +message.file.not_exist.body=El archivo {} parece no existir \ No newline at end of file diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index 7bf23f67..f715f261 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -170,4 +170,6 @@ address=indirizzo view.components.file_chooser.placeholder=Fai clic qui per selezionare files=files all_files=tutti i files -file_chooser.title=Selettore file \ No newline at end of file +file_chooser.title=Selettore file +message.file.not_exist=File non esiste +message.file.not_exist.body=Il file {} sembra non esistere \ No newline at end of file diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index 4ab1f8f5..55e63265 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -217,4 +217,6 @@ address=endereço view.components.file_chooser.placeholder=Clique aqui para selecionar files=arquivos all_files=todos os arquivos -file_chooser.title=Seletor arquivos \ No newline at end of file +file_chooser.title=Seletor arquivos +message.file.not_exist=Arquivo não existe +message.file.not_exist.body=O arquivo {} parece não existir \ No newline at end of file