From: Leandro Lucarella Date: Sat, 24 Nov 2007 19:04:23 +0000 (-0300) Subject: Port maildir_status_server.sh to Python. X-Git-Url: https://git.llucax.com/personal/ion3-config.git/commitdiff_plain/bd2b6e12b083b412fb94da85415d228495c07d71?hp=dfb59f8a55d307c45a0fbbb6603a13c2f1792d3d Port maildir_status_server.sh to Python. --- diff --git a/default/cfg_statusbar.lua b/default/cfg_statusbar.lua index 3309554..71ac899 100644 --- a/default/cfg_statusbar.lua +++ b/default/cfg_statusbar.lua @@ -140,8 +140,8 @@ mod_statusbar.launch_statusd{ }, }, maildir = { - program = '~/.ion3/maildir_status_server.sh 10', - retry_delay = 10 * 1000, + program = '~/.ion3/maildir_status_server.py 10', -- 10 segundos + retry_delay = 10 * 1000, -- 10 segundos hint_regexp = { important = '([0-9]+)', }, diff --git a/maildir_status_server.py b/maildir_status_server.py new file mode 100755 index 0000000..3b7cef9 --- /dev/null +++ b/maildir_status_server.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python2.5 + +import os +import re +import sys +import glob +import time + +# MUST config +maildir = os.path.join(os.getenv('HOME'), 'Maildir') + +# MAY config +no_template = 'nada nuevo' +yes_template = '%(name)s (%(messages)s)' +join_str = ' ' +default_secs = 30 + +if len(sys.argv) > 1: + secs = int(sys.argv[1]) + +os.chdir(maildir) + +folders = [f for f in glob.glob(os.path.join(maildir, '.*')) + if not f.endswith('.historial') + and os.path.exists(os.path.join(f, 'new'))] +folders.sort() +folders.insert(0, maildir) + +while True: + new = [] + for folder in folders: + name = folder[len(maildir)+2:] + if not name: name = 'INBOX' + messages = len(glob.glob(os.path.join(folder, 'new', '*'))) + if messages: + new.append((name, messages)) + if new: + print join_str.join([yes_template % dict(name=n, messages=m) + for (n,m) in new]) + else: + print no_template + sys.stdout.flush() + time.sleep(secs) + diff --git a/maildir_status_server.sh b/maildir_status_server.sh deleted file mode 100755 index b831866..0000000 --- a/maildir_status_server.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -#set -x - -delay=30 -maildir=~/Maildir - -[ -n "$1" ] && delay="$1" -[ -n "$2" ] && maildir="$2" - -cd $maildir -maildirs=`find -type d -name new | grep -v historial` - -print_status() -{ - - messages= - for d in $maildirs - do - msgs=`ls $d | wc -l` - if [ $msgs -gt 0 ] - then - name=`dirname $d` - name=`basename $name | cut -b2-` - [ -z "$name" ] && name=Inbox - messages="$messages $name ($msgs)" - fi - done - if [ -n "$messages" ] - then - echo $messages - else - echo "nada nuevo" - fi -} - -print_status -while sleep $delay -do - print_status -done -