1
0
Fork 0

replace run with system

- hiding stdout ain't helpful 99% of the time like I have to go
  "why the fuck is this shit hanging?" and have to guess if it's
  even doing shit
This commit is contained in:
Kim, Jimin 2022-11-07 17:30:27 +09:00
parent 13774f69c4
commit 65fea2ec89
17 changed files with 85 additions and 113 deletions

View file

@ -22,18 +22,6 @@ tmp_dir = "/tmp/com.developomp.setup"
# #
def run(command: str, hide_stdout: bool = True, hide_stderr: bool = True):
if hide_stderr:
system(f"{command} &> /dev/null")
return
if hide_stdout:
system(f"{command} > /dev/null")
return
system(command)
def run_and_return(command: str) -> list[str]: def run_and_return(command: str) -> list[str]:
return popen(command).readlines() return popen(command).readlines()
@ -103,7 +91,7 @@ def exit_if_no_internet():
"""Exits script if there's no internet connection. """Exits script if there's no internet connection.
Pings archlinux.org for testing.""" Pings archlinux.org for testing."""
if run("ping -c 1 archlinux.org"): if system("ping -c 1 archlinux.org"):
print(" Failed to connect to the internet.", file=sys.stderr) print(" Failed to connect to the internet.", file=sys.stderr)
exit(1) exit(1)
@ -139,7 +127,7 @@ def install_git():
"""Install git if it's not installed already.""" """Install git if it's not installed already."""
if not command_exists("git"): if not command_exists("git"):
run("sudo pacman -S --noconfirm --needed git") system("sudo pacman -S --noconfirm --needed git")
def clone_repository(): def clone_repository():
@ -149,12 +137,12 @@ def clone_repository():
cleanup() cleanup()
# clone repository # clone repository
if run(f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"): if system(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)
# allow everyone to read and write. # allow everyone to read and write.
if run(f"chmod -R a+rw {tmp_dir}"): if system(f"chmod -R a+rw {tmp_dir}"):
print(" Failed to change file permission for cloned repo", file=sys.stderr) print(" Failed to change file permission for cloned repo", file=sys.stderr)
exit(1) exit(1)

View file

@ -1,15 +1,16 @@
from os import system
from src import log from src import log
from src.util import run
def install_via_pacman(package: str): def install_via_pacman(package: str):
if run(f"paru -S --noconfirm {package}", True): if system(f"paru -S --noconfirm {package}"):
log.error(f"Failed to install {package} via pacman") log.error(f"Failed to install {package} via pacman")
exit(1) exit(1)
def install_via_pip(package: str): def install_via_pip(package: str):
if run(f"pip install {package}"): if system(f"pip install {package}"):
log.error(f"Failed to install {package} via pip") log.error(f"Failed to install {package} via pip")
exit(1) exit(1)

View file

@ -1,4 +1,6 @@
from src.util import flatpak_install, paru_install, copy_file, run from os import system
from src.util import flatpak_install, paru_install, copy_file
from src import log from src import log
@ -58,8 +60,8 @@ def setup():
log.log(f"installing {url}") log.log(f"installing {url}")
# assumes that plugins is located in "~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins" because I'm using flatpak # assumes that plugins is located in "~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins" because I'm using flatpak
run( system(
f'wget --content-disposition --no-clobber -P ~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins "{url}"' f'wget --content-disposition --no-clobber -P ~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins "{url}"'
) )
run("betterdiscordctl -i flatpak install") system("betterdiscordctl -i flatpak install")

View file

@ -1,6 +1,6 @@
from src.util import paru_install, load_dconf, command_exists, run from src.util import paru_install, load_dconf, command_exists
from src.setup.apps import terminal from src.setup.apps import terminal
from os import system
name = "Nautilus" name = "Nautilus"
@ -22,10 +22,12 @@ def setup():
load_dconf("nautilus.conf") load_dconf("nautilus.conf")
# set nautilus terminal settings # set nautilus terminal settings
run( system(
"gsettings set com.github.stunkymonkey.nautilus-open-any-terminal terminal kitty" "gsettings set com.github.stunkymonkey.nautilus-open-any-terminal terminal kitty"
) )
run( system(
"gsettings set com.github.stunkymonkey.nautilus-open-any-terminal keybindings ''" "gsettings set com.github.stunkymonkey.nautilus-open-any-terminal keybindings ''"
) )
run("gsettings set com.github.stunkymonkey.nautilus-open-any-terminal new-tab true") system(
"gsettings set com.github.stunkymonkey.nautilus-open-any-terminal new-tab true"
)

View file

@ -1,7 +1,8 @@
from src.util import flatpak_install, paru_install, copy_file, run from src.util import flatpak_install, paru_install, copy_file
from src.setup.system import system76_scheduler from src.setup.system import system76_scheduler
from os.path import exists from os.path import exists
from os import system
name = "osu!lazer" name = "osu!lazer"
post_install = ["Install osu! skin from https://github.com/developomp/osu-pomp-skin"] post_install = ["Install osu! skin from https://github.com/developomp/osu-pomp-skin"]
@ -37,15 +38,15 @@ def setup():
for name in modules_to_disable: for name in modules_to_disable:
# Add blacklist rule if it does not exist # Add blacklist rule if it does not exist
run( system(
f'sudo grep -qxF "blacklist {name}" /etc/modprobe.d/blacklist.conf || echo "blacklist {name}" | sudo tee -a /etc/modprobe.d/blacklist.conf' f'sudo grep -qxF "blacklist {name}" /etc/modprobe.d/blacklist.conf || echo "blacklist {name}" | sudo tee -a /etc/modprobe.d/blacklist.conf'
) )
# remove module from kernel if it's loaded # remove module from kernel if it's loaded
run(f"sudo rmmod {name}") system(f"sudo rmmod {name}")
# Reload the systemd user unit daemon # Reload the systemd user unit daemon
run("systemctl --user daemon-reload") system("systemctl --user daemon-reload")
# Enable and start the user service # Enable and start the user service
run("systemctl --user enable opentabletdriver --now") system("systemctl --user enable opentabletdriver --now")

View file

@ -1,6 +1,6 @@
# https://github.com/tenacityteam/tenacity-flatpak-nightly # https://github.com/tenacityteam/tenacity-flatpak-nightly
from src.util import run from os import system
name = "Tenacity" name = "Tenacity"
@ -8,7 +8,7 @@ name = "Tenacity"
def setup(): def setup():
"""Safe audacity fork""" """Safe audacity fork"""
run( system(
"flatpak remote-add tenacity oci+https://tenacityteam.github.io/tenacity-flatpak-nightly" "flatpak remote-add tenacity oci+https://tenacityteam.github.io/tenacity-flatpak-nightly"
) )
run("flatpak install tenacity org.tenacityaudio.Tenacity") system("flatpak install tenacity org.tenacityaudio.Tenacity")

View file

@ -1,5 +1,6 @@
from src.util import paru_install, run from src.util import paru_install
from getpass import getuser from getpass import getuser
from os import system
name = "Docker" name = "Docker"
@ -9,5 +10,5 @@ def setup():
paru_install("docker") paru_install("docker")
run(f'sudo usermod -aG docker "{getuser()}"') system(f'sudo usermod -aG docker "{getuser()}"')
run("sudo systemctl --now enable docker") system("sudo systemctl --now enable docker")

View file

@ -1,4 +1,5 @@
from src.util import paru_install, run from src.util import paru_install
from os import system
name = "git" name = "git"
@ -8,8 +9,8 @@ def setup():
paru_install("git") paru_install("git")
run('git config --global user.email "developomp@gmail.com"') system('git config --global user.email "developomp@gmail.com"')
run('git config --global user.name "developomp"') system('git config --global user.name "developomp"')
run("git config --global pull.rebase false") system("git config --global pull.rebase false")
run("git config --global init.defaultBranch master") system("git config --global init.defaultBranch master")
run("git config --global credential.helper store") system("git config --global credential.helper store")

View file

@ -1,9 +1,10 @@
from src.constants import home_dir from src.constants import home_dir
from src.util import paru_install, run, command_exists from src.util import paru_install, command_exists
from src.setup.system import zsh from src.setup.system import zsh
from src import log from src import log
from os.path import isdir from os.path import isdir
from os import system
name = "node" name = "node"
@ -26,15 +27,15 @@ def setup():
paru_install("nvm") paru_install("nvm")
log.log("Installing Node.JS LTS") log.log("Installing Node.JS LTS")
run("source /usr/share/nvm/init-nvm.sh; nvm install --lts") system("source /usr/share/nvm/init-nvm.sh; nvm install --lts")
# todo: add "source /usr/share/nvm/init-nvm.sh" to ~/.zshrc # todo: add "source /usr/share/nvm/init-nvm.sh" to ~/.zshrc
log.log("Installing npm") log.log("Installing npm")
run("npm install --global npm") system("npm install --global npm")
log.log("Installing pnpm") log.log("Installing pnpm")
run("npm install --global pnpm") system("npm install --global pnpm")
log.log("Installing yarn") log.log("Installing yarn")
run("npm install --global yarn") system("npm install --global yarn")

View file

@ -1,4 +1,5 @@
from src.util import paru_install, run from src.util import paru_install
from os import system
name = "rust" name = "rust"
@ -8,4 +9,4 @@ def setup():
"""C++ but modern""" """C++ but modern"""
paru_install(["rustup", "rust-analyzer"]) paru_install(["rustup", "rust-analyzer"])
run("rustup install stable") system("rustup install stable")

View file

@ -1,4 +1,5 @@
from src.util import paru_install, run from src.util import paru_install
from os import system
name = "virtualbox" name = "virtualbox"
@ -14,6 +15,6 @@ def setup():
] ]
) )
run("sudo systemctl enable systemd-modules-load") system("sudo systemctl enable systemd-modules-load")
run("sudo systemctl start systemd-modules-load") system("sudo systemctl start systemd-modules-load")
run("sudo modprobe vboxdrv") system("sudo modprobe vboxdrv")

View file

@ -1,4 +1,5 @@
from src.util import paru_install, copy_file, run from src.util import paru_install, copy_file
from os import system
name = "Vscodium" name = "Vscodium"
@ -50,7 +51,7 @@ def setup():
# codium --list-extensions # codium --list-extensions
for extension in EXTENSIONS: for extension in EXTENSIONS:
run(f"codium --install-extension {extension} --force") system(f"codium --install-extension {extension} --force")
# vscodium settings # vscodium settings
copy_file("home/.config/VSCodium/User/settings.json") copy_file("home/.config/VSCodium/User/settings.json")

View file

@ -1,7 +1,7 @@
from src.util import paru_install, smart_mkdir, download, unzip from src.util import paru_install, smart_mkdir, download, unzip
from src.constants import tmp_dir, home_dir from src.constants import tmp_dir, home_dir
from shutil import rmtree, move from shutil import rmtree, move
from os import remove from os import remove, system
from os.path import exists, basename from os.path import exists, basename
import requests import requests
import glob import glob
@ -61,7 +61,7 @@ def setup():
move(ttf_file_path, f"{FONT_INSTALL_DIR}/{basename(ttf_file_path)}") move(ttf_file_path, f"{FONT_INSTALL_DIR}/{basename(ttf_file_path)}")
# regenerate font cache # regenerate font cache
run("fc-cache -vf") system("fc-cache -vf")
# cleanup # cleanup
rmtree(TMP_FONTS_DIRECTORY) rmtree(TMP_FONTS_DIRECTORY)

View file

@ -1,4 +1,4 @@
from src.util import run from os import system
name = "fstab" name = "fstab"
@ -19,4 +19,4 @@ def setup():
# append a line to the end and ignore output # append a line to the end and ignore output
# not using python's file interface because I don't wanna deal with permission stuff # not using python's file interface because I don't wanna deal with permission stuff
run(f'echo "{line_to_write}" | sudo tee -a {fstab_path} >/dev/null') system(f'echo "{line_to_write}" | sudo tee -a {fstab_path} >/dev/null')

View file

@ -1,6 +1,8 @@
from src.util import paru_install, load_dconf, run from src.util import paru_install, load_dconf
from src import log from src import log
from os import system
name = "GNOME extensions" name = "GNOME extensions"
post_install = ["Restart GNOME shell", "enable GNOME extensions"] post_install = ["Restart GNOME shell", "enable GNOME extensions"]
@ -39,7 +41,7 @@ def setup():
for (extension, dconf_file) in EXTENSIONS: for (extension, dconf_file) in EXTENSIONS:
log.log("installing: https://extensions.gnome.org/extension/$1") log.log("installing: https://extensions.gnome.org/extension/$1")
run(f"gnome-shell-extension-installer {extension} --yes --update") system(f"gnome-shell-extension-installer {extension} --yes --update")
if dconf_file: # if dconf_file is not empty if dconf_file: # if dconf_file is not empty
load_dconf(dconf_file) load_dconf(dconf_file)

View file

@ -1,8 +1,9 @@
from src.util import paru_install, copy_file, trash, run from src.util import paru_install, copy_file, trash
from src.constants import home_dir from src.constants import home_dir
from src import log from src import log
from os.path import isdir from os.path import isdir
from os import system
name = "Zsh" name = "Zsh"
@ -13,21 +14,23 @@ def setup():
paru_install("zsh") paru_install("zsh")
log.log("Installing Oh My Zsh") log.log("Installing Oh My Zsh")
run( system(
'sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' 'sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"'
) )
log.log("Installing powerlevel10k theme") log.log("Installing powerlevel10k theme")
p10k_path = f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k" p10k_path = f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k"
trash(p10k_path) trash(p10k_path)
run(f"git clone --depth=1 https://github.com/romkatv/powerlevel10k.git {p10k_path}") system(
f"git clone --depth=1 https://github.com/romkatv/powerlevel10k.git {p10k_path}"
)
log.log("Installing zsh syntax highlighter") log.log("Installing zsh syntax highlighter")
zsh_syntax_highlighting_path = ( zsh_syntax_highlighting_path = (
f"{home_dir}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" f"{home_dir}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
) )
trash(zsh_syntax_highlighting_path) trash(zsh_syntax_highlighting_path)
run( system(
f"git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git {zsh_syntax_highlighting_path}" f"git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git {zsh_syntax_highlighting_path}"
) )
@ -35,4 +38,4 @@ def setup():
copy_file("home/.zshrc") copy_file("home/.zshrc")
# set the default terminal to zsh # set the default terminal to zsh
run("chsh -s /bin/zsh") system("chsh -s /bin/zsh")

View file

@ -8,21 +8,6 @@ from src.log import error
import src.constants import src.constants
def run(command: str, hide_stdout: bool = True, hide_stderr: bool = True) -> None:
"""os.system but has an option to hide stdout and/or stderr.
A copy of this function also exists in `setup.py`."""
if hide_stderr:
system(f"{command} &> /dev/null")
return
if hide_stdout:
system(f"{command} > /dev/null")
return
system(command)
def run_and_return(command: str) -> list[str]: def run_and_return(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.
@ -31,9 +16,7 @@ def run_and_return(command: str) -> list[str]:
return popen(command).readlines() return popen(command).readlines()
def paru_install( def paru_install(packages: str | list[str]) -> None:
packages: str | list[str], hide_stdout: bool = True, hide_stderr: bool = True
) -> None:
""" """
Download arch linux packages (including AUR). Download arch linux packages (including AUR).
@ -49,12 +32,10 @@ def paru_install(
error("Invalid paru packages format.") error("Invalid paru packages format.")
return return
run(f"paru -S --noconfirm {packages}", hide_stdout, hide_stderr) system(f"paru -S --noconfirm {packages}")
def flatpak_install( def flatpak_install(packages: str) -> None:
packages: str, hide_stdout: bool = True, hide_stderr: bool = True
) -> None:
""" """
Download packages from flathub. Download packages from flathub.
@ -62,7 +43,7 @@ def flatpak_install(
packages: space-separated list of packages. packages: space-separated list of packages.
""" """
run(f"flatpak install -y {packages}", hide_stdout, hide_stderr) system(f"flatpak install -y {packages}")
def smart_mkdir(path: str) -> None: def smart_mkdir(path: str) -> None:
@ -76,23 +57,17 @@ def smart_mkdir(path: str) -> None:
pass pass
def trash(path, hide_stdout: bool = True, hide_stderr: bool = True) -> None: def trash(path) -> None:
"""Moves a file or directory to freedesktop trash.""" """Moves a file or directory to freedesktop trash."""
try: try:
run(f"trash-put {path}", hide_stdout, hide_stderr) system(f"trash-put {path}")
except Exception as err: except Exception as err:
print(f"Failed to remove: {path}") print(f"Failed to remove: {path}")
raise err raise err
def copy_file( def copy_file(src_file: str, mode="644", sudo=False) -> None:
src_file: str,
mode="644",
sudo=False,
hide_stdout: bool = True,
hide_stderr: bool = True,
) -> None:
""" """
Copies a file in the repo to the system. Copies a file in the repo to the system.
If the `src_file` starts with `home/`, it maps to $HOME. If the `src_file` starts with `home/`, it maps to $HOME.
@ -117,12 +92,10 @@ def copy_file(
if sudo: if sudo:
command = f"sudo {command}" command = f"sudo {command}"
run(command, hide_stdout, hide_stderr) system(command)
def copy_directory( def copy_directory(src: str, dst: str) -> None:
src: str, dst: str, hide_stdout: bool = True, hide_stderr: bool = True
) -> None:
"""Copy a directory. """Copy a directory.
Automatically creates parent directory/directories of dst if it does not exist already Automatically creates parent directory/directories of dst if it does not exist already
@ -131,19 +104,13 @@ def copy_directory(
dst: A path-like object or string pointing to a directory. dst: A path-like object or string pointing to a directory.
""" """
run(f"cp -R {src} {dst}", hide_stdout, hide_stderr) system(f"cp -R {src.constants.content_dir}{src} {dst}")
def load_dconf( def load_dconf(file_name: str) -> None:
file_name: str, hide_stdout: bool = True, hide_stderr: bool = True
) -> None:
"""Loads dconf configuration""" """Loads dconf configuration"""
run( system(f'dconf load / < "{src.constants.content_dir}/files/dconf/{file_name}"')
f'dconf load / < "{src.constants.content_dir}/files/dconf/{file_name}"',
hide_stdout,
hide_stderr,
)
def download(file_name: str, url: str) -> None: def download(file_name: str, url: str) -> None: