mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[wgem] filling preset app options
This commit is contained in:
@@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- bauh relies on [NodeJS](https://nodejs.org/en/), [Electron](https://electronjs.org/) and [nativefier](https://github.com/jiahaog/nativefier) to install the Web applications, but there is no need to have them installed on your system. Bauh will create its own installation environment with these technologies in **~/.local/share/bauh/web/env**.
|
||||
- requires only **python-beautifulsoup4** and **python-lxml** to be enabled
|
||||
|
||||
### Improvements
|
||||
- AppImage:
|
||||
- cleaning the downloaded database files when **--reset** is passed as parameter
|
||||
|
||||
|
||||
## [0.7.4] 2019-12-09
|
||||
### Improvements
|
||||
|
||||
@@ -73,6 +73,5 @@ class HttpClient:
|
||||
return system.get_human_size_str(size)
|
||||
|
||||
def exists(self, url: str) -> bool:
|
||||
res = self.session.get(url=url, allow_redirects=True, ignore_ssl=True)
|
||||
res = self.session.head(url=url, allow_redirects=True, verify=False, timeout=5)
|
||||
return res.status_code == 200
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from bauh.api.http import HttpClient
|
||||
|
||||
def is_available(client: HttpClient, logger: logging.Logger) -> bool:
|
||||
try:
|
||||
client.get('https://google.com')
|
||||
client.exists('https://google.com')
|
||||
return True
|
||||
except requests.exceptions.ConnectionError:
|
||||
if logger:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -10,6 +11,8 @@ from pathlib import Path
|
||||
from threading import Lock
|
||||
from typing import Set, Type, List
|
||||
|
||||
from colorama import Fore
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
@@ -19,7 +22,7 @@ from bauh.api.abstract.view import MessageType
|
||||
from bauh.api.constants import HOME_PATH
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess
|
||||
from bauh.gems.appimage import query, INSTALLATION_PATH, suggestions
|
||||
from bauh.gems.appimage import query, INSTALLATION_PATH, suggestions, LOCAL_PATH
|
||||
from bauh.gems.appimage.model import AppImage
|
||||
from bauh.gems.appimage.worker import DatabaseUpdater
|
||||
|
||||
@@ -446,3 +449,13 @@ class AppImageManager(SoftwareManager):
|
||||
return [pkg.url_screenshot]
|
||||
|
||||
return []
|
||||
|
||||
def clear_data(self):
|
||||
for f in glob.glob('{}/*.db'.format(LOCAL_PATH)):
|
||||
try:
|
||||
print('[bauh][appimage] Deleting {}'.format(f))
|
||||
os.remove(f)
|
||||
print('{}[bauh][appimage] {} deleted{}'.format(Fore.YELLOW, f, Fore.RESET))
|
||||
except:
|
||||
print('{}[bauh][appimage] An exception has happened when deleting {}{}'.format(Fore.RED, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
@@ -10,6 +10,7 @@ from threading import Thread
|
||||
import requests
|
||||
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.commons import internet
|
||||
from bauh.gems.appimage import LOCAL_PATH
|
||||
|
||||
|
||||
@@ -73,7 +74,8 @@ class DatabaseUpdater(Thread):
|
||||
if self.enabled:
|
||||
while True:
|
||||
try:
|
||||
self._download_databases()
|
||||
if internet.is_available(self.http_client, self.logger):
|
||||
self._download_databases()
|
||||
except requests.exceptions.ConnectionError:
|
||||
self.logger.warning('The internet connection seems to be off.')
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSugge
|
||||
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \
|
||||
SelectViewType, TextInputComponent, FormComponent, FileChooserComponent
|
||||
from bauh.api.constants import DESKTOP_ENTRIES_DIR
|
||||
from bauh.commons import resource
|
||||
from bauh.commons import resource, internet
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
|
||||
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN, ENV_PATH, UA_CHROME, \
|
||||
@@ -108,6 +108,19 @@ class WebApplicationManager(SoftwareManager):
|
||||
if icon_url:
|
||||
return icon_url
|
||||
|
||||
def _get_app_description(self, url: str, soup: "BeautifulSoup") -> str:
|
||||
description = None
|
||||
desc_tag = soup.head.find('meta', attrs={'name': 'description'})
|
||||
|
||||
if desc_tag:
|
||||
description = desc_tag.get('content')
|
||||
|
||||
if not description:
|
||||
desc_tag = soup.find('title')
|
||||
description = desc_tag.text if desc_tag else url
|
||||
|
||||
return description
|
||||
|
||||
def _get_fix_for(self, url_no_protocol: str) -> str:
|
||||
res = self.http_client.get(URL_FIX_PATTERN.format(url=url_no_protocol))
|
||||
|
||||
@@ -120,7 +133,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
def serialize_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
|
||||
super(WebApplicationManager, self).serialize_to_disk(pkg=pkg, icon_bytes=None, only_icon=False)
|
||||
|
||||
def _map_url(self, url: str) -> BeautifulSoup:
|
||||
def _map_url(self, url: str) -> "BeautifulSoup":
|
||||
url_res = self.http_client.get(url,
|
||||
headers={'Accept-language': self._get_lang_header(), 'User-Agent': UA_CHROME},
|
||||
ignore_ssl=True, single_call=True)
|
||||
@@ -147,10 +160,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
if soup:
|
||||
name = self._get_app_name(url_no_protocol, soup)
|
||||
|
||||
desc_tag = soup.head.find('meta', attrs={'name': 'description'})
|
||||
desc = desc_tag.get('content') if desc_tag else words
|
||||
|
||||
desc = self._get_app_description(url, soup)
|
||||
icon_url = self._get_app_icon_url(url, soup)
|
||||
|
||||
app = WebApplication(url=url, name=name, description=desc, icon_url=icon_url)
|
||||
@@ -259,14 +269,32 @@ class WebApplicationManager(SoftwareManager):
|
||||
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])
|
||||
def_cat = cat_ops[0]
|
||||
|
||||
if app.categories:
|
||||
for opt in cat_ops:
|
||||
if opt.value == app.categories[0]:
|
||||
def_cat = opt
|
||||
break
|
||||
|
||||
inp_cat = SingleSelectComponent(label=self.i18n['category'], type_=SelectViewType.COMBO, options=cat_ops, default_option=def_cat)
|
||||
|
||||
tray_op_off = InputOption(id_='tray_off', label=self.i18n['web.install.option.tray.off.label'], value=0, tooltip=self.i18n['web.install.option.tray.off.tip'])
|
||||
tray_op_default = InputOption(id_='tray_def', label=self.i18n['web.install.option.tray.default.label'], value='--tray', tooltip=self.i18n['web.install.option.tray.default.tip'])
|
||||
tray_op_min = InputOption(id_='tray_min', label=self.i18n['web.install.option.tray.min.label'], value='--tray=start-in-tray', tooltip=self.i18n['web.install.option.tray.min.tip'])
|
||||
|
||||
tray_opts = [tray_op_off, tray_op_default, tray_op_min]
|
||||
def_tray_opt = None
|
||||
|
||||
if app.preset_options:
|
||||
for opt in tray_opts:
|
||||
if opt.id in app.preset_options:
|
||||
def_tray_opt = opt
|
||||
break
|
||||
|
||||
inp_tray = SingleSelectComponent(type_=SelectViewType.COMBO,
|
||||
options=[tray_op_off, tray_op_default, tray_op_min],
|
||||
options=tray_opts,
|
||||
default_option=def_tray_opt,
|
||||
label=self.i18n['web.install.option.tray.label'])
|
||||
|
||||
icon_chooser = FileChooserComponent(allowed_extensions={'png'}, label=self.i18n['web.install.option.icon.label'])
|
||||
@@ -282,7 +310,15 @@ class WebApplicationManager(SoftwareManager):
|
||||
op_insecure = InputOption(id_='insecure', label=self.i18n['web.install.option.insecure.label'], value="--insecure", tooltip=self.i18n['web.install.option.insecure.tip'])
|
||||
op_igcert = InputOption(id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip'])
|
||||
|
||||
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=self.i18n['web.install.options.advanced'].capitalize())
|
||||
adv_opts = [op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert]
|
||||
def_adv_opts = {op_single}
|
||||
|
||||
if app.preset_options:
|
||||
for opt in adv_opts:
|
||||
if opt.id in app.preset_options:
|
||||
def_adv_opts.add(opt)
|
||||
|
||||
check_options = MultipleSelectComponent(options=adv_opts, default_options=def_adv_opts, label=self.i18n['web.install.options.advanced'].capitalize())
|
||||
|
||||
res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
|
||||
body=None,
|
||||
@@ -496,14 +532,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
app.name = self._get_app_name(app.url, soup)
|
||||
|
||||
if not app.description:
|
||||
desc_tag = soup.head.find('meta', attrs={'name': 'description'})
|
||||
|
||||
if desc_tag:
|
||||
app.description = desc_tag.get('content')
|
||||
|
||||
if not app.description:
|
||||
desc_tag = soup.find('title')
|
||||
app.description = desc_tag.text if desc_tag else app.url
|
||||
app.description = self._get_app_description(app.url, soup)
|
||||
|
||||
find_url = not app.icon_url or (app.icon_url and not self.http_client.exists(app.icon_url))
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class WebApplication(SoftwarePackage):
|
||||
self.installation_dir = installation_dir
|
||||
self.desktop_entry = desktop_entry
|
||||
self.set_custom_icon(custom_icon)
|
||||
self.preset_categories = preset_options
|
||||
self.preset_options = preset_options
|
||||
|
||||
def has_history(self):
|
||||
return False
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
gem.web.info=It allows to install Web applications on the system through they addresses ( URLs )
|
||||
gem.web.install.warning=This app it is not officially distributed by its domain owner
|
||||
web.environment.install=Installing {}
|
||||
web.waiting.env_updater=Updating environment
|
||||
web.env.checking=Checking the Web installation environment
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
gem.web.info=Permite instalar aplicações Web no seu sistema através dos seus endereços ( URLs )
|
||||
gem.web.install.warning=Esse aplicativo não é oficialmente distribuído pelo proprietário do domínio
|
||||
web.environment.nativefier=Instalando {}
|
||||
web.waiting.env_updater=Atualizando ambiente
|
||||
web.env.checking=Verificando o ambiente de instalação Web
|
||||
|
||||
@@ -21,6 +21,9 @@ whatsapp:
|
||||
priority: 3
|
||||
url: https://web.whatsapp.com
|
||||
category: Network
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
telegram:
|
||||
name: Telegram
|
||||
@@ -28,6 +31,7 @@ telegram:
|
||||
url: https://web.telegram.org
|
||||
category: Network
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
slack:
|
||||
@@ -35,6 +39,8 @@ slack:
|
||||
priority: 3
|
||||
url: https://slack.com
|
||||
category: Network
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
|
||||
office:
|
||||
@@ -79,6 +85,7 @@ ms_outlook:
|
||||
category: Network
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
ms_drive:
|
||||
name: Microsoft One Drive
|
||||
@@ -110,6 +117,7 @@ google-keep:
|
||||
category: Utility
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
google-cal:
|
||||
name: Google Calendar
|
||||
@@ -119,6 +127,7 @@ google-cal:
|
||||
category: Utility
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
google-sheets:
|
||||
name: Google Sheets
|
||||
@@ -154,6 +163,7 @@ google-hangouts:
|
||||
category: Network
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
gmail:
|
||||
name: GMail
|
||||
@@ -163,6 +173,7 @@ gmail:
|
||||
category: Network
|
||||
options:
|
||||
- allow_urls
|
||||
- tray_min
|
||||
|
||||
mega:
|
||||
name: Mega
|
||||
|
||||
Reference in New Issue
Block a user