[wgem] beginning install

This commit is contained in:
Vinícius Moreira
2019-12-10 19:25:30 -03:00
parent 37717d81dc
commit 49a3f12047
4 changed files with 35 additions and 20 deletions

View File

@@ -7,8 +7,10 @@ from bauh.api.abstract.controller import SoftwareManager, SearchResult
from bauh.api.abstract.disk import DiskCacheLoader from bauh.api.abstract.disk import DiskCacheLoader
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
from bauh.gems.web import npm from bauh.api.abstract.view import MessageType
from bauh.gems.web.environment import NodeUpdater from bauh.commons.html import bold
from bauh.commons.system import ProcessHandler
from bauh.gems.web.environment import EnvironmentUpdater
from bauh.gems.web.model import WebApplication from bauh.gems.web.model import WebApplication
try: try:
@@ -27,12 +29,14 @@ except:
class WebApplicationManager(SoftwareManager): class WebApplicationManager(SoftwareManager):
def __init__(self, context: ApplicationContext): def __init__(self, context: ApplicationContext, env_updater: Thread = None):
super(WebApplicationManager, self).__init__(context=context) super(WebApplicationManager, self).__init__(context=context)
self.http_client = context.http_client self.http_client = context.http_client
self.node_updater = NodeUpdater(logger=context.logger, http_client=context.http_client, self.node_updater = EnvironmentUpdater(logger=context.logger, http_client=context.http_client,
file_downloader=context.file_downloader, i18n=context.i18n) file_downloader=context.file_downloader, i18n=context.i18n)
self.enabled = True self.enabled = True
self.i18n = context.i18n
self.env_updater = env_updater
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult: def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult:
res = SearchResult([], [], 0) res = SearchResult([], [], 0)
@@ -44,7 +48,7 @@ class WebApplicationManager(SoftwareManager):
soup = BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')) soup = BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head'))
name_tag = soup.head.find('meta', attrs={'name': 'application-name'}) name_tag = soup.head.find('meta', attrs={'name': 'application-name'})
name = name_tag.get('content') if name_tag else words.split('.')[0] name = name_tag.get('content') if name_tag else words.split('.')[0].split('://')[1]
desc_tag = soup.head.find('meta', attrs={'name': 'description'}) desc_tag = soup.head.find('meta', attrs={'name': 'description'})
desc = desc_tag.get('content') if desc_tag else words desc = desc_tag.get('content') if desc_tag else words
@@ -82,8 +86,18 @@ class WebApplicationManager(SoftwareManager):
def get_history(self, pkg: SoftwarePackage) -> PackageHistory: def get_history(self, pkg: SoftwarePackage) -> PackageHistory:
pass pass
def install(self, pkg: SoftwarePackage, root_password: str, watcher: ProcessWatcher) -> bool: def install(self, pkg: WebApplication, root_password: str, watcher: ProcessWatcher) -> bool:
pass if self.env_updater and self.env_updater.is_alive():
watcher.change_substatus(self.i18n['web.waiting.env_updater'])
self.env_updater.join()
watcher.change_substatus(self.i18n['web.env.checking'])
handler = ProcessHandler(watcher)
if not self._update_environment(handler=handler):
watcher.show_message(title=self.i18n['error'], body=self.i18n['web.env.error'].format(bold(pkg.name)), type_=MessageType.ERROR)
return False
return True
def is_enabled(self) -> bool: def is_enabled(self) -> bool:
return self.enabled return self.enabled
@@ -97,12 +111,13 @@ class WebApplicationManager(SoftwareManager):
def requires_root(self, action: str, pkg: SoftwarePackage): def requires_root(self, action: str, pkg: SoftwarePackage):
return False return False
def _update_environment(self): def _update_environment(self, handler: ProcessHandler = None) -> bool:
self.node_updater.update_environment(self.context.is_system_x86_64()) return self.node_updater.update_environment(self.context.is_system_x86_64(), handler=handler)
def prepare(self): def prepare(self):
if bool(int(os.getenv('BAUH_WEB_UPDATE_NODE', 1))): if bool(int(os.getenv('BAUH_WEB_UPDATE_NODE', 1))):
Thread(daemon=True, target=self._update_environment).start() self.env_updater = Thread(daemon=True, target=self._update_environment)
self.env_updater.start()
def list_updates(self, internet_available: bool) -> List[PackageUpdate]: def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
pass pass

View File

@@ -2,7 +2,6 @@ import logging
import os import os
import shutil import shutil
import tarfile import tarfile
import traceback
from pathlib import Path from pathlib import Path
import requests import requests
@@ -19,7 +18,7 @@ from bauh.gems.web import BIN_PATH, NODE_DIR_PATH, NODE_BIN_PATH, NPM_BIN_PATH,
from bauh.view.util.translation import I18n from bauh.view.util.translation import I18n
class NodeUpdater: class EnvironmentUpdater:
def __init__(self, logger: logging.Logger, http_client: HttpClient, file_downloader: FileDownloader, i18n: I18n): def __init__(self, logger: logging.Logger, http_client: HttpClient, file_downloader: FileDownloader, i18n: I18n):
self.logger = logger self.logger = logger
@@ -27,11 +26,6 @@ class NodeUpdater:
self.i18n = i18n self.i18n = i18n
self.http_client = http_client self.http_client = http_client
def _is_internet_available(self) -> bool:
self.logger.info('Checking internet connection')
# TODO
return True
def _download_and_install(self, version: str, version_url: str, watcher: ProcessWatcher) -> bool: def _download_and_install(self, version: str, version_url: str, watcher: ProcessWatcher) -> bool:
self.logger.info("Downloading NodeJS {}: {}".format(version, version_url)) self.logger.info("Downloading NodeJS {}: {}".format(version, version_url))

View File

@@ -1,2 +1,5 @@
gem.web.info=It allows to install Web applications on your system gem.web.info=It allows to install Web applications on your system
web.environment.install=Installing {} web.environment.install=Installing {}
web.waiting.env_updater=Updating environment
web.env.checking=Checking the Web application installation environment
web.env.error=It seems there are issues with the Web application installation environment. It wil not be possible to install {}.

View File

@@ -1,2 +1,5 @@
gem.web.info=Permite instalar aplicações Web no seu sistema gem.web.info=Permite instalar aplicações Web no seu sistema
web.environment.nativefier=Instalando {} web.environment.nativefier=Instalando {}
web.waiting.env_updater=Atualizando ambiente
web.env.checking=Verificando o ambiente de instalação para aplicativos Web
web.env.error=Parece haver problemas com o ambiente de instalação para aplicativos Web. Não sera possível instalar {}.