diff --git a/.tmux b/.tmux index 4d38b937e..d13990c5e 100755 --- a/.tmux +++ b/.tmux @@ -31,7 +31,17 @@ tmux send-keys -t "$SESSION_NAME" "cd ./aspects/email/files/.config; clear" Ente tmux new-window -t "$SESSION_NAME" +tmux rename-window -t "$SESSION_NAME" "Man" +tmux send-keys -t "$SESSION_NAME" "cd ./man; clear" Enter + +tmux new-window -t "$SESSION_NAME" + tmux rename-window -t "$SESSION_NAME" "Git" tmux send-keys -t "$SESSION_NAME" "clear; wgs" Enter +tmux split-window -v + +tmux send-keys -t "$SESSION_NAME" "clear" Enter +tmux send-keys -t "$SESSION_NAME" "g aa; g ce; g p; c" + eval "$tmuxAttachCommand" diff --git a/aspects/aspects-template.json b/aspects/aspects-template.json new file mode 100644 index 000000000..4cbf78ccc --- /dev/null +++ b/aspects/aspects-template.json @@ -0,0 +1,24 @@ +{ + "description": "", + "files": { + ".home": {}, + ".config": {}, + ".local": {} + }, + "templates": { + ".home": {}, + ".config": {}, + ".local": {} + }, + "packages": { + "aur": {}, + "pacman": {}, + "apt": {}, + "apt-get": {}, + "yum": {} + }, + "libraries": { + "python": {}, + "npm": {} + } +} diff --git a/aspects/dotfiles/aspect.json b/aspects/dotfiles/aspect.json index 8975b7a7b..c98f97d2a 100644 --- a/aspects/dotfiles/aspect.json +++ b/aspects/dotfiles/aspect.json @@ -125,35 +125,12 @@ "lf", "ueberzug" ], - "libraries": [ - "npm", - "python-pip" - ], - "fcitx": [ - "fcitx" - ], - "fonts": [ - "all-repository-fonts" - ], - "xdotool": [ - "xdotool" - ], - "chrome": [ - "google-chrome" - ], - "lightdm": [ - "lightdm", - "lightdm-gtk-greeter" - ], - "lynx": [ - "lynx" - ], - "manuskript": [ - "manuskript" - ], "mpd": [ "mpd" ], + "mpc": [ + "mpc" + ], "mpv": [ "mpv" ], @@ -169,26 +146,12 @@ "pamixer": [ "pamixer" ], - "pcmanfm": [ - "pcmanfm" - ], "picom": [ "picom" ], - "theme": [ - "sxiv", - "feh", - "pywal", - "flameshot", - "lxappearance", - "themix-full" - ], "polybar": [ "polybar" ], - "python": [ - "ipython" - ], "ranger": [ "ranger" ], diff --git a/aspects/dotfiles/files/.config/bspwm/bspwmrc b/aspects/dotfiles/files/.config/bspwm/bspwmrc index 240921c0f..140d11837 100755 --- a/aspects/dotfiles/files/.config/bspwm/bspwmrc +++ b/aspects/dotfiles/files/.config/bspwm/bspwmrc @@ -13,7 +13,7 @@ xrdb -load ~/.config/X11/Xresources # Autostart # ############# -picom -b --backend glx --blur-method dual_kawase & +# picom -b --backend glx --blur-method dual_kawase & killall bspswallow; pidof ~/.local/bin/bspwm/bspswallow | ~/.local/bin/bspwm/bspswallow & killall flameshot; flameshot & killall fcitx; fcitx -d & diff --git a/aspects/dotfiles/files/.config/btop/btop.conf b/aspects/dotfiles/files/.config/btop/btop.conf index 4be299f7c..ea8ce65f1 100644 --- a/aspects/dotfiles/files/.config/btop/btop.conf +++ b/aspects/dotfiles/files/.config/btop/btop.conf @@ -1,4 +1,4 @@ -#? Config file for btop v. 1.2.9 +#? Config file for btop v. 1.3.2 #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" @@ -16,7 +16,7 @@ force_tty = False #* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets. #* Format: "box_name:P:G,box_name:P:G" P=(0 or 1) for alternate positions, G=graph symbol to use for box. -#* Use withespace " " as separator between different presets. +#* Use whitespace " " as separator between different presets. #* Example: "cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty" presets = "cpu:1:default,proc:0:default cpu:0:default,mem:0:default,net:0:default cpu:0:block,net:0:tty" @@ -37,6 +37,9 @@ graph_symbol = "braille" # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". graph_symbol_cpu = "default" +# Graph symbol to use for graphs in gpu box, "default", "braille", "block" or "tty". +graph_symbol_gpu = "default" + # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". graph_symbol_mem = "default" @@ -46,7 +49,7 @@ graph_symbol_net = "default" # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". graph_symbol_proc = "default" -#* Manually set which boxes to show. Available values are "cpu mem net proc", separate values with whitespace. +#* Manually set which boxes to show. Available values are "cpu mem net proc" and "gpu0" through "gpu5", separate values with whitespace. shown_boxes = "cpu mem net proc" #* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs. @@ -86,6 +89,9 @@ proc_left = False #* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop). proc_filter_kernel = False +#* In tree-view, always accumulate child process resources in the parent process. +proc_aggregate = False + #* Sets the CPU stat shown in upper half of the CPU graph, "total" is always available. #* Select from a list of detected attributes from the options menu. cpu_graph_upper = "total" @@ -94,6 +100,9 @@ cpu_graph_upper = "total" #* Select from a list of detected attributes from the options menu. cpu_graph_lower = "total" +#* If gpu info should be shown in the cpu box. Available values = "Auto", "On" and "Off". +show_gpu_info = "Auto" + #* Toggles if the lower CPU graph should be inverted. cpu_invert_lower = True @@ -207,6 +216,33 @@ show_battery = True #* Which battery to use if multiple are present. "Auto" for auto detection. selected_battery = "Auto" +#* Show power stats of battery next to charge indicator. +show_battery_watts = True + #* Set loglevel for "~/.config/btop/btop.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". #* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. -log_level = "INFO" \ No newline at end of file +log_level = "INFO" + +#* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards. +nvml_measure_pcie_speeds = True + +#* Horizontally mirror the GPU graph. +gpu_mirror_graph = True + +#* Custom gpu0 model name, empty string to disable. +custom_gpu_name0 = "" + +#* Custom gpu1 model name, empty string to disable. +custom_gpu_name1 = "" + +#* Custom gpu2 model name, empty string to disable. +custom_gpu_name2 = "" + +#* Custom gpu3 model name, empty string to disable. +custom_gpu_name3 = "" + +#* Custom gpu4 model name, empty string to disable. +custom_gpu_name4 = "" + +#* Custom gpu5 model name, empty string to disable. +custom_gpu_name5 = "" diff --git a/aspects/dotfiles/files/.local/share/autojump/autojump.txt b/aspects/dotfiles/files/.local/share/autojump/autojump.txt index 10f854ae0..6a851ec3f 100644 Binary files a/aspects/dotfiles/files/.local/share/autojump/autojump.txt and b/aspects/dotfiles/files/.local/share/autojump/autojump.txt differ diff --git a/aspects/dotfiles/files/.local/share/autojump/autojump.txt.bak b/aspects/dotfiles/files/.local/share/autojump/autojump.txt.bak index aa86db0f1..2678eecaa 100644 Binary files a/aspects/dotfiles/files/.local/share/autojump/autojump.txt.bak and b/aspects/dotfiles/files/.local/share/autojump/autojump.txt.bak differ diff --git a/aspects/dotfiles/files/.local/share/newsboat/cache.db b/aspects/dotfiles/files/.local/share/newsboat/cache.db index 7a1ec8324..9f71d9c28 100644 Binary files a/aspects/dotfiles/files/.local/share/newsboat/cache.db and b/aspects/dotfiles/files/.local/share/newsboat/cache.db differ diff --git a/aspects/dotfiles/files/.local/share/zathura/bookmarks.sqlite b/aspects/dotfiles/files/.local/share/zathura/bookmarks.sqlite index 2608c26a2..73147c3c1 100644 Binary files a/aspects/dotfiles/files/.local/share/zathura/bookmarks.sqlite and b/aspects/dotfiles/files/.local/share/zathura/bookmarks.sqlite differ diff --git a/aspects/email/files/.config/mbsync/mbsyncrc.temp b/aspects/email/files/.config/mbsync/mbsyncrc.temp index 137157be3..24689e687 100644 --- a/aspects/email/files/.config/mbsync/mbsyncrc.temp +++ b/aspects/email/files/.config/mbsync/mbsyncrc.temp @@ -86,7 +86,7 @@ Channel ^{email_1}-get-folders # # ################################################################################ IMAPAccount ^{email_2} -Host imap.gmail.com +Host ^{email_2_server} User ^{email_2} PassCmd "^{email_2_password}" SSLType IMAPS @@ -164,7 +164,7 @@ Channel ^{email_2}-get-folders # # ################################################################################ IMAPAccount ^{email_3} -Host imap.gmail.com +Host ^{email_3_server} User ^{email_3} PassCmd "^{email_3_password}" SSLType IMAPS @@ -242,7 +242,7 @@ Channel ^{email_3}-get-folders # # ################################################################################ IMAPAccount ^{email_4} -Host imap.gmail.com +Host ^{email_4_server} User ^{email_4} PassCmd "^{email_4_password}" SSLType IMAPS @@ -320,7 +320,7 @@ Channel ^{email_4}-get-folders # # ################################################################################ IMAPAccount ^{email_5} -Host imap.gmail.com +Host ^{email_5_server} User ^{email_5} PassCmd "^{email_5_password}" SSLType IMAPS @@ -391,3 +391,81 @@ Channel ^{email_5}-starred Channel ^{email_5}-trash Channel ^{email_5}-get-folders ################################################################################ + +################################################################################ +# # +# Account 6 # +# # +################################################################################ +IMAPAccount ^{email_6} +Host ^{email_6_server} +User ^{email_6} +PassCmd "^{email_6_password}" +SSLType IMAPS +AuthMechs LOGIN + +IMAPStore ^{email_6}-remote +Account ^{email_6} + +MaildirStore ^{email_6}-local +Path ~/.local/share/mail/^{email_6}/ +Inbox ~/.local/share/mail/^{email_6}/INBOX +SubFolders Verbatim + +Channel ^{email_6}-inbox +Far :^{email_6}-remote:INBOX +Near :^{email_6}-local:INBOX + +# Channel ^{email_6}-archive +# Far :^{email_6}-remote:"[Gmail]/All Mail" +# Near :^{email_6}-local:Archive + +# Channel ^{email_6}-drafts +# Far :^{email_6}-remote:"[Gmail]/Drafts" +# Near :^{email_6}-local:Drafts + +# Channel ^{email_6}-important +# Far :^{email_6}-remote:"[Gmail]/Important" +# Near :^{email_6}-local:Important + +# Channel ^{email_6}-sent +# Far :^{email_6}-remote:"[Gmail]/Sent Mail" +# Near :^{email_6}-local:Sent + +# Channel ^{email_6}-spam +# Far :^{email_6}-remote:"[Gmail]/Spam" +# Near :^{email_6}-local:Spam + +# Channel ^{email_6}-starred +# Far :^{email_6}-remote:"[Gmail]/Starred" +# Near :^{email_6}-local:Starred + +# Channel ^{email_6}-trash +# Far :^{email_6}-remote:"[Gmail]/Trash" +# Near :^{email_6}-local:Trash + +# Channel ^{email_6}-get-folders +# Far :^{email_6}-remote: +# Near :^{email_6}-local: +# Patterns * +# Patterns !INBOX +# Patterns !Search +# Patterns !Sent +# Patterns !Spam +# Patterns !Trash +# Patterns ![Gmail]* +# Patterns !Archive +# Patterns !Drafts +# Patterns !Starred + +# Group ^{email_6} +# Channel ^{email_6}-inbox +# Channel ^{email_6}-archive +# Channel ^{email_6}-drafts +# Channel ^{email_6}-important +# Channel ^{email_6}-sent +# Channel ^{email_6}-spam +# Channel ^{email_6}-starred +# Channel ^{email_6}-trash +# Channel ^{email_6}-get-folders +################################################################################ diff --git a/aspects/email/files/.config/msmtp/config.temp b/aspects/email/files/.config/msmtp/config.temp index e4b004884..8e05a562d 100644 --- a/aspects/email/files/.config/msmtp/config.temp +++ b/aspects/email/files/.config/msmtp/config.temp @@ -1,3 +1,8 @@ +auth on +tls on +tls_trust_file /etc/ssl/certs/ca-certificates.crt +logfile ~/.config/msmtp/msmtp.log + ################################################################################ account ^{email_1} host ^{email_1_host} @@ -5,10 +10,6 @@ port ^{email_1_port} from ^{email_1} user ^{email_1} passwordeval "^{email_1_password}" -auth on -tls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -logfile ~/.config/msmtp/msmtp.log ################################################################################ ################################################################################ @@ -18,10 +19,6 @@ port ^{email_2_port} from ^{email_2} user ^{email_2} passwordeval "^{email_2_password}" -auth on -tls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -logfile ~/.config/msmtp/msmtp.log ################################################################################ ################################################################################ @@ -31,10 +28,6 @@ port ^{email_3_port} from ^{email_3} user ^{email_3} passwordeval "^{email_3_password}" -auth on -tls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -logfile ~/.config/msmtp/msmtp.log ################################################################################ ################################################################################ @@ -44,10 +37,6 @@ port ^{email_4_port} from ^{email_4} user ^{email_4} passwordeval "^{email_4_password}" -auth on -tls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -logfile ~/.config/msmtp/msmtp.log ################################################################################ ################################################################################ @@ -57,8 +46,13 @@ port ^{email_5_port} from ^{email_5} user ^{email_5} passwordeval "^{email_5_password}" -auth on -tls on -tls_trust_file /etc/ssl/certs/ca-certificates.crt -logfile ~/.config/msmtp/msmtp.log +################################################################################ + +################################################################################ +account ^{email_6} +host ^{email_6_host} +port ^{email_6_port} +from ^{email_6} +user ^{email_6} +passwordeval "^{email_6_password}" ################################################################################ diff --git a/aspects/email/files/.config/notmuch/config.temp b/aspects/email/files/.config/notmuch/config.temp index 8932a9025..0ebc41c7b 100644 --- a/aspects/email/files/.config/notmuch/config.temp +++ b/aspects/email/files/.config/notmuch/config.temp @@ -1,7 +1,7 @@ [database] path=/home/^{user}/.local/share/mail [user] -name=singularisartt +name=^{user} primary_email=^{primary_email} [new] tags=unread;inbox; diff --git a/aspects/email/vars/private.yaml b/aspects/email/vars/private.yaml index 05eccb683..537f1d941 100644 Binary files a/aspects/email/vars/private.yaml and b/aspects/email/vars/private.yaml differ diff --git a/aspects/email/vars/public.yaml b/aspects/email/vars/public.yaml index f8ea4b426..ae7febe34 100644 --- a/aspects/email/vars/public.yaml +++ b/aspects/email/vars/public.yaml @@ -19,6 +19,10 @@ email_5: your@email-5.com email_5_password: pass your@email-5.com email_5_server: imap.gmail.com +email_6: your@email-6.com +email_6_password: pass your@email-6.com +email_6_server: imap.gmail.com + # msmtp/config email_1_host: smtp.gmail.com email_1_port: 587 @@ -35,6 +39,9 @@ email_4_port: 587 email_5_host: smtp.gmail.com email_5_port: 587 +email_6_host: smtp.gmail.com +email_6_port: 587 + # notmuch/config user: user primary_email: your-primary@gmail.com diff --git a/aspects/packages/README.md b/aspects/packages/README.md new file mode 100644 index 000000000..3fbbc74f7 --- /dev/null +++ b/aspects/packages/README.md @@ -0,0 +1 @@ +# Packages diff --git a/aspects/packages/aspect.json b/aspects/packages/aspect.json new file mode 100644 index 000000000..bdf70193d --- /dev/null +++ b/aspects/packages/aspect.json @@ -0,0 +1,74 @@ +{ + "description": "All of my used packages.", + "files": { + ".home": {}, + ".config": {}, + ".local": {} + }, + "templates": { + ".home": {}, + ".config": {}, + ".local": {} + }, + "packages": { + "aur": { + "libraries": [ + "npm", + "python-pip" + ], + "fcitx": [ + "fcitx" + ], + "fonts": [ + "all-repository-fonts" + ], + "xdotool": [ + "xdotool" + ], + "chrome": [ + "google-chrome" + ], + "lightdm": [ + "lightdm", + "lightdm-gtk-greeter" + ], + "slock": [ + "slock" + ], + "pcmanfm": [ + "pcmanfm" + ], + "theme": [ + "sxiv", + "feh", + "pywal", + "flameshot", + "lxappearance", + "themix-full" + ], + "python": [ + "ipython" + ], + "latex": [ + "texlive", + "texlive-basic", + "texlive-latex", + "texlive-latexrecommended", + "texlive-latexextra", + "texlive-fontsrecommended", + "texlive-fontsextra", + "texlive-bibtexextra", + "texlive-mathscience", + "texlive-lang" + ] + }, + "pacman": {}, + "apt": {}, + "apt-get": {}, + "yum": {} + }, + "libraries": { + "python": {}, + "npm": {} + } +} diff --git a/aspects/packages/index.py b/aspects/packages/index.py new file mode 100755 index 000000000..5da2d6778 --- /dev/null +++ b/aspects/packages/index.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from man.log import Log as Log +from man.operations.file import Files as Files +from man.operations.packages import Packages as Packages +from man.operations.template import Templates as Templates +from man.operations.library import Python as Python +from man.operations.library import Node as Node + + +log = Log() + +log.log_notice("Installing my Packages.") + +Files("packages", specific_items_to_install, specific_items_to_ignore, args) +Templates("packages", specific_items_to_install, specific_items_to_ignore, args) +Packages("packages", specific_items_to_install, specific_items_to_ignore, args) +Python("packages", specific_items_to_ignore, specific_items_to_install, args) +Node("packages", specific_items_to_ignore, specific_items_to_install, args) + +log.log_success("Installed my Packages.") diff --git a/install b/install index 19261d60f..de2cbc13a 100755 --- a/install +++ b/install @@ -2,4 +2,5 @@ import man.main as main + main.main() diff --git a/man/helpers.py b/man/helpers.py index fa728a17f..69c264d0c 100644 --- a/man/helpers.py +++ b/man/helpers.py @@ -2,6 +2,10 @@ import os import re import subprocess +import sys +import termios +import tty +from shutil import get_terminal_size def load_data(file, aspect_name, log): @@ -40,15 +44,35 @@ def pretty_log(log, log_level, string): ) +def get_keypress(): + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return ch + + def confirm(prompt): + status = False + print(f"{prompt} (Default: no) ", end="", flush=True) + while True: - choice = input(f"{prompt} (Default: no) ").lower() - if choice in ["yes", "y"]: - return True - elif choice in ["no", "n", ""]: - return False + key = get_keypress().lower() + if key in ["y"]: + status = True + break + elif key in ["n", "\r", "\n"]: + status = False + break else: - print('Please enter "yes", "y" or "no", "n"') + print("\nPlease enter 'y' or 'n'", end="", flush=True) + + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="\r") + return status def install_package(package, log_level, confirm=False, package_type="aur"): diff --git a/man/loading_animation.py b/man/loading_animation.py new file mode 100644 index 000000000..c31883acb --- /dev/null +++ b/man/loading_animation.py @@ -0,0 +1,48 @@ +from itertools import cycle +from shutil import get_terminal_size +from threading import Thread +from time import sleep + +from man.log import Log as Log + +log = Log() + + +class Loader: + def __init__(self, log_function, failure_function, log_level=3): + self.timeout = 0.1 + self.success_function = log_function + self.failure_function = failure_function + self.log_level = log_level + + self._thread = Thread(target=self._animate, daemon=True) + self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"] + self.done = False + + def start(self, desc): + self.desc = desc + self._thread.start() + return self + + def _animate(self): + for c in cycle(self.steps): + if self.done: + break + if self.log_level >= 3: + print(f"\r{self.desc} {c}", flush=True, end="") + sleep(self.timeout) + + def __enter__(self, desc): + self.start(desc) + + def success(self, end): + self.done = True + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="\r") + self.success_function(end) + + def failure(self, end=""): + self.done = True + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="\r") + self.failure_function(end) diff --git a/man/log.py b/man/log.py index 136ff7bb9..7d27a54a5 100644 --- a/man/log.py +++ b/man/log.py @@ -106,7 +106,7 @@ def log_format(self, type, text, spacing_number): spacing, self.style["reset"], text, - ) + ), ) def log_trace(self, text): diff --git a/man/main.py b/man/main.py index 4c0e5ac61..9932cec94 100644 --- a/man/main.py +++ b/man/main.py @@ -10,6 +10,13 @@ def core(args): aspects = Aspects(args) + + # Move the packages aspect to the front of the list. + for x, aspect in enumerate(aspects["aspects_to_install"]): + if "packages" == aspect.__repr__(): + aspects["aspects_to_install"].pop(x) + aspects["aspects_to_install"].insert(0, aspect) + [aspect.install_aspect() for aspect in aspects["aspects_to_install"]] diff --git a/man/operations/aspects.py b/man/operations/aspects.py index 64670f36b..163400201 100644 --- a/man/operations/aspects.py +++ b/man/operations/aspects.py @@ -67,12 +67,12 @@ def __init__(self, args): self.all_aspects = [ Aspect(a, self.args) for a in os.listdir(self.aspects_dir) - if os.path.exists("{}/{}/index.py".format(self.aspects_dir, a)) + if os.path.exists(f"{self.aspects_dir}/{a}/index.py") ] self.all_aspect_names = [ a for a in os.listdir(self.aspects_dir) - if os.path.exists("{}/{}/index.py".format(self.aspects_dir, a)) + if os.path.exists(f"{self.aspects_dir}/{a}/index.py") ] s = self.args.aspect diff --git a/man/operations/file.py b/man/operations/file.py index b22eb0c61..d13c32479 100644 --- a/man/operations/file.py +++ b/man/operations/file.py @@ -94,20 +94,20 @@ def install(self): return if self.args.dry_run: - log.log_info(f"Install {name}.") + log.log_info(f"Would have installed '{pretty_name}'.") return if self.args.confirm: - if not helpers.confirm(f"Would you like to install {pretty_name}"): + if not helpers.confirm(f"Would you like to install the config files for '{pretty_name}'"): return if self.type != ".local": - log.log_trace(f"Installing {name}.") + log.log_trace(f"Installing {pretty_name}.") helpers.symlink(self.file_location, self.file_destination) log.log_trace( f"Symlinking: {self.file_location} -> {self.file_destination}." ) - log.log_info(f"Installed {name}.") + log.log_info(f"Installed {pretty_name}.") return @@ -118,7 +118,7 @@ def install(self): helpers.symlink(file_location, file_destination) log.log_trace(f"Symlinking: {file_location} -> {file_destination}.") - log.log_info(f"Installed {name}.") + log.log_info(f"Installed {pretty_name}.") def check_sum(self): return True diff --git a/man/operations/library.py b/man/operations/library.py index 4d2141076..bf66afa6c 100644 --- a/man/operations/library.py +++ b/man/operations/library.py @@ -2,6 +2,7 @@ import man.helpers as helpers from man import InitClass as InitClass +from man.loading_animation import Loader from man.log import Log as Log from man.variables import aspects_dir @@ -25,12 +26,21 @@ def __init__( self.args = args self.library_type = library_type - if self.library_type == "python" and self.args.no_python or self.library_type == "node" and self.args.no_node: - log.log_warn(f"Skipping installing {self.library_type} libraries for {self.aspect_name}.") + if ( + self.library_type == "python" + and self.args.no_python + or self.library_type == "node" + and self.args.no_node + ): + log.log_warn( + f"Skipping installing {self.library_type} libraries for {self.aspect_name}." + ) return self.aspect_json_file_location = helpers.join( - aspects_dir, self.aspect_name, "aspect.json", + aspects_dir, + self.aspect_name, + "aspect.json", ) self.data = helpers.load_data(self.aspect_json_file_location, aspect_name, log) @@ -39,23 +49,28 @@ def __init__( try: self.libraries = self.data["libraries"][self.library_type] except KeyError: - log.log_warn(f"No {self.library_type} libraries to install for {self.aspect_name}.") + log.log_warn( + f"No {self.library_type} libraries to install for {self.aspect_name}." + ) return - log.log_trace(f"Installing all {self.library_type} libraries for {self.aspect_name.title()}.") + log.log_trace( + f"Installing all {self.library_type} libraries for {self.aspect_name}." + ) self.get_libraries() - log.log_trace(f"Installed all {self.library_type} libraries for {self.aspect_name.title()}.") + log.log_trace( + f"Installed all {self.library_type} libraries for {self.aspect_name}." + ) def get_libraries(self): for lib in self.libraries: if not self.specific_items_to_install and not self.specific_items_to_ignore: - self.install_library(lib) - + self.install_library_collection(lib) elif lib in self.specific_items_to_install: - self.install_library(lib) + self.install_library_collection(lib) - def install_library(self, lib): - log.log_trace(f"Installing {lib} for {self.aspect_name.title()}.") + def install_library_collection(self, lib): + log.log_trace(f"Installing {lib} for {self.aspect_name}.") cmd = [ "pip3", "install", @@ -67,32 +82,50 @@ def install_library(self, lib): "install", "-g", ] + for library in self.libraries[lib]: cmd_lib = cmd.copy() cmd_lib.append(library) - log.log_trace(f"Installing {library} for {self.aspect_name.title()}.") log_level = int(self.args.log_level) if self.args.log_level else -1 - try: - log.log_trace(f"Installing {self.library_type} library '{library}' for {self.aspect_name.title()}.") - stdout = subprocess.PIPE if log_level > 2 or log_level == -1 else None - stderr = subprocess.PIPE if log_level > 2 or log_level == -1 else None - subprocess.run( - cmd_lib, - stdout=stdout, - stderr=stderr, - check=True, - ) - log.log_info(f"Installed {self.library_type} library '{library}' for {self.aspect_name.title()}.") - except subprocess.CalledProcessError as e: - log.log_error(f"Error installing {self.library_type} library {library} for {self.aspect_name.title()}.") - if log_level <= 2 and log_level != -1: - log.log_debug(e.stderr.decode("utf-8")) - + if self.args.confirm and helpers.confirm( + f"Do you want to install {self.library_type} library '{library}' for {self.aspect_name}?" + ): + self.install_library(cmd_lib, library, log_level) + elif self.args.dry_run: + pretty_name = helpers.pretty_log(log, log.info, library) + if self.args.dry_run: + log.log_info( + f"Would have installed {self.library_type} library '{pretty_name}'." + ) + + def install_library(self, cmd_lib, library, log_level): + loader = Loader(log.log_info, log.log_error) + loader.start(f"Installing {self.library_type} library '{library}'") + try: + stdout = subprocess.PIPE if log_level > 2 or log_level == -1 else None + stderr = subprocess.PIPE if log_level > 2 or log_level == -1 else None + subprocess.run( + cmd_lib, + stdout=stdout, + stderr=stderr, + check=True, + ) + loader.success( + f"Installed {self.library_type} library '{library}' for {self.aspect_name}." + ) + except subprocess.CalledProcessError as e: + loader.failure_function( + f"Error installing {self.library_type} library {library} for {self.aspect_name}." + ) + if log_level <= 2 and log_level != -1: + log.log_debug(e.stderr.decode("utf-8")) class Python(Library): - def __init__(self, aspect_name, specific_items_to_install, specific_items_to_ignore, args): + def __init__( + self, aspect_name, specific_items_to_install, specific_items_to_ignore, args + ): Library.__init__( self, aspect_name, @@ -104,7 +137,9 @@ def __init__(self, aspect_name, specific_items_to_install, specific_items_to_ign class Node(Library): - def __init__(self, aspect_name, specific_items_to_install, specific_items_to_ignore, args): + def __init__( + self, aspect_name, specific_items_to_install, specific_items_to_ignore, args + ): Library.__init__( self, aspect_name, diff --git a/man/operations/packages.py b/man/operations/packages.py index b8f4dfbea..4bce2eaae 100644 --- a/man/operations/packages.py +++ b/man/operations/packages.py @@ -1,9 +1,11 @@ +import subprocess + import man.helpers as helpers from man import InitClass as InitClass from man.helpers import install_package +from man.loading_animation import Loader from man.log import Log as Log from man.variables import aspects_dir -import subprocess log = Log() @@ -69,15 +71,24 @@ def __init__( pass def install_package(self, package_name): - try: - log.log_trace(f"Installing package '{package_name}'.") - log_level = int(self.args.log_level) if self.args.log_level else -1 - install_package( - package_name, - log_level, - confirm=self.args.confirm, - package_type=self.package_type, - ) - log.log_info(f"Installed package '{package_name}'.") - except subprocess.CalledProcessError: - log.log_error(f"Error installing package '{package_name}'.") + pretty_name = helpers.pretty_log(log, log.info, package_name) + if self.args.dry_run: + log.log_info(f"Would install package '{pretty_name}'.") + return + + if self.args.confirm and helpers.confirm( + f"Would you like to install the package '{pretty_name}'" + ): + loader = Loader(log.log_info, log.log_error) + try: + loader.start(f"Installing package '{pretty_name}'") + log_level = int(self.args.log_level) if self.args.log_level else -1 + install_package( + package_name, + log_level, + confirm=self.args.confirm, + package_type=self.package_type, + ) + loader.success(f"Installed package '{pretty_name}'.") + except subprocess.CalledProcessError: + loader.failure(f"Failed to install package '{pretty_name}'.") diff --git a/man/operations/template.py b/man/operations/template.py index 238a5b460..9314c34e9 100644 --- a/man/operations/template.py +++ b/man/operations/template.py @@ -185,11 +185,11 @@ def __init__( self.aspect_json_template_location, self.aspect, log ) - log.log_trace("Installing all templates for {}".format(aspect.title())) + log.log_trace(f"Installing all templates for {aspect.title()}") dict.__init__(self, self.get_templates()) - log.log_trace("Installed all templates for {}".format(aspect.title())) + log.log_trace(f"Installed all templates for {aspect.title()}") def get_templates(self): templates = {