packages: ekg2-script-pynotif/ekg2-script-pynotif.spec, ekg2-script-pynotif...

pawelz pawelz at pld-linux.org
Tue Jul 14 12:04:54 CEST 2009


Author: pawelz                       Date: Tue Jul 14 10:04:54 2009 GMT
Module: packages                      Tag: HEAD
---- Log message:
- up to 20090714

---- Files affected:
packages/ekg2-script-pynotif:
   ekg2-script-pynotif.spec (1.2 -> 1.3) , pynotif.py (1.2 -> 1.3) 

---- Diffs:

================================================================
Index: packages/ekg2-script-pynotif/ekg2-script-pynotif.spec
diff -u packages/ekg2-script-pynotif/ekg2-script-pynotif.spec:1.2 packages/ekg2-script-pynotif/ekg2-script-pynotif.spec:1.3
--- packages/ekg2-script-pynotif/ekg2-script-pynotif.spec:1.2	Mon Jul  6 10:37:15 2009
+++ packages/ekg2-script-pynotif/ekg2-script-pynotif.spec	Tue Jul 14 12:04:48 2009
@@ -4,7 +4,7 @@
 Summary(pl.UTF-8):	Skrypt programu ekg2 wysyłający powiadomienia
 Name:		ekg2-script-pynotif
 Version:	0
-Release:	0.20090706.1
+Release:	0.20090714.1
 License:	GPL v3
 Group:		Applications/Communications
 # git clone git://github.com/pawelz/pynotif.git
@@ -43,6 +43,9 @@
 All persons listed below can be reached at <cvs_login>@pld-linux.org
 
 $Log$
+Revision 1.3  2009/07/14 10:04:48  pawelz
+- up to 20090714
+
 Revision 1.2  2009/07/06 08:37:15  pawelz
 - dropped R: python-pynotify. It should be added by autodeps.
 

================================================================
Index: packages/ekg2-script-pynotif/pynotif.py
diff -u packages/ekg2-script-pynotif/pynotif.py:1.2 packages/ekg2-script-pynotif/pynotif.py:1.3
--- packages/ekg2-script-pynotif/pynotif.py:1.2	Mon Jul  6 10:32:03 2009
+++ packages/ekg2-script-pynotif/pynotif.py	Tue Jul 14 12:04:48 2009
@@ -1,4 +1,4 @@
-# vim:fileencoding=utf-8
+# vim:fileencoding=utf-8:sw=4
 
 #   This program is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -14,12 +14,14 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #   Copyright (c) 2009 by Paweł Tomak <satherot (at) gmail (dot) com>
+#   Copyright (c) 2009 by Paweł Zuzelski <pawelz.pld-linux.org>
 
 import ekg
 import time
 import pynotify
 import re
 import sys
+import glib
 
 TIMEOUT_STATUS=3500
 TIMEOUT_MSG=3500
@@ -27,12 +29,22 @@
 def removeHTML(text):
     reg = re.compile("&")
     text = reg.sub("&#38;", text)
+    reg = re.compile('"')
+    text = reg.sub("&#34;", text)
     reg = re.compile("<")
     text = reg.sub("&#60;", text)
     reg = re.compile(">")
     text = reg.sub("&#62;", text)
     return text
 
+def catchURL(text):
+    reg = re.compile("((news|telnet|nttp|file|http|ftp|https)://[^ ]+|www.[^ ]+)")
+    if len(reg.findall(text)):
+        text = reg.sub(r'<a href="\1">\1</a>', text)
+        return [1, text]
+    else:
+        return [0, text]
+
 def transStatus(status):
     return {
             'avail': 'dostepny',
@@ -44,26 +56,46 @@
             'dnd': 'nie przeszkadzac',
             'xa': 'bardzo zajety',
             'notavail': 'niedostepny',
+            'unknown': 'nieznany',
             }[status]
 
 def displayNotify(title, text, timeout, type):
     if not pynotify.init("EkgNotif"):
         ekg.echo("you don't seem to have pynotify installed")
         return 0
+    if ekg.config["notify:catch_url"] != "0":
+        l = catchURL(text)
+        if l[0]:
+            text = l[1]
+            timeout = int(ekg.config["notify:catch_url_timeout"])
     n = pynotify.Notification(title, text, type)
     n.set_timeout(timeout)
-    n.show()
+
+    # Most probably glib.GError is:
+    # The name org.freedesktop.Notifications was not provided by any
+    # .service files
+    # Catch this exception and print information in debug window.
+    # Sometimes I
+    # do not have org.freedesktop.Notifications registered and
+    # I do not want
+    # error messages in chat window.
+    # Or logs buffer has overflowed ;/
+    try:
+        n.show()
+    except glib.GError as e:
+        ekg.debug("pynotif: " + str(e))
+
     return 1
 
 def notifyStatus(session, uid, status, descr):
-    regexp = re.compile('irc:*')
-    regexp = regexp.findall(session)
-    if len(regexp):
+    if ekg.config["notify:status_notify"] == "0":
+        return 1
+    regexp = re.compile('^irc:')
+    if regexp.match(session):
         return 1
     regexp = re.compile('.*' + session + '.*')
-    regexp = regexp.findall(uid)
-    if len(regexp):
-        ekg.echo("Zmienil sie status sesji: %s. Nie zostal on zmieniony przez ten program. Sprawdz to, jesli nie zmieniales statusu jakims innym programem" % session)
+    if regexp.match(uid):
+        ekg.debug("Zmienil sie status sesji: %s. Nie zostal on zmieniony przez ten program. Sprawdz to, jesli nie zmieniales statusu jakims innym programem" % session)
         return 1
     sesja = ekg.session_get(session)
     regexp = re.compile('([a-z]{2,4}:[^/]+)')
@@ -72,10 +104,13 @@
     try:
         user = sesja.user_get(regexp)
     except KeyError:
-        ekg.echo("Nie znalazlem uzytkownika %s." % uid)
-        return 1
+        ekg.debug("Nie znalazlem uzytkownika %s." % uid)
+        user = "Empty"
     status = transStatus(status)
-    nick = user.nickname or user.uid or "Empty"
+    if user == "Empty":
+        nick = regexp
+    else:
+        nick = user.nickname or user.uid or "Empty"
     s = status or "Empty"
     s = removeHTML(s)
     text = "<b>" + nick + "</b> zmienil status na <b>" + s + "</b>"
@@ -85,19 +120,26 @@
     return displayNotify(session, text, TIMEOUT_STATUS, ekg.config["notify:icon_status"])
 
 def notifyMessage(session, uid, type, text, stime, ignore_level):
-    regexp = re.compile('irc:*')
-    regexp = regexp.findall(session)
-    if len(regexp):
+    if ekg.config["notify:message_notify"] == "0":
+        return 1
+    regexp = re.compile('^irc:')
+    if regexp.match(session):
         return 1
     text = removeHTML(text)
     sesja = ekg.session_get(session)
     try:
         user = sesja.user_get(uid)
     except KeyError:
-        ekg.echo("Nie znalazlem uzytkownika %s." % uid)
-        return 1
+        ekg.debug("Nie znalazlem uzytkownika %s." % uid)
+        user = "Empty"
     t = time.strftime("%H:%M:%S", time.gmtime(stime))
-    title = t + " " + user.nickname
+    if user == "Empty" and ekg.config["notify:message_notify_unknown"] == "0":
+        return 1
+    if user == "Empty":
+        user = uid
+    else:
+        user = user.nickname
+    title = t + " " + user
     if len(text) > 200:
         text = text[0:199] + "... >>>\n\n"
     return displayNotify(title, text, TIMEOUT_MSG, ekg.config["notify:icon_msg"])
@@ -114,19 +156,43 @@
         if name == "notify:status_timeout":
             TIMEOUT_STATUS = int(rexp[0])
             return 1
+        if name == "notify:catch_url_timeout":
+            return 1
 
     if name == "notify:message_timeout":
         ekg.echo("Zmienna %s bedzie pomijana do czasu, az zostanie ustawiona wartosc z zakresu od 1000ms do 9999ms. Jej obecna wartosc to: %i" % (name,TIMEOUT_MSG))
     elif name == "notify:status_timeout":
         ekg.echo("Zmienna %s bedzie pomijana do czasu, az zostanie ustawiona wartosc z zakresu od 1000ms do 9999ms. Jej obecna wartosc to: %i" % (name,TIMEOUT_STATUS))
+    elif name == "notify:catch_url_timeout":
+        ekg.echo("Zmienna %s bedzie pomijana do czasu, az zostanie ustawiona wartosc z zakresu od 1000ms do 9999ms. Jej obecna wartosc to: %i" % (name,TIMEOUT_STATUS))
     return 0
 
+def notifyTest(name, args):
+    args = args.split(None, 1)
+    if (len(args) == 0):
+        title="Test"
+    else:
+        title=args[0]
+  
+    if (len(args) <= 1):
+        text="Pięćdziesiąt trzy"
+    else:
+        text = args[1]
+  
+    return displayNotify(title, text, TIMEOUT_MSG, ekg.config["notify:icon_msg"])
+
 ekg.handler_bind('protocol-status', notifyStatus)
 ekg.handler_bind("protocol-message-received", notifyMessage)
 ekg.variable_add("notify:icon_status", "dialog-warning")
 ekg.variable_add("notify:icon_msg", "dialog-warning")
 ekg.variable_add("notify:message_timeout", "3500", timeCheck)
+ekg.variable_add("notify:message_notify", "1")
+ekg.variable_add("notify:message_notify_unknown", "1")
 ekg.variable_add("notify:status_timeout", "3500", timeCheck)
+ekg.variable_add("notify:status_notify", "1")
+ekg.variable_add("notify:catch_url", "1")
+ekg.variable_add("notify:catch_url_timeout", "5000", timeCheck)
+ekg.command_bind("notify:send", notifyTest)
 
 if int(ekg.config["notify:message_timeout"]) < 1000 or int(ekg.config["notify:message_timeout"]) > 9999:
     timeCheck("notify:message_timeout", ekg.config["notify:message_timeout"])
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/ekg2-script-pynotif/ekg2-script-pynotif.spec?r1=1.2&r2=1.3&f=u
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/ekg2-script-pynotif/pynotif.py?r1=1.2&r2=1.3&f=u



More information about the pld-cvs-commit mailing list