From 8a7d5f6fd348c53a30cde59a4324eecd2bee8d7a Mon Sep 17 00:00:00 2001 From: Progfou Date: Tue, 22 Mar 2011 03:44:05 +0700 Subject: [PATCH] =?utf8?q?Quelques=20mini-outils=20de=20plus=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- outils/auf-reportbug | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ outils/ip2cc | 25 ++++++++++++++++ outils/ooo-text2date | 16 ++++++++++ 3 files changed, 122 insertions(+) create mode 100755 outils/auf-reportbug create mode 100755 outils/ip2cc create mode 100755 outils/ooo-text2date diff --git a/outils/auf-reportbug b/outils/auf-reportbug new file mode 100755 index 0000000..a99115b --- /dev/null +++ b/outils/auf-reportbug @@ -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 index 0000000..ea049ec --- /dev/null +++ b/outils/ip2cc @@ -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 index 0000000..7b2157c --- /dev/null +++ b/outils/ooo-text2date @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import sys +import re + +PAT1 = r'[^>]*)office:value-type="string">(?P\s*)(?P[0-9][0-9])/(?P[0-9][0-9])/(?P[0-9][0-9])(?P\s*)' +PAT2 = r'office:value-type="date" office:date-value="%(year)s-\g-\g">\g\g/\g/\g\g' + +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())) -- 1.7.10.4