]> git.llucax.com Git - personal/ion3-config.git/commitdiff
Port maildir_status_server.sh to Python.
authorLeandro Lucarella <llucax@gmail.com>
Sat, 24 Nov 2007 19:04:23 +0000 (16:04 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 24 Nov 2007 19:04:23 +0000 (16:04 -0300)
default/cfg_statusbar.lua
maildir_status_server.py [new file with mode: 0755]
maildir_status_server.sh [deleted file]

index 330955490dc6580f3c4e8926f919e8dcf5c2106d..71ac8995af3ddce892e376f14d2268f1ddb0cc61 100644 (file)
@@ -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 (executable)
index 0000000..3b7cef9
--- /dev/null
@@ -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 (executable)
index b831866..0000000
+++ /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
-