[web] checking if the electron files exist before downloading

This commit is contained in:
Vinicius Moreira
2019-12-24 11:13:51 -03:00
parent e62383a844
commit 4fccba2750
9 changed files with 40 additions and 11 deletions

View File

@@ -255,7 +255,7 @@ class WebApplicationManager(SoftwareManager):
if local_config['environment']['electron']['version']: if local_config['environment']['electron']['version']:
for app in res.new: 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 app.latest_version = app.version
return res return res
@@ -605,10 +605,10 @@ class WebApplicationManager(SoftwareManager):
watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier'))) 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, installed = handler.handle_simple(nativefier.install(url=pkg.url, name=app_id, output_dir=app_dir,
electron_version=electron_version, electron_version=electron_version,
system=local_config['environment']['system'], system=bool(local_config['environment']['system']),
cwd=INSTALLED_PATH, cwd=INSTALLED_PATH,
extra_options=install_options)) extra_options=install_options))
@@ -838,7 +838,7 @@ class WebApplicationManager(SoftwareManager):
thread_config.join() thread_config.join()
if local_config and local_config['environment']['electron']['version']: if local_config and local_config['environment']['electron']['version']:
for s in res: 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 s.package.latest_version = s.package.version
return res return res

View File

@@ -11,6 +11,7 @@ import yaml
from bauh.api.abstract.download import FileDownloader from bauh.api.abstract.download import FileDownloader
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.view import MessageType
from bauh.api.http import HttpClient from bauh.api.http import HttpClient
from bauh.commons import system from bauh.commons import system
from bauh.commons.html import bold from bauh.commons.html import bold
@@ -193,11 +194,27 @@ class EnvironmentUpdater:
Path(ELECTRON_PATH).mkdir(parents=True, exist_ok=True) Path(ELECTRON_PATH).mkdir(parents=True, exist_ok=True)
self.logger.info("Downloading Electron {}".format(version)) self.logger.info("Downloading Electron {}".format(version))
electron_path = '{}/{}'.format(ELECTRON_PATH, url.split('/')[-1]) 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) 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: def download_electron_sha256(self, version: str, url: str, watcher: ProcessWatcher) -> bool:
self.logger.info("Downloading Electron {} sha526".format(version)) self.logger.info("Downloading Electron {} sha526".format(version))
sha256_path = '{}/{}'.format(ELECTRON_PATH, url.split('/')[-1]) + '-{}'.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) 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: def _get_electron_url(self, version: str, is_x86_x64_arch: bool) -> str:

View File

@@ -299,7 +299,7 @@ class AppsTable(QTableWidget):
self.setCellWidget(pkg.table_index, col, item) self.setCellWidget(pkg.table_index, col, item)
def _set_col_version(self, col: int, pkg: PackageView): 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) label_version.setAlignment(Qt.AlignCenter)
item = QWidget() item = QWidget()

View File

@@ -215,4 +215,6 @@ address=adreça
view.components.file_chooser.placeholder=Feu clic aquí per seleccionar view.components.file_chooser.placeholder=Feu clic aquí per seleccionar
files=fitxers files=fitxers
all_files=tots els fitxers all_files=tots els fitxers
file_chooser.title=Selector de fitxers file_chooser.title=Selector de fitxers
message.file.not_exist=Fitxer no existeix
message.file.not_exist.body=El fitxer {} sembla no existir

View File

@@ -169,4 +169,6 @@ address=Adresse
view.components.file_chooser.placeholder=Klicken Sie hier, um auszuwählen view.components.file_chooser.placeholder=Klicken Sie hier, um auszuwählen
files=Dateien files=Dateien
all_files=Alle Dateien all_files=Alle Dateien
file_chooser.title=Dateiauswahl file_chooser.title=Dateiauswahl
message.file.not_exist=Datei existiert nicht
message.file.not_exist.body=Die Datei {} scheint nicht zu existieren

View File

@@ -173,4 +173,6 @@ address=address
view.components.file_chooser.placeholder=Click here to select view.components.file_chooser.placeholder=Click here to select
files=files files=files
all_files=all files all_files=all files
file_chooser.title=File selector file_chooser.title=File selector
message.file.not_exist=File does not exist
message.file.not_exist.body=The file {} seems not to exist

View File

@@ -214,4 +214,6 @@ address=dirección
view.components.file_chooser.placeholder=Pulse aquí para seleccionar view.components.file_chooser.placeholder=Pulse aquí para seleccionar
files=archivos files=archivos
all_files=todos los archivos all_files=todos los archivos
file_chooser.title=Selector de archivos file_chooser.title=Selector de archivos
message.file.not_exist=Archivo no existe
message.file.not_exist.body=El archivo {} parece no existir

View File

@@ -170,4 +170,6 @@ address=indirizzo
view.components.file_chooser.placeholder=Fai clic qui per selezionare view.components.file_chooser.placeholder=Fai clic qui per selezionare
files=files files=files
all_files=tutti i files all_files=tutti i files
file_chooser.title=Selettore file file_chooser.title=Selettore file
message.file.not_exist=File non esiste
message.file.not_exist.body=Il file {} sembra non esistere

View File

@@ -217,4 +217,6 @@ address=endereço
view.components.file_chooser.placeholder=Clique aqui para selecionar view.components.file_chooser.placeholder=Clique aqui para selecionar
files=arquivos files=arquivos
all_files=todos os arquivos all_files=todos os arquivos
file_chooser.title=Seletor arquivos file_chooser.title=Seletor arquivos
message.file.not_exist=Arquivo não existe
message.file.not_exist.body=O arquivo {} parece não existir