mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 21:44:16 +02:00
[web] improvement: Electron cache moved to ~/.local/share/bauh/web/env/electron
This commit is contained in:
@@ -18,6 +18,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.22/missing_type_dep.png">
|
||||
</p>
|
||||
|
||||
- Web
|
||||
- the Electron builds cache directory has been moved to the environment directory `~/.local/share/bauh/web/env/electron`
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
@@ -68,7 +68,7 @@ class SimpleProcess:
|
||||
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG, root_password: str = None,
|
||||
extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None,
|
||||
shell: bool = False,
|
||||
success_phrases: Set[str] = None):
|
||||
success_phrases: Set[str] = None, extra_env: Optional[Dict[str, str]] = None):
|
||||
pwdin, final_cmd = None, []
|
||||
|
||||
self.shell = shell
|
||||
@@ -78,13 +78,21 @@ class SimpleProcess:
|
||||
|
||||
final_cmd.extend(cmd)
|
||||
|
||||
self.instance = self._new(final_cmd, cwd, global_interpreter, lang, stdin=pwdin, extra_paths=extra_paths)
|
||||
self.instance = self._new(final_cmd, cwd, global_interpreter, lang, stdin=pwdin, extra_paths=extra_paths, extra_env=extra_env)
|
||||
self.expected_code = expected_code
|
||||
self.error_phrases = error_phrases
|
||||
self.wrong_error_phrases = wrong_error_phrases
|
||||
self.success_phrases = success_phrases
|
||||
|
||||
def _new(self, cmd: List[str], cwd: str, global_interpreter: bool, lang: str, stdin = None, extra_paths: Set[str] = None) -> subprocess.Popen:
|
||||
def _new(self, cmd: List[str], cwd: str, global_interpreter: bool, lang: str, stdin = None,
|
||||
extra_paths: Set[str] = None, extra_env: Optional[Dict[str, str]] = None) -> subprocess.Popen:
|
||||
|
||||
env = gen_env(global_interpreter, lang, extra_paths=extra_paths)
|
||||
|
||||
if extra_env:
|
||||
for var, val in extra_env.items():
|
||||
if var not in env:
|
||||
env[var] = val
|
||||
|
||||
args = {
|
||||
"stdout": subprocess.PIPE,
|
||||
@@ -92,7 +100,7 @@ class SimpleProcess:
|
||||
"stdin": stdin if stdin else subprocess.DEVNULL,
|
||||
"bufsize": -1,
|
||||
"cwd": cwd,
|
||||
"env": gen_env(global_interpreter, lang, extra_paths=extra_paths),
|
||||
"env": env,
|
||||
"shell": self.shell
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH)
|
||||
NPM_BIN_PATH = '{}/bin/npm'.format(NODE_DIR_PATH)
|
||||
NODE_MODULES_PATH = '{}/node_modules'.format(ENV_PATH)
|
||||
NATIVEFIER_BIN_PATH = '{}/.bin/nativefier'.format(NODE_MODULES_PATH)
|
||||
ELECTRON_PATH = '{}/.cache/electron'.format(str(Path.home()))
|
||||
ELECTRON_CACHE_DIR = f'{ENV_PATH}/electron'
|
||||
ELECTRON_DOWNLOAD_URL = 'https://github.com/electron/electron/releases/download/v{version}/electron-v{version}-linux-{arch}.zip'
|
||||
ELECTRON_SHA256_URL = 'https://github.com/electron/electron/releases/download/v{version}/SHASUMS256.txt'
|
||||
ELECTRON_WIDEVINE_URL = 'https://github.com/castlabs/electron-releases/releases/download/v{version}-wvvmp/electron-v{version}-wvvmp-linux-{arch}.zip'
|
||||
|
||||
@@ -32,7 +32,7 @@ from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str, SimpleProcess
|
||||
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN, ENV_PATH, UA_CHROME, \
|
||||
SUGGESTIONS_CACHE_FILE, ROOT_DIR, TEMP_PATH, FIXES_PATH, ELECTRON_PATH, \
|
||||
SUGGESTIONS_CACHE_FILE, ROOT_DIR, TEMP_PATH, FIXES_PATH, ELECTRON_CACHE_DIR, \
|
||||
get_icon_path
|
||||
from bauh.gems.web.config import WebConfigManager
|
||||
from bauh.gems.web.environment import EnvironmentUpdater, EnvironmentComponent
|
||||
@@ -93,7 +93,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
handler = ProcessHandler(watcher)
|
||||
|
||||
success = True
|
||||
for path in (ENV_PATH, ELECTRON_PATH):
|
||||
for path in (ENV_PATH, ELECTRON_CACHE_DIR):
|
||||
self.logger.info("Checking path '{}'".format(path))
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
|
||||
@@ -20,7 +20,7 @@ from bauh.commons import system
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SimpleProcess, ProcessHandler
|
||||
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_CACHE_DIR, ELECTRON_DOWNLOAD_URL, ELECTRON_SHA256_URL, URL_ENVIRONMENT_SETTINGS, NPM_BIN_PATH, NODE_PATHS, \
|
||||
nativefier, ELECTRON_WIDEVINE_URL, ELECTRON_WIDEVINE_SHA256_URL, \
|
||||
ENVIRONMENT_SETTINGS_CACHED_FILE, ENVIRONMENT_SETTINGS_TS_FILE, get_icon_path, NATIVEFIER_BASE_URL
|
||||
from bauh.gems.web.model import WebApplication
|
||||
@@ -192,7 +192,7 @@ class EnvironmentUpdater:
|
||||
return os.path.exists(NATIVEFIER_BIN_PATH)
|
||||
|
||||
def download_electron(self, version: str, url: str, widevine: bool, watcher: ProcessWatcher) -> bool:
|
||||
Path(ELECTRON_PATH).mkdir(parents=True, exist_ok=True)
|
||||
Path(ELECTRON_CACHE_DIR).mkdir(parents=True, exist_ok=True)
|
||||
self.logger.info("Downloading Electron {}".format(version))
|
||||
|
||||
electron_path = self._get_electron_file_path(url=url, relative=False)
|
||||
@@ -204,7 +204,7 @@ class EnvironmentUpdater:
|
||||
type_=MessageType.ERROR)
|
||||
return False
|
||||
|
||||
return self.file_downloader.download(file_url=url, watcher=watcher, output_path=electron_path, cwd=ELECTRON_PATH)
|
||||
return self.file_downloader.download(file_url=url, watcher=watcher, output_path=electron_path, cwd=ELECTRON_CACHE_DIR)
|
||||
|
||||
def download_electron_sha256(self, version: str, url: str, widevine: bool, watcher: ProcessWatcher) -> bool:
|
||||
self.logger.info("Downloading Electron {} sha526".format(version))
|
||||
@@ -218,7 +218,7 @@ class EnvironmentUpdater:
|
||||
type_=MessageType.ERROR)
|
||||
return False
|
||||
|
||||
return self.file_downloader.download(file_url=url, watcher=watcher, output_path=sha256_path, cwd=ELECTRON_PATH)
|
||||
return self.file_downloader.download(file_url=url, watcher=watcher, output_path=sha256_path, cwd=ELECTRON_CACHE_DIR)
|
||||
|
||||
def _get_electron_url(self, version: str, is_x86_x64_arch: bool, widevine: bool) -> str:
|
||||
arch = 'x64' if is_x86_x64_arch else 'ia32'
|
||||
@@ -235,16 +235,16 @@ class EnvironmentUpdater:
|
||||
|
||||
def _get_electron_file_path(self, url: str, relative: bool) -> str:
|
||||
file_path = url.replace(':', '').replace('/', '') + '/' + url.split('/')[-1]
|
||||
return '{}/{}'.format(ELECTRON_PATH, file_path) if not relative else file_path
|
||||
return f'{ELECTRON_CACHE_DIR}/{file_path}' if not relative else file_path
|
||||
|
||||
def check_electron_installed(self, version: str, is_x86_x64_arch: bool, widevine: bool) -> Dict[str, bool]:
|
||||
self.logger.info("Checking if Electron {} (widevine={}) is installed".format(version, widevine))
|
||||
res = {'electron': False, 'sha256': False}
|
||||
|
||||
if not os.path.exists(ELECTRON_PATH):
|
||||
self.logger.info("The Electron folder {} was not found".format(ELECTRON_PATH))
|
||||
if not os.path.exists(ELECTRON_CACHE_DIR):
|
||||
self.logger.info(f"Electron cache directory {ELECTRON_CACHE_DIR} not found")
|
||||
else:
|
||||
files = {f.split(ELECTRON_PATH + '/')[1] for f in glob.glob(ELECTRON_PATH + '/**', recursive=True) if os.path.isfile(f)}
|
||||
files = {f.split(ELECTRON_CACHE_DIR + '/')[1] for f in glob.glob(ELECTRON_CACHE_DIR + '/**', recursive=True) if os.path.isfile(f)}
|
||||
|
||||
if files:
|
||||
electron_url = self._get_electron_url(version, is_x86_x64_arch, widevine)
|
||||
@@ -259,7 +259,7 @@ class EnvironmentUpdater:
|
||||
sha_path = self._get_electron_file_path(url=sha_url, relative=True)
|
||||
res['sha256'] = sha_path in files
|
||||
else:
|
||||
self.logger.info('No Electron file found in {}'.format(ELECTRON_PATH))
|
||||
self.logger.info(f"No Electron file found in '{ELECTRON_CACHE_DIR}'")
|
||||
|
||||
for att in ('electron', 'sha256'):
|
||||
if res[att]:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
import shutil
|
||||
from typing import List, Optional
|
||||
|
||||
from bauh.commons.system import SimpleProcess, run_cmd
|
||||
from bauh.gems.web import NATIVEFIER_BIN_PATH, NODE_PATHS
|
||||
from bauh.gems.web import NATIVEFIER_BIN_PATH, NODE_PATHS, ELECTRON_CACHE_DIR
|
||||
|
||||
|
||||
def install(url: str, name: str, output_dir: str, electron_version: Optional[str], cwd: str, system: bool, extra_options: List[str] = None) -> SimpleProcess:
|
||||
@@ -15,7 +16,8 @@ def install(url: str, name: str, output_dir: str, electron_version: Optional[str
|
||||
if extra_options:
|
||||
cmd.extend(extra_options)
|
||||
|
||||
return SimpleProcess(cmd, cwd=cwd, extra_paths=NODE_PATHS if not system else None)
|
||||
return SimpleProcess(cmd, cwd=cwd, extra_paths=NODE_PATHS if not system else None,
|
||||
extra_env={'XDG_CACHE_HOME': os.path.dirname(ELECTRON_CACHE_DIR)})
|
||||
|
||||
|
||||
def is_available() -> bool:
|
||||
|
||||
Reference in New Issue
Block a user