mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[snap.snap] refactoring: 'BASE_CMD' constant removed
This commit is contained in:
@@ -6,22 +6,20 @@ from typing import Tuple, Optional
|
|||||||
|
|
||||||
from bauh.commons.system import SimpleProcess
|
from bauh.commons.system import SimpleProcess
|
||||||
|
|
||||||
BASE_CMD = 'snap'
|
|
||||||
|
|
||||||
|
|
||||||
def is_installed() -> bool:
|
def is_installed() -> bool:
|
||||||
return bool(shutil.which(BASE_CMD))
|
return bool(shutil.which('snap'))
|
||||||
|
|
||||||
|
|
||||||
def uninstall_and_stream(app_name: str, root_password: Optional[str]) -> SimpleProcess:
|
def uninstall_and_stream(app_name: str, root_password: Optional[str]) -> SimpleProcess:
|
||||||
return SimpleProcess(cmd=[BASE_CMD, 'remove', app_name],
|
return SimpleProcess(cmd=['snap', 'remove', app_name],
|
||||||
root_password=root_password,
|
root_password=root_password,
|
||||||
shell=True)
|
shell=True)
|
||||||
|
|
||||||
|
|
||||||
def install_and_stream(app_name: str, confinement: str, root_password: Optional[str], channel: Optional[str] = None) -> SimpleProcess:
|
def install_and_stream(app_name: str, confinement: str, root_password: Optional[str], channel: Optional[str] = None) -> SimpleProcess:
|
||||||
|
|
||||||
install_cmd = [BASE_CMD, 'install', app_name] # default
|
install_cmd = ['snap', 'install', app_name] # default
|
||||||
|
|
||||||
if confinement == 'classic':
|
if confinement == 'classic':
|
||||||
install_cmd.append('--classic')
|
install_cmd.append('--classic')
|
||||||
@@ -33,13 +31,13 @@ def install_and_stream(app_name: str, confinement: str, root_password: Optional[
|
|||||||
|
|
||||||
|
|
||||||
def downgrade_and_stream(app_name: str, root_password: Optional[str]) -> SimpleProcess:
|
def downgrade_and_stream(app_name: str, root_password: Optional[str]) -> SimpleProcess:
|
||||||
return SimpleProcess(cmd=[BASE_CMD, 'revert', app_name],
|
return SimpleProcess(cmd=['snap', 'revert', app_name],
|
||||||
root_password=root_password,
|
root_password=root_password,
|
||||||
shell=True)
|
shell=True)
|
||||||
|
|
||||||
|
|
||||||
def refresh_and_stream(app_name: str, root_password: Optional[str], channel: Optional[str] = None) -> SimpleProcess:
|
def refresh_and_stream(app_name: str, root_password: Optional[str], channel: Optional[str] = None) -> SimpleProcess:
|
||||||
cmd = [BASE_CMD, 'refresh', app_name]
|
cmd = ['snap', 'refresh', app_name]
|
||||||
|
|
||||||
if channel:
|
if channel:
|
||||||
cmd.append(f'--channel={channel}')
|
cmd.append(f'--channel={channel}')
|
||||||
@@ -51,12 +49,12 @@ def refresh_and_stream(app_name: str, root_password: Optional[str], channel: Opt
|
|||||||
|
|
||||||
|
|
||||||
def run(cmd: str):
|
def run(cmd: str):
|
||||||
subprocess.Popen([f'{BASE_CMD} run {cmd}'], shell=True, env={**os.environ})
|
subprocess.Popen([f'snap run {cmd}'], shell=True, env={**os.environ})
|
||||||
|
|
||||||
|
|
||||||
def is_api_available() -> Tuple[bool, str]:
|
def is_api_available() -> Tuple[bool, str]:
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
for o in SimpleProcess([BASE_CMD, 'search']).instance.stdout:
|
for o in SimpleProcess(['snap', 'search']).instance.stdout:
|
||||||
if o:
|
if o:
|
||||||
output.write(o.decode())
|
output.write(o.decode())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user