1
0
Fork 0

moved command existance check to separate function

This commit is contained in:
Kim, Jimin 2022-05-06 18:07:54 +09:00
parent 741f320eca
commit 8fa8d4c140
4 changed files with 18 additions and 8 deletions

View file

@ -15,6 +15,15 @@ import sys
# must be synced with `src/constants.py` # must be synced with `src/constants.py`
tmp_dir = "/tmp/com.developomp.setup" tmp_dir = "/tmp/com.developomp.setup"
#
# Util
#
def command_exits(command: str) -> bool:
return system(f"command -v {command} &> /dev/null") == 0
# #
# Common # Common
# #
@ -53,7 +62,7 @@ def exit_if_system_not_compatible():
"""Exits script if the OS is not linux or if pacman does not exist""" """Exits script if the OS is not linux or if pacman does not exist"""
print("Checking if system is compatible") print("Checking if system is compatible")
if "linux" not in sys.platform.lower() or system("command -v pacman &> /dev/null"): if "linux" not in sys.platform.lower() or not command_exits("pacman"):
print("This script should only be used on arch linux.", file=sys.stderr) print("This script should only be used on arch linux.", file=sys.stderr)
exit(1) exit(1)
@ -77,7 +86,7 @@ def install_git():
"""Installs git if it's not installed already""" """Installs git if it's not installed already"""
print("Initializing git") print("Initializing git")
if system("command -v git &> /dev/null"): if not command_exits("git"):
print("git was not installed already. Installing now.") print("git was not installed already. Installing now.")
system("sudo pacman -S --noconfirm --needed git") system("sudo pacman -S --noconfirm --needed git")

View file

@ -2,9 +2,6 @@
# this variable may be altered by the script # this variable may be altered by the script
# most notably by `src/interface/choose_action.py` # most notably by `src/interface/choose_action.py`
from os import system
content_dir = "/tmp/com.developomp.setup" content_dir = "/tmp/com.developomp.setup"
tmp_dir = content_dir tmp_dir = content_dir
home_dir = "/home/pomp" home_dir = "/home/pomp"
is_zsh_available: bool = system("command -v zsh &> /dev/null") == 0

View file

@ -1,8 +1,8 @@
from os import system from os import system
from os.path import isdir from os.path import isdir
from src.constants import home_dir, is_zsh_available from src.constants import home_dir
from src.util import paru_install, zsh_system from src.util import paru_install, zsh_system, command_exists
from src.setup.system import zsh from src.setup.system import zsh
from src import log from src import log
@ -21,7 +21,7 @@ def setup():
""" """
# Install zsh if it's not installed already # Install zsh if it's not installed already
if not is_zsh_available: if not command_exists("zsh"):
zsh.setup() zsh.setup()
paru_install("nvm") paru_install("nvm")

View file

@ -114,6 +114,10 @@ def zsh_system(command: str):
system(f"/usr/bin/zsh -c '{command}'") system(f"/usr/bin/zsh -c '{command}'")
def command_exists(command: str) -> bool:
return system(f"command -v {command} &> /dev/null") == 0
""" """
def setup_essentials(): def setup_essentials():
setup_fstab setup_fstab