Alessio Treglia

everybody lies
  • it blog
  • rss
  • Home
  • About
  • Roma3 WiFi Authenticator
  • 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 »

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

Sponsor

About me


Send me a mail

Categories

Bugs and issues Hardy Howtos and docs Kernel and modules Planet Ubuntu Python Wiki and documentation

Recent comments

  • Alessio Treglia: Realtek’s modules, new version has been released | Christian eBuddy Blog on How to compile r8168 and r8101 modules for Realtek ethernet adapters
  • erUSUL on Realtek’s modules, new version has been released
  • Ste on How to compile r8168 and r8101 modules for Realtek ethernet adapters
  • Herman Bos on How to compile r8168 and r8101 modules for Realtek ethernet adapters
  • Eddie on python -c “print ‘SGVsbG8gcGxhbmV0IQ==\n’.decode(’base64′)”

Archive

Ubuntu in Italian

Versione a 32 bit

RSS Planet Ubuntu

  • Fabián Rodríguez: Massively purchase proprietary software without any invitations to tender: get sued by your local free software association
  • Ubuntu Server blog: Server Team 20080826 meeting minutes
  • Matt Zimmerman: Is it cold in here, or is it me?
  • Siegfried Gevatter: Ubiquity - Connecting the web with language
  • Aaron Toponce: Dear Lazyweb- RAID/LVM Crossroads Decision

License

Contents of this blog are published under a copyleft license


Creative Commons Attribution-ShareAlike 2.5 Italy

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox