mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 13:14:35 +00:00
Run install packages when the file started directly
This commit is contained in:
parent
555a2d0599
commit
37c6db12a3
|
@ -3,7 +3,7 @@ import yaml
|
||||||
|
|
||||||
from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage
|
from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage
|
||||||
from src.util.install import Install
|
from src.util.install import Install
|
||||||
from src.util import log
|
from src.util.user import Print
|
||||||
|
|
||||||
|
|
||||||
def obtain_packages() -> t.List[Package]:
|
def obtain_packages() -> t.List[Package]:
|
||||||
|
@ -30,9 +30,13 @@ def install_packages() -> None:
|
||||||
Install.upgrade_pacman()
|
Install.upgrade_pacman()
|
||||||
for package in packages:
|
for package in packages:
|
||||||
try:
|
try:
|
||||||
log.action(f"Installing {package}")
|
Print.action(f"Installing {package}")
|
||||||
package.install()
|
package.install()
|
||||||
except PackageAlreadyInstalled:
|
except PackageAlreadyInstalled:
|
||||||
log.cancel(f"Package {package} is already installed.")
|
Print.cancel(f"Package {package} is already installed.")
|
||||||
except InvalidPackage as e:
|
except InvalidPackage as e:
|
||||||
log.warning(e)
|
Print.warning(e)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
install_packages()
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
import typing as t
|
|
||||||
|
|
||||||
from src.util.color import Color
|
|
||||||
|
|
||||||
|
|
||||||
def question(question: str, options: t.Optional[list] = None) -> None:
|
|
||||||
"""Print syntax for question with optional `options` to it"""
|
|
||||||
text = [f"{Color.GREEN} // {question}{Color.RESET}"]
|
|
||||||
if options:
|
|
||||||
for option in options:
|
|
||||||
text.append(f"{Color.GREEN} # {options}{Color.RESET}")
|
|
||||||
print("\n".join(text))
|
|
||||||
|
|
||||||
|
|
||||||
def action(action: str) -> None:
|
|
||||||
"""Print syntax for action"""
|
|
||||||
print(f"{Color.GOLD} >> {action}{Color.RESET}")
|
|
||||||
|
|
||||||
|
|
||||||
def err(text: str) -> None:
|
|
||||||
"""Print syntax for error"""
|
|
||||||
print(f"{Color.RED} !! {text}{Color.RESET}")
|
|
||||||
|
|
||||||
|
|
||||||
def cancel(text: str) -> None:
|
|
||||||
"""Print syntax for cancellation"""
|
|
||||||
print(f"{Color.GREY} >> {text}{Color.RESET}")
|
|
||||||
|
|
||||||
|
|
||||||
def comment(text: str) -> None:
|
|
||||||
"""Print syntax for comments"""
|
|
||||||
print(f"{Color.GREY} // {text}{Color.RESET}")
|
|
||||||
|
|
||||||
|
|
||||||
def warning(text: str) -> None:
|
|
||||||
"""Print syntax for warnings"""
|
|
||||||
print(f"{Color.YELLOW} ** {text}{Color.RESET}")
|
|
33
src/util/user.py
Normal file
33
src/util/user.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from src.util.color import Color
|
||||||
|
|
||||||
|
|
||||||
|
class Print:
|
||||||
|
def question(question: str, options: t.Optional[list] = None) -> None:
|
||||||
|
"""Print syntax for question with optional `options` to it"""
|
||||||
|
text = [f"{Color.GREEN} // {question}{Color.RESET}"]
|
||||||
|
if options:
|
||||||
|
for option in options:
|
||||||
|
text.append(f"{Color.GREEN} # {options}{Color.RESET}")
|
||||||
|
print("\n".join(text))
|
||||||
|
|
||||||
|
def action(action: str) -> None:
|
||||||
|
"""Print syntax for action"""
|
||||||
|
print(f"{Color.GOLD} >> {action}{Color.RESET}")
|
||||||
|
|
||||||
|
def err(text: str) -> None:
|
||||||
|
"""Print syntax for error"""
|
||||||
|
print(f"{Color.RED} !! {text}{Color.RESET}")
|
||||||
|
|
||||||
|
def cancel(text: str) -> None:
|
||||||
|
"""Print syntax for cancellation"""
|
||||||
|
print(f"{Color.GREY} >> {text}{Color.RESET}")
|
||||||
|
|
||||||
|
def comment(text: str) -> None:
|
||||||
|
"""Print syntax for comments"""
|
||||||
|
print(f"{Color.GREY} // {text}{Color.RESET}")
|
||||||
|
|
||||||
|
def warning(text: str) -> None:
|
||||||
|
"""Print syntax for warnings"""
|
||||||
|
print(f"{Color.YELLOW} ** {text}{Color.RESET}")
|
Loading…
Reference in a new issue