moved /dev/null
usage to a separate function
This commit is contained in:
parent
c4e463ef00
commit
9d1eb5834a
3 changed files with 22 additions and 10 deletions
13
setup.py
13
setup.py
|
@ -18,6 +18,13 @@ tmp_dir = "/tmp/com.developomp.setup"
|
||||||
#
|
#
|
||||||
# Util
|
# Util
|
||||||
#
|
#
|
||||||
|
# These commands are from `src/util.py`.
|
||||||
|
# Comments can only be found over there.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
def silent_system(command: str) -> None:
|
||||||
|
system(f"{command} &> /dev/null")
|
||||||
|
|
||||||
|
|
||||||
def command_exits(command: str) -> bool:
|
def command_exits(command: str) -> bool:
|
||||||
|
@ -72,7 +79,7 @@ def exit_if_no_internet():
|
||||||
Pings archlinux.org for testing."""
|
Pings archlinux.org for testing."""
|
||||||
|
|
||||||
print("Checking if there's internet connection")
|
print("Checking if there's internet connection")
|
||||||
if system("ping -c 1 archlinux.org &> /dev/null"):
|
if silent_system("ping -c 1 archlinux.org"):
|
||||||
print("Failed to connect to internet.", file=sys.stderr)
|
print("Failed to connect to internet.", file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
@ -100,8 +107,8 @@ def clone_repository():
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
# clone repository
|
# clone repository
|
||||||
if system(
|
if silent_system(
|
||||||
f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir} &> /dev/null"
|
f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"
|
||||||
):
|
):
|
||||||
print("Failed to clone repository", file=sys.stderr)
|
print("Failed to clone repository", file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
from src.util import silent_system, paru_install
|
||||||
|
|
||||||
from src import log
|
from src import log
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,29 +8,29 @@ def initialize():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.log("Initializing flatpak")
|
log.log("Initializing flatpak")
|
||||||
if os.system("sudo pacman -S --noconfirm --needed flatpak &> /dev/null"):
|
if paru_install("flatpak"):
|
||||||
log.error("Failed to install flatpak via pacman")
|
log.error("Failed to install flatpak via pacman")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
log.log("Initializing pip")
|
log.log("Initializing pip")
|
||||||
if os.system("sudo pacman -S --noconfirm --needed python-pip &> /dev/null"):
|
if paru_install("python-pip"):
|
||||||
log.error("Failed to install pip via pacman")
|
log.error("Failed to install pip via pacman")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# https://pypi.org/project/requests
|
# https://pypi.org/project/requests
|
||||||
log.log("Initializing requests")
|
log.log("Initializing requests")
|
||||||
if os.system("pip install requests &> /dev/null"):
|
if silent_system("pip install requests"):
|
||||||
log.error("Failed to install requests via pip")
|
log.error("Failed to install requests via pip")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# https://pypi.org/project/PyYAML
|
# https://pypi.org/project/PyYAML
|
||||||
log.log("Initializing PyYAML")
|
log.log("Initializing PyYAML")
|
||||||
if os.system("pip install PyYAML &> /dev/null"):
|
if silent_system("pip install PyYAML"):
|
||||||
log.error("Failed to install PyYAML via pip")
|
log.error("Failed to install PyYAML via pip")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# https://github.com/magmax/python-inquirer
|
# https://github.com/magmax/python-inquirer
|
||||||
log.log("Initializing inquirer")
|
log.log("Initializing inquirer")
|
||||||
if os.system("pip install inquirer &> /dev/null"):
|
if silent_system("pip install inquirer"):
|
||||||
log.error("Failed to install inquirer via pip")
|
log.error("Failed to install inquirer via pip")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -115,6 +115,12 @@ def zsh_system(command: str) -> None:
|
||||||
system(f"/usr/bin/zsh -c '{command}'")
|
system(f"/usr/bin/zsh -c '{command}'")
|
||||||
|
|
||||||
|
|
||||||
|
def silent_system(command: str) -> None:
|
||||||
|
"""os.system but does not show its log and error to the terminal."""
|
||||||
|
|
||||||
|
system(f"{command} &> /dev/null")
|
||||||
|
|
||||||
|
|
||||||
def run(command: str) -> list[str]:
|
def run(command: str) -> list[str]:
|
||||||
"""Runs command in system shell and return the result.
|
"""Runs command in system shell and return the result.
|
||||||
This is a blocking function.
|
This is a blocking function.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue