1
0
Fork 0

remove unnecessary use of os.popen

This commit is contained in:
Kim, Jimin 2022-11-13 16:30:48 +09:00
parent 38dcb4843b
commit 4382601aa2
2 changed files with 5 additions and 17 deletions

View file

@ -6,7 +6,7 @@
For more information, please refer to the repository (https://github.com/developomp/setup). 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 os.path import exists
from shutil import rmtree from shutil import rmtree
import sys 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: 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: def cleanup() -> None:

View file

@ -1,5 +1,5 @@
from importlib.machinery import SourceFileLoader 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 os.path import dirname, exists
from tqdm.auto import tqdm from tqdm.auto import tqdm
from pathlib import Path from pathlib import Path
@ -12,14 +12,6 @@ from src.log import error, log
import src.constants 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: def paru_install(packages: str | list[str]) -> None:
""" """
Download arch linux packages (including AUR). 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" download_path = f"{Path.home()}/Applications/{file_name}.AppImage"
# install AppImageLauncher if it's not installed already # install AppImageLauncher if it's not installed already
if system("command -v AppImageLauncher &> /dev/null"): if not command_exists("AppImageLauncher"):
paru_install("appimagelauncher") paru_install("appimagelauncher")
log(f" Downloading AppImage file to {download_path}") 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. """Check if a command can be found in the current default shell.
A copy of this function also exists in `setup.py`.""" 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