From 841ae4723a5de49d97001cc9e93b9f45176ce937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Wed, 11 Dec 2019 19:18:58 -0300 Subject: [PATCH] [wgem] reading installed during search --- bauh/gems/web/controller.py | 34 +++++++++++++++++++++++++------ bauh/gems/web/resources/locale/en | 2 ++ bauh/gems/web/resources/locale/pt | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index e2b75b8c..e85d932c 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -1,6 +1,7 @@ import glob import json import os +import re import shutil import subprocess import traceback @@ -14,7 +15,6 @@ from bauh.api.abstract.disk import DiskCacheLoader from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory from bauh.api.abstract.view import MessageType -from bauh.commons import system from bauh.commons.html import bold from bauh.commons.system import ProcessHandler from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN @@ -34,6 +34,8 @@ try: except: LXML_AVAILABLE = False +RE_PROTOCOL_STRIP = re.compile(r'[a-zA-Z]+://') + class WebApplicationManager(SoftwareManager): @@ -52,6 +54,17 @@ class WebApplicationManager(SoftwareManager): res = SearchResult([], [], 0) if is_url: + + installed = self.read_installed(disk_loader=disk_loader, limit=limit).installed + + url_no_protocol = RE_PROTOCOL_STRIP.split(words)[0].strip().lower() + + installed_matches = [app for app in installed if RE_PROTOCOL_STRIP.split(app.url)[0].lower() == url_no_protocol] + + if installed_matches: + res.installed.extend(installed_matches) + return res + url_res = self.http_client.get(words) if url_res: @@ -164,10 +177,11 @@ class WebApplicationManager(SoftwareManager): if not os.path.exists(app_dir): break else: - app_name_id += str(counter) + app_name_id = pkg_name + str(counter) app_dir = '{}/{}'.format(INSTALLED_PATH, app_name_id) counter += 1 + watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('Nativefier'))) installed = handler.handle_simple(nativefier.install(url=pkg.url, name=pkg_name, output_dir=app_dir, electron_version=self.env_settings['electron']['version'], cwd=INSTALLED_PATH)) @@ -201,16 +215,24 @@ class WebApplicationManager(SoftwareManager): pkg.version = f.read().strip() pkg.latest_version = pkg.version - desktop_entry = DESKTOP_ENTRY_PATH_PATTERN.format(name=app_name_id) - entry_content = self._gen_desktop_entry_content(pkg) + watcher.change_substatus(self.i18n['web.install.substatus.shortcut']) - # TODO check if the desktop entry exists + entry_id = app_name_id + desktop_entry = DESKTOP_ENTRY_PATH_PATTERN.format(name=entry_id) + while True: + if not os.path.exists(desktop_entry): + break + else: + counter += 1 + entry_id = pkg_name + str(counter) + desktop_entry += DESKTOP_ENTRY_PATH_PATTERN.format(name=entry_id) + + entry_content = self._gen_desktop_entry_content(pkg) with open(desktop_entry, 'w+') as f: f.write(entry_content) pkg.desktop_entry = desktop_entry - return True def _gen_desktop_entry_content(self, pkg: WebApplication) -> str: diff --git a/bauh/gems/web/resources/locale/en b/bauh/gems/web/resources/locale/en index b31634d5..d653e71b 100644 --- a/bauh/gems/web/resources/locale/en +++ b/bauh/gems/web/resources/locale/en @@ -6,6 +6,8 @@ web.env.error=It seems there are issues with the Web installation environment. I web.install.error=An error has happened during the {} installation web.install.nativefier.error.unknown=Have a look at the {} to identify the reason web.install.nativefier.error.inner_dir=The app installation directory was not found in {} +web.install.substatus.call_nativefier=Running {} +web.install.substatus.shortcut=Generating a menu shortcut web.uninstall.error.install_dir.not_found=The installation directory {} was not found web.uninstall.error.remove_dir=It was not possible to remove {} web.info.1_url=URL diff --git a/bauh/gems/web/resources/locale/pt b/bauh/gems/web/resources/locale/pt index ae8b1df8..a00f96d9 100644 --- a/bauh/gems/web/resources/locale/pt +++ b/bauh/gems/web/resources/locale/pt @@ -6,6 +6,8 @@ web.env.error=Parce que existem problemas com o ambiente de instalação Web. N wen.install.error=Ocorreu um erro durante a instalação de {} web.install.nativefier.error.unknown=Dê uma olhada em {} para identificar o motivo web.install.nativefier.error.inner_dir=O diretório de instalação do aplicativo não foi encontrado em {} +web.install.substatus.call_nativefier=Executando {} +web.install.substatus.shortcut=Criando um atalho no menu web.uninstall.error.install_dir.not_found=O diretório de instalação {} não foi encontrado web.uninstall.error.remove=Não foi possível remover {} web.info.1_url=URL