mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 22:24:14 +02:00
[wgem] adding category
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import glob
|
||||
import json
|
||||
import locale
|
||||
import os
|
||||
import re
|
||||
@@ -11,6 +10,8 @@ from pathlib import Path
|
||||
from threading import Thread
|
||||
from typing import List, Type, Set, Tuple
|
||||
|
||||
import yaml
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
@@ -39,6 +40,7 @@ except:
|
||||
|
||||
RE_PROTOCOL_STRIP = re.compile(r'[a-zA-Z]+://')
|
||||
RE_SEVERAL_SPACES = re.compile(r'\s+')
|
||||
RE_SYMBOLS_SPLIT = re.compile(r'[\-|_\s]')
|
||||
|
||||
|
||||
class WebApplicationManager(SoftwareManager):
|
||||
@@ -70,13 +72,10 @@ class WebApplicationManager(SoftwareManager):
|
||||
name = name_tag.text.strip() if name_tag else None
|
||||
|
||||
if not name:
|
||||
name = url_no_protocol.split('.')[0]
|
||||
name = url_no_protocol.split('.')[0].strip()
|
||||
|
||||
if name:
|
||||
name = name.replace('|', '').replace('_', ' ')
|
||||
|
||||
if ' ' in name:
|
||||
name = RE_SEVERAL_SPACES.sub(' ', name)
|
||||
name = RE_SYMBOLS_SPLIT.split(name)[0].strip()
|
||||
|
||||
return name
|
||||
|
||||
@@ -115,7 +114,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
if installed_matches:
|
||||
res.installed.extend(installed_matches)
|
||||
else:
|
||||
url_res = self.http_client.get(url, headers={'Accept-language': self._get_lang_header()}, ignore_ssl=True)
|
||||
url_res = self.http_client.get(url, headers={'Accept-language': self._get_lang_header()}, ignore_ssl=True, single_call=True)
|
||||
|
||||
if url_res:
|
||||
soup = BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head'))
|
||||
@@ -149,9 +148,9 @@ class WebApplicationManager(SoftwareManager):
|
||||
res = SearchResult([], [], 0)
|
||||
|
||||
if os.path.exists(INSTALLED_PATH):
|
||||
for data_path in glob.glob('{}/*/*data.json'.format(INSTALLED_PATH)):
|
||||
for data_path in glob.glob('{}/*/*data.yml'.format(INSTALLED_PATH)):
|
||||
with open(data_path, 'r') as f:
|
||||
res.installed.append(WebApplication(installed=True, **json.loads(f.read())))
|
||||
res.installed.append(WebApplication(installed=True, **yaml.safe_load(f.read())))
|
||||
res.total += 1
|
||||
|
||||
return res
|
||||
@@ -199,12 +198,15 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
def get_info(self, pkg: WebApplication) -> dict:
|
||||
if pkg.installed:
|
||||
info = {'{}_{}'.format(idx + 1, att): getattr(pkg, att) for idx, att in enumerate(('url', 'description', 'version', 'installation_dir', 'desktop_entry'))}
|
||||
info['6_exec_file'] = pkg.get_exec_path()
|
||||
info['7_icon_path'] = pkg.get_disk_icon_path()
|
||||
info = {'{}_{}'.format(idx + 1, att): getattr(pkg, att) for idx, att in enumerate(('url', 'description', 'version', 'categories', 'installation_dir', 'desktop_entry'))}
|
||||
info['7_exec_file'] = pkg.get_exec_path()
|
||||
info['8_icon_path'] = pkg.get_disk_icon_path()
|
||||
|
||||
if os.path.exists(pkg.installation_dir):
|
||||
info['8_size'] = get_human_size_str(get_dir_size(pkg.installation_dir))
|
||||
info['9_size'] = get_human_size_str(get_dir_size(pkg.installation_dir))
|
||||
|
||||
if info.get('4_categories'):
|
||||
info['4_categories'] = [self.i18n[c.lower()].capitalize() for c in info['4_categories']]
|
||||
|
||||
return info
|
||||
|
||||
@@ -214,9 +216,15 @@ class WebApplicationManager(SoftwareManager):
|
||||
def _ask_install_options(self, app: WebApplication, watcher: ProcessWatcher) -> Tuple[bool, List[str]]:
|
||||
watcher.change_substatus(self.i18n['web.install.substatus.options'])
|
||||
|
||||
inp_url = TextInputComponent(label=self.i18n['address'], value=app.url, read_only=True)
|
||||
inp_name = TextInputComponent(label=self.i18n['name'], value=app.name)
|
||||
inp_desc = TextInputComponent(label=self.i18n['description'], value=app.description)
|
||||
|
||||
cat_ops = [InputOption(label=self.i18n['web.install.option.category.none'].capitalize(), value=0)]
|
||||
cat_ops.extend([InputOption(label=self.i18n[c.lower()].capitalize(), value=c) for c in self.context.default_categories])
|
||||
|
||||
inp_cat = SingleSelectComponent(label=self.i18n['category'], type_=SelectViewType.COMBO, options=cat_ops, default_option=cat_ops[0])
|
||||
|
||||
tray_op_off = InputOption(label=self.i18n['web.install.option.tray.off.label'], value=0, tooltip=self.i18n['web.install.option.tray.off.tip'])
|
||||
tray_op_default = InputOption(label=self.i18n['web.install.option.tray.default.label'], value='--tray', tooltip=self.i18n['web.install.option.tray.default.tip'])
|
||||
tray_op_min = InputOption(label=self.i18n['web.install.option.tray.min.label'], value='--tray=start-in-tray', tooltip=self.i18n['web.install.option.tray.min.tip'])
|
||||
@@ -225,7 +233,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
options=[tray_op_off, tray_op_default, tray_op_min],
|
||||
label=self.i18n['web.install.option.tray.label'])
|
||||
|
||||
form_1 = FormComponent(components=[inp_name, inp_desc, inp_tray])
|
||||
form_1 = FormComponent(components=[inp_url, inp_name, inp_desc, inp_cat, inp_tray])
|
||||
|
||||
op_single = InputOption(id_='single', label=self.i18n['web.install.option.single.label'], value="--single-instance", tooltip=self.i18n['web.install.option.single.tip'])
|
||||
op_max = InputOption(id_='max', label=self.i18n['web.install.option.max.label'], value="--maximize", tooltip=self.i18n['web.install.option.max.tip'])
|
||||
@@ -238,11 +246,10 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='')
|
||||
|
||||
bt_continue = self.i18n['continue'].capitalize()
|
||||
res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
|
||||
body=self.i18n['web.install.options_dialog.body'].format(bold(bt_continue)),
|
||||
body=None,
|
||||
components=[form_1, check_options],
|
||||
confirmation_label=bt_continue,
|
||||
confirmation_label=self.i18n['continue'].capitalize(),
|
||||
deny_label=self.i18n['cancel'].capitalize())
|
||||
|
||||
if res:
|
||||
@@ -251,7 +258,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
if check_options.values:
|
||||
selected.extend(check_options.get_selected_values())
|
||||
|
||||
tray_mode = inp_tray.get_selected_value()
|
||||
tray_mode = inp_tray.get_selected()
|
||||
if tray_mode is not None and tray_mode != 0:
|
||||
selected.append(tray_mode)
|
||||
|
||||
@@ -265,6 +272,11 @@ class WebApplicationManager(SoftwareManager):
|
||||
if custom_desc:
|
||||
app.description = inp_desc.get_value()
|
||||
|
||||
cat = inp_cat.get_selected()
|
||||
|
||||
if cat != 0:
|
||||
app.categories = [cat]
|
||||
|
||||
return res, selected
|
||||
|
||||
return False, []
|
||||
@@ -385,12 +397,13 @@ class WebApplicationManager(SoftwareManager):
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name={name} ( web )
|
||||
Categories=Applications;
|
||||
Comment={desc}
|
||||
Icon={icon}
|
||||
Exec={exec_path}
|
||||
{categories}
|
||||
""".format(name=pkg.name, exec_path=pkg.get_exec_path(),
|
||||
desc=pkg.description or pkg.url, icon=pkg.get_disk_icon_path())
|
||||
desc=pkg.description or pkg.url, icon=pkg.get_disk_icon_path(),
|
||||
categories='Categories={}'.format(';'.join(pkg.categories)) if pkg.categories else '')
|
||||
|
||||
def is_enabled(self) -> bool:
|
||||
return self.enabled
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
from bauh.api.abstract.model import SoftwarePackage
|
||||
from bauh.commons import resource
|
||||
@@ -8,9 +9,11 @@ from bauh.gems.web import ROOT_DIR
|
||||
class WebApplication(SoftwarePackage):
|
||||
|
||||
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
|
||||
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None):
|
||||
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
|
||||
categories: List[str] = None):
|
||||
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
|
||||
icon_url=icon_url, installed=installed, version=version)
|
||||
icon_url=icon_url, installed=installed, version=version,
|
||||
categories=categories)
|
||||
self.url = url
|
||||
self.installation_dir = installation_dir
|
||||
self.desktop_entry = desktop_entry
|
||||
@@ -23,7 +26,7 @@ class WebApplication(SoftwarePackage):
|
||||
|
||||
@staticmethod
|
||||
def _get_cached_attrs() -> tuple:
|
||||
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', 'desktop_entry'
|
||||
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', 'desktop_entry', 'categories'
|
||||
|
||||
def can_be_downgraded(self):
|
||||
return False
|
||||
@@ -41,6 +44,9 @@ class WebApplication(SoftwarePackage):
|
||||
def get_default_icon_path(self) -> str:
|
||||
return resource.get_path('img/web.png', ROOT_DIR)
|
||||
|
||||
def get_disk_data_path(self):
|
||||
return '{}/data.yml'.format(self.get_disk_cache_path())
|
||||
|
||||
def is_application(self):
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
gem.web.info=It allows to install Web applications on your system
|
||||
gem.web.info=It allows to install Web applications on the system through they addresses ( URLs )
|
||||
web.environment.install=Installing {}
|
||||
web.waiting.env_updater=Updating environment
|
||||
web.env.checking=Checking the Web installation environment
|
||||
web.env.error=It seems there are issues with the Web installation environment. It wil not be possible to install {}.
|
||||
web.install.options_dialog.title=Installation options
|
||||
web.install.options_dialog.body=Select the wanted installation options and click in the {} button
|
||||
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 {}
|
||||
@@ -35,13 +34,15 @@ web.install.option.tray.default.label=Default
|
||||
web.install.option.tray.default.tip=The app icon will be attached to the system tray allowing it to be quickly opened
|
||||
web.install.option.tray.min.label=Start minimized
|
||||
web.install.option.tray.min.tip=The app will be started minimized as an icon in the system tray
|
||||
web.install.option.category.none=none
|
||||
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
|
||||
web.info.2_description=description
|
||||
web.info.3_version=version
|
||||
web.info.4_installation_dir=installation dir
|
||||
web.info.5_desktop_entry=shortcut
|
||||
web.info.6_exec_file=executable
|
||||
web.info.7_icon_path=icon
|
||||
web.info.8_size=size
|
||||
web.info.4_categories=categories
|
||||
web.info.5_installation_dir=installation dir
|
||||
web.info.6_desktop_entry=shortcut
|
||||
web.info.7_exec_file=executable
|
||||
web.info.8_icon_path=icon
|
||||
web.info.9_size=size
|
||||
@@ -1,10 +1,9 @@
|
||||
gem.web.info=Permite instalar aplicações Web no seu sistema
|
||||
gem.web.info=Permite instalar aplicações Web no seu sistema através dos seus endereços ( URLs )
|
||||
web.environment.nativefier=Instalando {}
|
||||
web.waiting.env_updater=Atualizando ambiente
|
||||
web.env.checking=Verificando o ambiente de instalação Web
|
||||
web.env.error=Parce que existem problemas com o ambiente de instalação Web. Não será possível instalar {}.
|
||||
web.install.options_dialog.title=Opções de instalação
|
||||
web.install.options_dialog.body=Selecione as opções de instalação desejadas e clique no botão {}
|
||||
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 {}
|
||||
@@ -35,13 +34,15 @@ web.install.option.tray.default.label=Padrão
|
||||
web.install.option.tray.default.tip=O ícone do aplicativo será anexado a bandeja do sistema permitindo que o mesma seja rapidamente aberto
|
||||
web.install.option.tray.min.label=Iniciar minimizado
|
||||
web.install.option.tray.min.tip=O aplicativo será iniciado minimizado como um ícone da bandeja do sistema
|
||||
web.install.option.category.none=nenhuma
|
||||
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
|
||||
web.info.2_description=descrição
|
||||
web.info.3_version=versão
|
||||
web.info.4_installation_dir=diretório de instalação
|
||||
web.info.5_desktop_entry=atalho
|
||||
web.info.6_exec_file=executável
|
||||
web.info.7_icon_path=ícone
|
||||
web.info.8_size=tamanho
|
||||
web.info.4_categories=categorias
|
||||
web.info.5_installation_dir=diretório de instalação
|
||||
web.info.6_desktop_entry=atalho
|
||||
web.info.7_exec_file=executável
|
||||
web.info.8_icon_path=ícone
|
||||
web.info.9_size=tamanho
|
||||
|
||||
Reference in New Issue
Block a user