]> git.llucax.com Git - personal/ion3-config.git/commitdiff
Port psi_status.sh to Python and make it a server.
authorLeandro Lucarella <llucax@gmail.com>
Sat, 24 Nov 2007 19:03:58 +0000 (16:03 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 24 Nov 2007 19:03:58 +0000 (16:03 -0300)
default/cfg_statusbar.lua
psi_status.sh [deleted file]
psi_status_server.py [new file with mode: 0755]

index 0a1193f0b3a9bbede3688a02c9df7556b6ff25ba..330955490dc6580f3c4e8926f919e8dcf5c2106d 100644 (file)
@@ -133,7 +133,7 @@ mod_statusbar.launch_statusd{
     -- Scripts
     exec = {
         psi = {
-            program = '~/.ion3/psi_status.sh',
+            program = '~/.ion3/psi_status_server.py 1', -- 1 segundo
             retry_delay = 1 * 1000, -- 1 segundo
             hint_regexp = {
                 important = '^[0-9]',
diff --git a/psi_status.sh b/psi_status.sh
deleted file mode 100755 (executable)
index 9a27059..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-psi_profile_dir=~/.psi/profiles/luca
-
-events_files="$psi_profile_dir"/events-*.xml
-regex='^\s*<jid'
-
-msgs=`egrep "$regex" $events_files | wc -l`
-jids=`egrep "$regex" $events_files \
-               | sed 's/.*<jid>\(.*\)<\/jid>.*/\1/' \
-               | sort -u \
-               | tr '\n' ' ' \
-               | sed 's/ $//'`
-if [ $msgs -eq 0 ]
-then
-       echo "nada nuevo"
-else
-       [ $msgs -gt 1 ] && pl=s
-       echo "$msgs mensaje$pl nuevo$pl (de $jids)"
-fi
diff --git a/psi_status_server.py b/psi_status_server.py
new file mode 100755 (executable)
index 0000000..aa4846c
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/env python2.5
+
+import os
+import re
+import sys
+import glob
+import time
+
+# MUST config
+psi_profile = 'luca'
+
+# MAY config
+no_template = 'nada nuevo'
+yes_template = '%(total)s mensaje%(pl)s nuevo%(pl)s (de %(jids)s)'
+join_str = ' '
+default_secs = 1
+
+# Probably you don't want to touch this
+psi_profile_dir = os.path.join(os.getenv('HOME'), '.psi', 'profiles', psi_profile)
+events_files_glob = 'events-*.xml'
+event_regex = re.compile(r'.*<jid>(.*)<\/jid>.*')
+
+os.chdir(psi_profile_dir)
+
+secs = default_secs
+
+if len(sys.argv) > 1:
+       secs = int(sys.argv[1])
+
+print 'start'
+while True:
+       events = []
+       for f in glob.glob(events_files_glob):
+               l = event_regex.findall(file(f).read())
+               if l:
+                       events.extend(l)
+       if events:
+               print yes_template % dict(
+                       total = len(events),
+                       pl    = 's' if len(events) > 1 else '',
+                       jids  = join_str.join(frozenset(events))
+               )
+       else:
+               print no_template
+       sys.stdout.flush()
+       time.sleep(secs)
+