mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 16:24:16 +02:00
[wgem] installed size on the info window
This commit is contained in:
@@ -4,7 +4,7 @@ import traceback
|
||||
|
||||
import requests
|
||||
|
||||
SIZE_MULTIPLIERS = ((0.001, 'Kb'), (0.000001, 'Mb'), (0.000000001, 'Gb'), (0.000000000001, 'Tb'))
|
||||
from bauh.commons import system
|
||||
|
||||
|
||||
class HttpClient:
|
||||
@@ -64,10 +64,4 @@ class HttpClient:
|
||||
size = res.headers.get('Content-Length')
|
||||
|
||||
if size is not None:
|
||||
size = int(size)
|
||||
for m in SIZE_MULTIPLIERS:
|
||||
size_str = str(size * m[0])
|
||||
|
||||
if len(size_str.split('.')[0]) < 4:
|
||||
return '{0:.2f}'.format(float(size_str)) + ' ' + m[1]
|
||||
return str(size)
|
||||
return system.get_human_size_str(size)
|
||||
|
||||
@@ -22,6 +22,8 @@ if GLOBAL_PY_LIBS not in PATH:
|
||||
|
||||
USE_GLOBAL_INTERPRETER = bool(os.getenv('VIRTUAL_ENV'))
|
||||
|
||||
SIZE_MULTIPLIERS = ((0.001, 'Kb'), (0.000001, 'Mb'), (0.000000001, 'Gb'), (0.000000000001, 'Tb'))
|
||||
|
||||
|
||||
def gen_env(global_interpreter: bool, lang: str = DEFAULT_LANG) -> dict:
|
||||
res = {}
|
||||
@@ -219,3 +221,25 @@ def new_root_subprocess(cmd: List[str], root_password: str, cwd: str = '.',
|
||||
|
||||
def notify_user(msg: str, app_name: str, icon_path: str):
|
||||
os.system("notify-send -a {} {} '{}'".format(app_name, "-i {}".format(icon_path) if icon_path else '', msg))
|
||||
|
||||
|
||||
def get_dir_size(start_path='.'):
|
||||
total_size = 0
|
||||
for dirpath, dirnames, filenames in os.walk(start_path):
|
||||
for f in filenames:
|
||||
fp = os.path.join(dirpath, f)
|
||||
|
||||
if not os.path.islink(fp):
|
||||
total_size += os.path.getsize(fp)
|
||||
|
||||
return total_size
|
||||
|
||||
|
||||
def get_human_size_str(size) -> str:
|
||||
int_size = int(size)
|
||||
for m in SIZE_MULTIPLIERS:
|
||||
size_str = str(int_size * m[0])
|
||||
|
||||
if len(size_str.split('.')[0]) < 4:
|
||||
return '{0:.2f}'.format(float(size_str)) + ' ' + m[1]
|
||||
return str(int_size)
|
||||
|
||||
@@ -16,7 +16,7 @@ from bauh.api.abstract.handler import ProcessWatcher
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
|
||||
from bauh.api.abstract.view import MessageType
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import ProcessHandler
|
||||
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
|
||||
from bauh.gems.web.environment import EnvironmentUpdater
|
||||
from bauh.gems.web.model import WebApplication
|
||||
@@ -150,6 +150,10 @@ class WebApplicationManager(SoftwareManager):
|
||||
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()
|
||||
|
||||
if os.path.exists(pkg.installation_dir):
|
||||
info['8_size'] = get_human_size_str(get_dir_size(pkg.installation_dir))
|
||||
|
||||
return info
|
||||
|
||||
def get_history(self, pkg: SoftwarePackage) -> PackageHistory:
|
||||
|
||||
@@ -16,4 +16,5 @@ 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.7_icon_path=icon
|
||||
web.info.8_size=size
|
||||
@@ -16,4 +16,5 @@ 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.7_icon_path=ícone
|
||||
web.info.8_size=tamanho
|
||||
Reference in New Issue
Block a user