remove unnecessary use of os.popen
This commit is contained in:
parent
38dcb4843b
commit
4382601aa2
2 changed files with 5 additions and 17 deletions
8
setup.py
8
setup.py
|
@ -6,7 +6,7 @@
|
|||
For more information, please refer to the repository (https://github.com/developomp/setup).
|
||||
"""
|
||||
|
||||
from os import system, geteuid, popen
|
||||
from os import system, geteuid
|
||||
from os.path import exists
|
||||
from shutil import rmtree
|
||||
import sys
|
||||
|
@ -22,12 +22,8 @@ tmp_dir = "/tmp/com.developomp.setup"
|
|||
#
|
||||
|
||||
|
||||
def run_and_return(command: str) -> list[str]:
|
||||
return popen(command).readlines()
|
||||
|
||||
|
||||
def command_exists(command: str) -> bool:
|
||||
return len(run_and_return(f"command -v {command}")) == 1
|
||||
return system(f"command -v {command} &> /dev/null") == 0
|
||||
|
||||
|
||||
def cleanup() -> None:
|
||||
|
|
14
src/util.py
14
src/util.py
|
@ -1,5 +1,5 @@
|
|||
from importlib.machinery import SourceFileLoader
|
||||
from os import system, makedirs, popen, remove
|
||||
from os import system, makedirs, remove
|
||||
from os.path import dirname, exists
|
||||
from tqdm.auto import tqdm
|
||||
from pathlib import Path
|
||||
|
@ -12,14 +12,6 @@ from src.log import error, log
|
|||
import src.constants
|
||||
|
||||
|
||||
def run_and_return(command: str) -> list[str]:
|
||||
"""Runs command in system shell and return the result.
|
||||
This is a blocking function.
|
||||
Use this if you want to get the output of the command."""
|
||||
|
||||
return popen(command).readlines()
|
||||
|
||||
|
||||
def paru_install(packages: str | list[str]) -> None:
|
||||
"""
|
||||
Download arch linux packages (including AUR).
|
||||
|
@ -58,7 +50,7 @@ def appimage_install(file_url: str, file_name: str) -> None:
|
|||
download_path = f"{Path.home()}/Applications/{file_name}.AppImage"
|
||||
|
||||
# install AppImageLauncher if it's not installed already
|
||||
if system("command -v AppImageLauncher &> /dev/null"):
|
||||
if not command_exists("AppImageLauncher"):
|
||||
paru_install("appimagelauncher")
|
||||
|
||||
log(f" Downloading AppImage file to {download_path}")
|
||||
|
@ -188,4 +180,4 @@ def command_exists(command: str) -> bool:
|
|||
"""Check if a command can be found in the current default shell.
|
||||
A copy of this function also exists in `setup.py`."""
|
||||
|
||||
return len(run_and_return(f"command -v {command}")) == 1
|
||||
return system(f"command -v {command} &> /dev/null") == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue