Created
March 8, 2014 05:32
-
-
Save balta2ar/9425810 to your computer and use it in GitHub Desktop.
Conky scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# | |
# The script prints new packages' info: | |
# package name -> old version -> new version | |
# colorized for conky | |
# | |
import sys | |
import subprocess | |
def print_header(n_max, n_new): | |
fmt = '${color3}New packages (%d of %d shown) $stippled_hr' | |
print(fmt % (n_max, n_new)) | |
def colorize(items): | |
width = max([len(c) for (a, b, c) in items]) | |
#fmt = "${{color1}}{name}${{color}} ${{alignr}} ${{color2}}{old} ${{color1}}→${{color}} {:>{width}}" | |
fmt = "${{color1}}{name}${{color}} ${{alignr}} ${{color1}}→${{color}} {:>{width}}" | |
#fmt = fmt.encode('utf-8') | |
for (name, old_v, new_v) in items: | |
#out = fmt.format(new_v, name=name, old=old_v, width=width) | |
out = fmt.format(new_v, name=name, width=width) | |
print(out) | |
def extract_version(line): | |
(a, _, b) = line.partition(':') | |
(a, b) = (a.strip(), b.strip()) | |
if a == 'Version': | |
return b | |
return None | |
def package_db_version(name): | |
pacman = subprocess.Popen(['pacman', '-Si', name], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
output, _ = pacman.communicate() | |
pacman.wait() | |
output = output.decode('utf-8').splitlines() | |
for l in output: | |
version = extract_version(l) | |
if version != None: | |
return version | |
return '?' | |
def add_new_version(items): | |
return [[name, old, package_db_version(name)] for (name, old) in items] | |
def main(argv): | |
max_items = 10 | |
if len(sys.argv) > 1: | |
max_items = int(sys.argv[1]) | |
pacman = subprocess.Popen(['pacman', '-Qu'], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
names_versions, _ = pacman.communicate() | |
names_versions = names_versions.decode('utf-8').splitlines() | |
pacman.wait() | |
new_items = len(names_versions) | |
if max_items > new_items: | |
max_items = new_items | |
if new_items == 0: | |
return 0 | |
names_versions = [s.split() for s in names_versions] | |
names_versions = add_new_version(names_versions) | |
#print_header(max_items, new_items) | |
colorize(names_versions) | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#${color1}Uptime$color $alignr ${color2}$uptime | |
#pacman -Qu | sed 's/\(^.\+\)\s\+\(.\+$\)/${color1}\1$color $alignr ${color2}\2/g' | |
SETTINGS_FILE=/tmp/conky-new-packages-settings.tmp | |
CACHED_OUTPUT=/tmp/conky-new-packages-output.tmp | |
# init max with default value | |
MAX=10 | |
if [[ ! -z $1 ]]; then | |
MAX=$1 | |
fi | |
# limit max to a number of new packages | |
NEW=`pacman -Qu | wc -l` | |
if [ $NEW -lt $MAX ]; then | |
MAX=$NEW | |
fi | |
# print colored packages | |
#RESULT=$(pacman -Qu \ | |
# | sed 's/\(^.\+\)\s\+\(.\+\)$/${color1}\1${color} ${alignr} ${color2}\2/g') | |
RESULT=$(cat $CACHED_OUTPUT) | |
print_header() | |
{ | |
# print title | |
echo '${color3}New packages' \ | |
"($1 of $2 shown)" \ | |
'$stippled_hr' | |
} | |
print_empty() | |
{ | |
exit 0 | |
} | |
limit() | |
{ | |
echo -e "$1" | head -n $2 | |
} | |
scroll() | |
{ | |
local res=$1 | |
local max=$2 | |
local num_new=$3 | |
# default state | |
REMOVE_LINES=0 | |
# load state | |
source $SETTINGS_FILE | |
# perform cut and limit | |
local dbl="$res\n\n$res" | |
limit "$(echo -e "$dbl" | sed "1,${REMOVE_LINES}d")" $max | |
# increase number | |
REMOVE_LINES=$(($REMOVE_LINES + 1)) | |
# check overflow | |
if [ $REMOVE_LINES -gt $(($num_new + 1)) ]; then | |
REMOVE_LINES=0 | |
fi | |
# save state | |
echo "REMOVE_LINES=$REMOVE_LINES" > $SETTINGS_FILE | |
} | |
# check if there are any new packages to print | |
if [ $NEW -eq 0 ]; then | |
print_empty | |
else | |
print_header $MAX $NEW | |
fi | |
# check if we need to scroll the output | |
if [ "$2" == "scroll" ] | |
then | |
scroll "$RESULT" $MAX $NEW | |
else | |
limit "$RESULT" $MAX | |
fi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=/var/log/pacman/update.log | |
echo "`date`: Downloading $# packages: $*" >> $LOG | |
pacman --noconfirm -Sw $* >> $LOG | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=/var/log/pacman/update.log | |
PACKAGES=`pacman -Qu` | |
echo -n "New packages: " >> $LOG | |
date >> $LOG | |
pacman -Qu >> $LOG | |
NAMES=`echo $PACKAGES | sed 's/\s\+/\n/g' | sed -n '1~2p'` | |
echo $NAMES | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=/var/log/pacman/update.log | |
echo -n "Updating pacman databases: " >> $LOG | |
date >> $LOG | |
pacman -Sy >> $LOG | |
echo >> $LOG | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment