deploypkg.zsh: Various Updates

* Clean up colors/pacman.py for colorful output
* Fixes for the .local/bin move
* Use the $COLORS and $BIN variables from common.zsh

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2023-07-19 11:45:58 -04:00
parent 70dfceccef
commit 2e9699a52e
2 changed files with 9 additions and 14 deletions

View File

@ -1,17 +1,12 @@
#!/usr/bin/python
"""Add color and machine tags to remote pacman output."""
import termcolor import termcolor
import re import re
import sys import sys
prefix = sys.argv[1] if len(sys.argv) > 1 else None prefix = sys.argv[1] if len(sys.argv) > 1 else None
pacman_colors = dict() pacman_colors = {"==>": "green", "->": "blue"}
pacman_attrs = dict()
def add_color_attr(field, color, *attrs):
pacman_colors[field] = color
pacman_attrs[field] = attrs
add_color_attr("==>", "green", "bold")
add_color_attr("->", "blue", "bold")
for line in sys.stdin: for line in sys.stdin:
if prefix: if prefix:
@ -19,8 +14,7 @@ for line in sys.stdin:
if "==>" in line or "->" in line: if "==>" in line or "->" in line:
for part in re.split(r'(\s+)', line): for part in re.split(r'(\s+)', line):
color = pacman_colors.get(part, "white") color = pacman_colors.get(part, "white")
attrs = pacman_attrs.get(part, ["bold"])
termcolor.cprint(part, color, attrs=attrs, end="") termcolor.cprint(part, color, attrs=["bold"], end="")
else: else:
print(line, end="") print(line, end="")

View File

@ -1,5 +1,5 @@
#!/bin/zsh #!/bin/zsh
colors="$HOME/bin/colors" source common.zsh
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
echo "Usage: $0 /path/to/package {remote host, ...}" echo "Usage: $0 /path/to/package {remote host, ...}"
@ -12,11 +12,12 @@ shift
function deploy_package() { function deploy_package() {
ssh $1 "mkdir -pv pkg" 2>&1 | sed -e "s/^/$2 /" ssh $1 "mkdir -pv pkg" 2>&1 | sed -e "s/^/$2 /"
script -q -c "scp $pkg $1:pkg/ 2>&1" 2>&1 | sed -e "s/^/$2 /" script -q -c "scp $pkg $1:pkg/ 2>&1" 2>&1 | sed -e "s/^/$2 /"
ssh $1 "sudo pacman --noconfirm -U pkg/$pkg" | python $colors/pacman.py $2 ssh $1 "sudo pacman --noconfirm -U pkg/$pkg" | python $COLORS/pacman.py $2
} }
$HOME/bin/vm.zsh boot $* $BIN/vm.zsh boot $*
tags=($(python $colors/vm.py $*))
tags=($(FORCE_COLOR=1 python $COLORS/vm.py $*))
for ((i=1; i<=$#; i++)); do for ((i=1; i<=$#; i++)); do
deploy_package ${@[i]} ${tags[i]} & deploy_package ${@[i]} ${tags[i]} &
done done