Quelques mini-outils de plus…
authorProgfou <jean-christophe.andre@auf.org>
Mon, 21 Mar 2011 20:44:05 +0000 (03:44 +0700)
committerProgfou <jean-christophe.andre@auf.org>
Mon, 21 Mar 2011 20:44:05 +0000 (03:44 +0700)
outils/auf-reportbug [new file with mode: 0755]
outils/ip2cc [new file with mode: 0755]
outils/ooo-text2date [new file with mode: 0755]

diff --git a/outils/auf-reportbug b/outils/auf-reportbug
new file mode 100755 (executable)
index 0000000..a99115b
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Depends: python-gtk2
+import sys
+try:
+    import gtk
+except:
+    print "Support PyGTK non disponible. Installer le paquet 'python-gtk2'."
+    sys.exit(1)
+
+TITLE = u"AuF — Envoi d'un rapport de bogue"
+EMAIL_LABEL = u"Entrez votre adresse électronique : "
+TEXT_LABEL = u"Décrivez votre problème ci-dessous :"
+
+HR = "-" * 78
+REPPORT = "\n".join([HR, "Rapport de bogue de %(email)s :", HR, "%(text)s", HR])
+
+def bugreport_print(email, text):
+    print REPPORT % {'email': email, 'text': text}
+
+def bugreport_http(email, text):
+    # on imagine ici une procédure d'envoi via HTTP
+    pass
+
+def cancel_clicked(btn):
+    gtk.main_quit()
+
+def ok_clicked(btn, email, text):
+    email = email.get_text()
+    start, end = text.get_buffer().get_bounds()
+    text = start.get_text(end)
+    bugreport_print(email, text)
+    bugreport_http(email, text)
+    gtk.main_quit()
+
+def run_gui():
+    email_label = gtk.Label(EMAIL_LABEL)
+    email = gtk.Entry()
+
+    email_hbox = gtk.HBox()
+    email_hbox.pack_start(email_label, False)
+    email_hbox.pack_start(email)
+
+    ruler = gtk.Ruler()
+    ruler.set_size_request(0, 1)
+
+    text_label = gtk.Label(TEXT_LABEL)
+    text = gtk.TextView()
+
+    scroller = gtk.ScrolledWindow()
+    scroller.add(text)
+
+    cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
+    cancel.connect("clicked", cancel_clicked)
+
+    ok = gtk.Button(stock=gtk.STOCK_OK)
+    ok.connect("clicked", ok_clicked, email, text)
+
+    buttons_hbox = gtk.HBox()
+    buttons_hbox.pack_start(cancel)
+    buttons_hbox.pack_start(ok)
+
+    vbox = gtk.VBox()
+    vbox.pack_start(email_hbox, False)
+    vbox.pack_start(ruler, False)
+    vbox.pack_start(text_label, False)
+    vbox.pack_start(scroller)
+    vbox.pack_start(buttons_hbox, False)
+
+    window = gtk.Window()
+    window.set_title(TITLE)
+    window.resize(500, 400)
+    window.add(vbox)
+
+    window.show_all()
+    gtk.main()
+
+if __name__ == '__main__':
+    run_gui()
+    sys.exit(0)
+
diff --git a/outils/ip2cc b/outils/ip2cc
new file mode 100755 (executable)
index 0000000..ea049ec
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Depends: python-geoip
+import sys
+import re
+try:
+    import GeoIP
+except:
+    print "Support GeoIP non disponible. Installer le paquet 'python-geoip'."
+    sys.exit(1)
+
+PATTERN_IP4 = r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
+#REPLACEMENT_IP4 = '<%(cc)s>%(ip4)s'
+REPLACEMENT_IP4 = '<\033[1;31m%(cc)s\033[m>\033[34m%(ip4)s\033[m'
+
+gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
+
+def ip4_to_cc(matchobj):
+    ip4 = matchobj.group(0)
+    cc = gi.country_code_by_addr(ip4)
+    if cc is None: cc = '??'
+    return REPLACEMENT_IP4 % {'cc': cc, 'ip4': ip4}
+
+pattern = re.compile(PATTERN_IP4, re.MULTILINE)
+sys.stdout.write(re.sub(pattern, ip4_to_cc, sys.stdin.read()))
diff --git a/outils/ooo-text2date b/outils/ooo-text2date
new file mode 100755 (executable)
index 0000000..7b2157c
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import sys
+import re
+
+PAT1 = r'<table:table-cell (?P<attrs>[^>]*)office:value-type="string">(?P<s1>\s*)<text:p>(?P<day>[0-9][0-9])/(?P<month>[0-9][0-9])/(?P<year>[0-9][0-9])</text:p>(?P<s2>\s*)</table:table-cell>'
+PAT2 = r'<table:table-cell \g<attrs>office:value-type="date" office:date-value="%(year)s-\g<month>-\g<day>">\g<s1><text:p>\g<day>/\g<month>/\g<year></text:p>\g<s2></table:table-cell>'
+
+def text2date(matchobj):
+    year = int(matchobj.group('year'))
+    if year < 100: year += 1900
+    if year < 1930: year += 100
+    return matchobj.expand(PAT2) % {'year': year}
+
+pattern = re.compile(PAT1, re.MULTILINE)
+sys.stdout.write(re.sub(pattern, text2date, sys.stdin.read()))