From bd2b6e12b083b412fb94da85415d228495c07d71 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 24 Nov 2007 16:04:23 -0300 Subject: [PATCH] Port maildir_status_server.sh to Python. --- default/cfg_statusbar.lua | 4 ++-- maildir_status_server.py | 44 +++++++++++++++++++++++++++++++++++++++ maildir_status_server.sh | 41 ------------------------------------ 3 files changed, 46 insertions(+), 43 deletions(-) create mode 100755 maildir_status_server.py delete mode 100755 maildir_status_server.sh 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 - -- 2.43.0