mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[wgem] fix icon path definition and caching | param --reset cleaning the web environment as well
This commit is contained in:
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
|
## [0.8.0] 2019-12
|
||||||
|
### Features
|
||||||
|
- Native Web applications support:
|
||||||
|
- if an URL is typed in the search, a native web application result will be displayed in the results table.
|
||||||
|
- 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
|
||||||
|
|
||||||
|
|
||||||
## [0.7.4] 2019-12-09
|
## [0.7.4] 2019-12-09
|
||||||
### Improvements
|
### Improvements
|
||||||
- AUR
|
- AUR
|
||||||
|
|||||||
@@ -265,3 +265,9 @@ class SoftwareManager(ABC):
|
|||||||
:return: screenshot urls for the given package
|
:return: screenshot urls for the given package
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def clear_data(self):
|
||||||
|
"""
|
||||||
|
Removes all data created by the SoftwareManager instance
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|||||||
18
bauh/app.py
18
bauh/app.py
@@ -29,10 +29,6 @@ def main():
|
|||||||
logger = logs.new_logger(__app_name__, bool(args.logs))
|
logger = logs.new_logger(__app_name__, bool(args.logs))
|
||||||
app_args.validate(args, logger)
|
app_args.validate(args, logger)
|
||||||
|
|
||||||
if args.reset:
|
|
||||||
util.clean_app_files()
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
i18n_key, current_i18n = translation.get_locale_keys(args.locale)
|
i18n_key, current_i18n = translation.get_locale_keys(args.locale)
|
||||||
default_i18n = translation.get_locale_keys(DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {}
|
default_i18n = translation.get_locale_keys(DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {}
|
||||||
i18n = I18n(current_i18n, default_i18n)
|
i18n = I18n(current_i18n, default_i18n)
|
||||||
@@ -56,6 +52,15 @@ def main():
|
|||||||
i18n, http_client))
|
i18n, http_client))
|
||||||
user_config = config.read()
|
user_config = config.read()
|
||||||
|
|
||||||
|
managers = gems.load_managers(context=context, locale=i18n_key, config=user_config, default_locale=DEFAULT_I18N_KEY)
|
||||||
|
|
||||||
|
if args.reset:
|
||||||
|
util.clean_app_files(managers)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
manager = GenericSoftwareManager(managers, context=context, app_args=args)
|
||||||
|
manager.prepare()
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
app.setApplicationName(__app_name__)
|
app.setApplicationName(__app_name__)
|
||||||
app.setApplicationVersion(__version__)
|
app.setApplicationVersion(__version__)
|
||||||
@@ -67,11 +72,6 @@ def main():
|
|||||||
if app.style().objectName().lower() not in {'fusion', 'breeze'}:
|
if app.style().objectName().lower() not in {'fusion', 'breeze'}:
|
||||||
app.setStyle('Fusion')
|
app.setStyle('Fusion')
|
||||||
|
|
||||||
managers = gems.load_managers(context=context, locale=i18n_key, config=user_config, default_locale=DEFAULT_I18N_KEY)
|
|
||||||
|
|
||||||
manager = GenericSoftwareManager(managers, context=context, app_args=args)
|
|
||||||
manager.prepare()
|
|
||||||
|
|
||||||
manage_window = ManageWindow(i18n=i18n,
|
manage_window = ManageWindow(i18n=i18n,
|
||||||
manager=manager,
|
manager=manager,
|
||||||
icon_cache=icon_cache,
|
icon_cache=icon_cache,
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR
|
|||||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home())
|
WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home())
|
||||||
INSTALLED_PATH = '{}/installed'.format(WEB_PATH)
|
INSTALLED_PATH = '{}/installed'.format(WEB_PATH)
|
||||||
BIN_PATH = '{}/runtime'.format(WEB_PATH)
|
ENV_PATH = '{}/env'.format(WEB_PATH)
|
||||||
NODE_DIR_PATH = '{}/node'.format(BIN_PATH)
|
NODE_DIR_PATH = '{}/node'.format(ENV_PATH)
|
||||||
NODE_PATHS = {NODE_DIR_PATH + '/bin'}
|
NODE_PATHS = {NODE_DIR_PATH + '/bin'}
|
||||||
NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH)
|
NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH)
|
||||||
NPM_BIN_PATH = '{}/bin/npm'.format(NODE_DIR_PATH)
|
NPM_BIN_PATH = '{}/bin/npm'.format(NODE_DIR_PATH)
|
||||||
NODE_MODULES_PATH = '{}/node_modules'.format(BIN_PATH)
|
NODE_MODULES_PATH = '{}/node_modules'.format(ENV_PATH)
|
||||||
NATIVEFIER_BIN_PATH = '{}/.bin/nativefier'.format(NODE_MODULES_PATH)
|
NATIVEFIER_BIN_PATH = '{}/.bin/nativefier'.format(NODE_MODULES_PATH)
|
||||||
ELECTRON_PATH = '{}/.cache/electron'.format(HOME_PATH)
|
ELECTRON_PATH = '{}/.cache/electron'.format(HOME_PATH)
|
||||||
ELECTRON_DOWNLOAD_URL = 'https://github.com/electron/electron/releases/download/v{version}/electron-v{version}-linux-{arch}.zip'
|
ELECTRON_DOWNLOAD_URL = 'https://github.com/electron/electron/releases/download/v{version}/electron-v{version}-linux-{arch}.zip'
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from threading import Thread
|
|||||||
from typing import List, Type, Set, Tuple
|
from typing import List, Type, Set, Tuple
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from colorama import Fore
|
||||||
|
|
||||||
from bauh.api.abstract.context import ApplicationContext
|
from bauh.api.abstract.context import ApplicationContext
|
||||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
||||||
@@ -22,7 +23,8 @@ from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOp
|
|||||||
from bauh.api.constants import DESKTOP_ENTRIES_DIR
|
from bauh.api.constants import DESKTOP_ENTRIES_DIR
|
||||||
from bauh.commons.html import bold
|
from bauh.commons.html import bold
|
||||||
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
|
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, environment
|
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN, environment, \
|
||||||
|
ENV_PATH
|
||||||
from bauh.gems.web.environment import EnvironmentUpdater
|
from bauh.gems.web.environment import EnvironmentUpdater
|
||||||
from bauh.gems.web.model import WebApplication
|
from bauh.gems.web.model import WebApplication
|
||||||
|
|
||||||
@@ -478,3 +480,14 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
|
|
||||||
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def clear_data(self):
|
||||||
|
if os.path.exists(ENV_PATH):
|
||||||
|
print('[bauh][web] Deleting directory {}'.format(ENV_PATH))
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.rmtree(ENV_PATH)
|
||||||
|
print('{}[bauh][web] Directory {} deleted{}'.format(Fore.YELLOW, ENV_PATH, Fore.RESET))
|
||||||
|
except:
|
||||||
|
print('{}[bauh][web] An exception has happened when deleting {}{}'.format(Fore.RED, ENV_PATH, Fore.RESET))
|
||||||
|
traceback.print_exc()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ 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
|
||||||
from bauh.commons.system import SimpleProcess, ProcessHandler, run_cmd
|
from bauh.commons.system import SimpleProcess, ProcessHandler, run_cmd
|
||||||
from bauh.gems.web import BIN_PATH, NODE_DIR_PATH, NODE_BIN_PATH, NODE_MODULES_PATH, NATIVEFIER_BIN_PATH, \
|
from bauh.gems.web import ENV_PATH, NODE_DIR_PATH, NODE_BIN_PATH, NODE_MODULES_PATH, NATIVEFIER_BIN_PATH, \
|
||||||
ELECTRON_PATH, ELECTRON_DOWNLOAD_URL, ELECTRON_SHA256_URL, URL_ENVIRONMENT_SETTINGS, NPM_BIN_PATH, NODE_PATHS
|
ELECTRON_PATH, ELECTRON_DOWNLOAD_URL, ELECTRON_SHA256_URL, URL_ENVIRONMENT_SETTINGS, NPM_BIN_PATH, NODE_PATHS
|
||||||
from bauh.view.util.translation import I18n
|
from bauh.view.util.translation import I18n
|
||||||
|
|
||||||
@@ -29,8 +29,8 @@ class EnvironmentUpdater:
|
|||||||
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))
|
||||||
|
|
||||||
tarf_path = '{}/{}'.format(BIN_PATH, version_url.split('/')[-1])
|
tarf_path = '{}/{}'.format(ENV_PATH, version_url.split('/')[-1])
|
||||||
downloaded = self.file_downloader.download(version_url, watcher=watcher, output_path=tarf_path, cwd=BIN_PATH)
|
downloaded = self.file_downloader.download(version_url, watcher=watcher, output_path=tarf_path, cwd=ENV_PATH)
|
||||||
|
|
||||||
if not downloaded:
|
if not downloaded:
|
||||||
self.logger.error("Could not download '{}'. Aborting...".format(version_url))
|
self.logger.error("Could not download '{}'. Aborting...".format(version_url))
|
||||||
@@ -38,9 +38,9 @@ class EnvironmentUpdater:
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tf = tarfile.open(tarf_path)
|
tf = tarfile.open(tarf_path)
|
||||||
tf.extractall(path=BIN_PATH)
|
tf.extractall(path=ENV_PATH)
|
||||||
|
|
||||||
extracted_file = '{}/{}'.format(BIN_PATH, tf.getnames()[0])
|
extracted_file = '{}/{}'.format(ENV_PATH, tf.getnames()[0])
|
||||||
|
|
||||||
os.rename(extracted_file, NODE_DIR_PATH)
|
os.rename(extracted_file, NODE_DIR_PATH)
|
||||||
return True
|
return True
|
||||||
@@ -55,7 +55,7 @@ class EnvironmentUpdater:
|
|||||||
self.logger.error('Could not delete file {}'.format(tarf_path))
|
self.logger.error('Could not delete file {}'.format(tarf_path))
|
||||||
|
|
||||||
def update_node(self, version: str, version_url: str, watcher: ProcessWatcher = None) -> bool:
|
def update_node(self, version: str, version_url: str, watcher: ProcessWatcher = None) -> bool:
|
||||||
Path(BIN_PATH).mkdir(parents=True, exist_ok=True)
|
Path(ENV_PATH).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if not os.path.exists(NODE_DIR_PATH):
|
if not os.path.exists(NODE_DIR_PATH):
|
||||||
return self._download_and_install(version=version, version_url=version_url, watcher=watcher)
|
return self._download_and_install(version=version, version_url=version_url, watcher=watcher)
|
||||||
@@ -92,7 +92,7 @@ class EnvironmentUpdater:
|
|||||||
if handler and handler.watcher:
|
if handler and handler.watcher:
|
||||||
handler.watcher.change_substatus(self.i18n['web.environment.install'].format(bold('nativefier')))
|
handler.watcher.change_substatus(self.i18n['web.environment.install'].format(bold('nativefier')))
|
||||||
|
|
||||||
proc = SimpleProcess([NPM_BIN_PATH, 'install', 'nativefier@{}'.format(version)], cwd=BIN_PATH, extra_paths=NODE_PATHS)
|
proc = SimpleProcess([NPM_BIN_PATH, 'install', 'nativefier@{}'.format(version)], cwd=ENV_PATH, extra_paths=NODE_PATHS)
|
||||||
|
|
||||||
if handler:
|
if handler:
|
||||||
installed = handler.handle_simple(proc)[0]
|
installed = handler.handle_simple(proc)[0]
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ class WebApplication(SoftwarePackage):
|
|||||||
def get_disk_icon_path(self) -> str:
|
def get_disk_icon_path(self) -> str:
|
||||||
if self.custom_icon:
|
if self.custom_icon:
|
||||||
return self.custom_icon
|
return self.custom_icon
|
||||||
else:
|
|
||||||
super(WebApplication, self).get_disk_icon_path()
|
if self.installation_dir:
|
||||||
|
return '{}/resources/app/icon.png'.format(self.installation_dir)
|
||||||
|
|
||||||
def is_application(self):
|
def is_application(self):
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ class AppsTable(QTableWidget):
|
|||||||
col_name = self.item(idx, 0)
|
col_name = self.item(idx, 0)
|
||||||
col_name.setIcon(icon_data['icon'])
|
col_name.setIcon(icon_data['icon'])
|
||||||
|
|
||||||
if self.disk_cache and app.model.supports_disk_cache():
|
if self.disk_cache and app.model.supports_disk_cache() and app.model.get_disk_icon_path():
|
||||||
if not icon_was_cached or not os.path.exists(app.model.get_disk_icon_path()):
|
if not icon_was_cached or not os.path.exists(app.model.get_disk_icon_path()):
|
||||||
self.window.manager.cache_to_disk(pkg=app.model, icon_bytes=icon_data['bytes'], only_icon=True)
|
self.window.manager.cache_to_disk(pkg=app.model, icon_bytes=icon_data['bytes'], only_icon=True)
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from PyQt5.QtCore import QCoreApplication
|
from PyQt5.QtCore import QCoreApplication
|
||||||
|
from colorama import Fore
|
||||||
|
|
||||||
from bauh import __app_name__
|
from bauh import __app_name__
|
||||||
|
from bauh.api.abstract.controller import SoftwareManager
|
||||||
from bauh.api.constants import CACHE_PATH, CONFIG_PATH
|
from bauh.api.constants import CACHE_PATH, CONFIG_PATH
|
||||||
from bauh.commons.system import run_cmd
|
from bauh.commons.system import run_cmd
|
||||||
from bauh.view.util import resource
|
from bauh.view.util import resource
|
||||||
@@ -40,10 +44,20 @@ def get_distro():
|
|||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
|
|
||||||
def clean_app_files():
|
def clean_app_files(managers: List[SoftwareManager]):
|
||||||
print('[bauh] Cleaning configuration and cache files')
|
print('[bauh] Cleaning configuration and cache files')
|
||||||
for path in (CACHE_PATH, CONFIG_PATH):
|
for path in (CACHE_PATH, CONFIG_PATH):
|
||||||
print('[bauh] Deleting directory {}'.format(path))
|
print('[bauh] Deleting directory {}'.format(path))
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
print('{}[bauh] Directory {} deleted{}'.format(Fore.YELLOW, path, Fore.RESET))
|
||||||
|
except:
|
||||||
|
print('{}[bauh] An exception has happened when deleting {}{}'.format(Fore.RED, path, Fore.RESET))
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
if managers:
|
||||||
|
for m in managers:
|
||||||
|
m.clear_data()
|
||||||
|
|
||||||
print('[bauh] Cleaning finished')
|
print('[bauh] Cleaning finished')
|
||||||
|
|||||||
Reference in New Issue
Block a user