<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/python

from urllib2 import urlopen
from argparse import ArgumentParser
import re
import os

class Task():

    def __init__(self, task, args):

        self.style = None
        self.bug = None
        self.message = None

        if args.not_needed:
            self.style = 'background:#f5f5f5;color:#333333'
        elif args.in_progress:
            self.style = 'background:#D9EDF7;color:#31708F'
        elif args.warning:
            self.style = 'background:#FCF8E3;color:#8A6D3B'
        elif args.done:
            self.style = 'background:#DFF0D8;color:#3C763D'
        elif args.error:
            self.style = 'background:#F2DEDE;color:#A94442'
        elif re.match(r'&lt;style="(.*)"&gt;', task):
            self.style = re.findall(r'&lt;style="(.*)"&gt;', task)[0]

        if args.bug:
            self.bug = args.bug
        elif re.search(r'&lt;&lt;Bug\(debian (.*)\)&gt;&gt;', task):
            self.bug = re.findall(r'&lt;&lt;Bug\(debian (.*)\)&gt;&gt;', task)[0]

        if args.message:
            self.message = args.message
        elif len(task.split('&gt;&gt;')) &gt; 1:
            self.message = task.split('&gt;&gt;')[1].strip()
        elif len(task.split('&gt;')) &gt; 1:
            self.message = task.split('&gt;')[1].strip()
        else:
            self.message = task

    def __str__(self):
        result = ""
        if self.style:
            result += '&lt;style="%s"&gt;' % self.style
        if self.bug:
            result += " &lt;&lt;Bug(debian %s)&gt;&gt;" % self.bug
        if self.message:
            result += " %s" % self.message
        return result


def _edit_line(line, args):
    info = line.split('||')

    info[-2] = "%s" % Task(info[-2], args)

    return '||'.join(info)


def main():

    if not os.path.exists('/usr/bin/xclip'):
        print("Install xclip:\n\n\tsudo apt-get install xclip\n")
        exit(1)

    usage = "%(prog)s [options] package_name"
    parser = ArgumentParser(prog='debomatic-webui-wiki', usage=usage)
    group = parser.add_mutually_exclusive_group()

    group.add_argument('-d', '--done', action="store_true", \
        default=False, help='job complete')
    group.add_argument('-e', '--error', action="store_true", \
        default=False, help='there is some strong issue')
    group.add_argument('-i', '--in-progress', action="store_true", \
        default=False, help='work in progress')
    group.add_argument('-n', '--not-needed', action="store_true", \
        default=False, help='no work needed')
    group.add_argument('-w', '--warning', action="store_true", \
        default=False, help='someone else has been warned about')


    parser.add_argument('-b', '--bug', help="add a debian bug")
    parser.add_argument('-m', '--message', help="leave a message")

    parser.add_argument('package_name', help='the package name')

    args = parser.parse_args()

    url_base = "http://wiki.ubuntu-it.org/LeoIannacone/Debomatic-webui"

    page = urlopen('%s?action=raw' % url_base).read().split('\n')

    found = False
    for i in range(0, len(page)):
        if page[i].find("%s (" % args.package_name) &gt; 0:
            found = True
            page[i] = _edit_line(page[i], args)
            break
    if not found:
        print("%s not found." % args.package_name)
        exit(1)

    with os.popen('xclip -selection c', 'w') as xclip:
        xclip.write('\n'.join(page))

    print("Result is in your clipboard. Just paste in the browser.")
    os.system("xdg-open %s?action=edit&amp;editor=text" % url_base)


if __name__ == '__main__':
    main()
</pre></body></html>