Alessio Treglia

everybody lies
  • Quality Assurance
  • it blog
  • rss
  • Home
  • About
  • Roma3 WiFi Authenticator
  • Installation Report Generator
  • Contact

A new macro for the Italian wiki

quadrispro | July 5, 2008

This Stephan Hermann’s article shows a simple and useful macro, which gets a Launchpad bug’s id and returns a link to its bugtracker page.

So, I had an idea: why don’t generalize it and make it compatible with other projects bugtrackers?

Ok, let’s start analyzing the code:


from MoinMoin import config, wikiutil

projects = {
    "ubuntu"    : "https://bugs.launchpad.net/ubuntu/+bug/%d",
    "debian"	: "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%d",
    "gnome"     : "http://bugzilla.gnome.org/show_bug.cgi?id=%d",
    "kde"       : "http://bugs.kde.org/show_bug.cgi?id=%d",
    "xfce"      : "http://bugzilla.xfce.org/show_bug.cgi?id=%d"
    }

projects_emblems = {
    "ubuntu"    : "https://launchpadlibrarian.net/9608570/ubuntu_emblem.png",
    "debian"	: "http://www.debian.org/favicon.ico",
    "gnome"     : "https://launchpadlibrarian.net/11396521/gnome.png",
    "kde"       : "https://launchpadlibrarian.net/7101115/klogo-official-crystal-14.png",
    "xfce"      : "https://launchpadlibrarian.net/4040580/mouse.png"
    }

def NoProjectSelectedException(Exception):
    """
    The macro raises an instance of this exception
    when the argument doesn't contain any project
    valid name.
    """
    def __init__(self, message):
        """
        Default __init__ method.
        """
        Exception.__init__(self, message)

def args_to_dict(args):
    """
    This method converts a string in a dictionary.
    It uses project's name (if valid) as key, and
    a list of bug ids as value.
    For example:

    The call:

    args_to_dict("gnome 3 4 6 ubuntu 1 9 6 kde 7 xfce")

    returns:

    {'kde': [7], 'xfce': [], 'gnome': [3, 4, 6], 'ubuntu': [1, 9, 6]}
    """
    args_dict = dict()
    project_selected = None
    for i in projects.keys():
        args_dict[i] = list()
    if args:
        args_list = args.split()
        for cur in args_list:
            if cur in projects.keys():
                project_selected = cur
            elif project_selected != None:
                try:
                    args_dict[project_selected].append(int(cur))
                except ValueError:
                    raise ValueError, u"Carattere non valido, i bug devono essere indicati con numeri interi: %s"
            else:
                raise NoProjectSelectedException, u"Nessun progetto selezionato per i bug elencati: %s"
    return args_dict

def execute(macro,args):
    """
    Execute method. It formats and returns
    the result.
    """
    request=macro.request
    formatter=macro.formatter
    result=""
    try:
        args_dict = args_to_dict(args)
    except ValueError, e:
        raise ValueError(e.message % args)
    except NoProjectSelectedException, e:
        raise NoProjectSelectedException(e.message % args)
    for i in args_dict.keys(): # i = current project
        for j in args_dict[i]: # j = current bug id
            result += u'<img src="%s" />' % projects_emblems[i]
            # result+='<img src="https://launchpadlibrarian.net/7094128/launchpad-icon.png" /> '
            # result+=formatter.url(on=1,url="http://launchpad.net/bugs/%s" % i)
            result+=formatter.url(on=1,url=projects[i] % j)
            result+=u"#%d" % j
            result+=formatter.url(on=0)
            result+=" "
    return result

Just like all wiki macros, it gets a string and returns a formatted output, in according with a specific model: input string contains projects’ names and lists of related bugs’ ids, then the output will be an HTML line containing the project emblem, followed by bugtracker links.

The correct syntax is:

[[Bug(project1 bug_id_1 project2 bug_id_1 bug_id_2 project3 bug_id_1 bug_id_2 bug_id_3)]]

Isn’t it easy? There aren’t separators, you need to remember that bugs ids refer to the first previous project (the ids order isn’t important). In case of error, depending by its kind, one of two exceptions will raise.

If you would have an example, open an Ubuntu-It wiki page in text mode and insert this:


Bug segnalati: [[Bug(ubuntu 68 3 5 gnome 21 kde 9 xfce 8 debian 76)]]

That’s the result of the previous example:

A list of reported bugs

That’s all!

One more thing: I would bring to your attention the Ubuntu Italian Documentation Team bazaar branch, where you can find the source code of all our MoinMoin mods.

Categories
Planet Ubuntu, Python, Wiki and documentation
Comments rss
Comments rss
Trackback
Trackback

« python -c “print ‘SGVsbG8gcGxhbmV0IQ==\n’.decode(’base64′)” How to compile r8168 and r8101 modules for Realtek ethernet adapters »

One response

[...] - bookmarked by 3 members originally found by NarutoSan1

Bookmarks about Wiki | September 30, 2008 | 1:45 pm

[...] - bookmarked by 3 members originally found by NarutoSan1 on 2008-09-13 A new macro for the Italian wiki http://en.alessiotreglia.com/articles/a-new-macro-for-the-italian-wiki/ - bookmarked by 1 members [...]

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Click to cancel reply

Categories

Bugs and issues GTK+ Hardy Howtos and docs Installation Report Generator Kernel and modules Planet Ubuntu Python Wiki and documentation

Recent comments

  • estorino on Realtek’s modules, new version has been released
  • Brian Wilson on How to compile r8168 and r8101 modules for Realtek ethernet adapters
  • Constantine Tsardounis on How to compile r8168 and r8101 modules for Realtek ethernet adapters
  • quadrispro on Installation Report Generator
  • Søren Juul on Installation Report Generator

Archive

RSS Planet Ubuntu

  • Jorge Castro: I broke the internets
  • Jeff Bailey: We're here!
  • Celeste Lyn Paul: System Settings as a Design Lesson
  • Mackenzie Morgan: Compiz? Emerald? Metacity? What's the Difference?
  • Jorge Castro: Lenovo X200 and Ubuntu 8.10
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox