Ik heb gisteren aan een script gewerkt die de berichten op Launchpad kan plaatsten
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 23 okt 2010
@author: Ronnie van den Crommenacker (ronnie@ubuntu-nl.org)
TODO: Add mail['Reply-To'] somewhere?
'''
import re
import sys
import email
import logging
try:
from launchpadlib.launchpad import Launchpad, STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT
import lazr
except ImportError:
logging.warning('launchpadlib is not installed. You can install it by running:\
\nsudo apt-get install python-lauchpadlib')
sys.exit(1)
# Change this variables to your own needs
PROJECT = 'ubuntu-nl-artwork' # Name of the project, where the bug will be filed against
IDENTIFIER = 'Ubuntu-NL Forum Ticket' # Name which is send to Lauchpad for statistics
SERVICE = STAGING_SERVICE_ROOT # use 'EDGE_SERVICE_ROOT' of 'production' for the production server
CACHEDIR = "~/.cache/launchpadlib/" # Location where the login should be saved
LOG_FILENAME = '~/.cache/launchpadlib/forum_ticket.log' # The filename and location of the logging file
logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO)
def get_message(mail):
output = ''
msg = mail.get_payload()
if isinstance(msg, str):
return msg
else:
for m in msg:
output += '%s' % get_message(m)
return output
if __name__ == '__main__':
# Read the mail from standard input
mail = email.message_from_string(sys.stdin.read())
# Login to Launchpad. This requires one time login name inside the browser to authenticate
# The user should be granted full rights to the project
try:
#launchpad = Launchpad.login_anonymously(IDENTIFIER, SERVICE, CACHEDIR)
launchpad = Launchpad.login_with(IDENTIFIER, SERVICE, CACHEDIR, allow_access_levels=["WRITE_PUBLIC"])
except lazr.restfulclient.errors.HTTPError as error:
logging.warning('Could not login to launchpad. Error: ')
logging.warning(error)
sys.exit(1)
# Get the message from the mail
message = get_message(mail)
# Get the url from the message, to serve as tags
re_url = re.compile('http://forum.ubuntu-nl.org/(?P<url_board>.*)/(?P<url_topic>.*)/(?P<url_msg>.*)/')
url = re_url.search(message)
if url:
# Launchpad supports only the following symbols - + .
# Delete all the other symbols from the text
re_tag = re.compile(r'[^a-zA-Z0-9-\+\.]')
board = '.'.join(re_tag.split(url.group('url_board')))
topic = '.'.join(re_tag.split(url.group('url_topic')))
msg_id = '.'.join(re_tag.split(url.group('url_msg')))
tags = [board, topic, msg_id]
else:
logging.warning('No forum url found in the mail, continuing without adding tags and duplication')
tags = ''
# Get the project from Launchpad
try:
forum_project = launchpad.projects[PROJECT]
except:
logging.warning('Launchpad project with name "%s" does not exist. Ticket has not been made!' % PROJECT)
sys.exit(1)
# File and Submit a new private bug into the project
try:
new_bug = launchpad.bugs.createBug(title=mail['Subject'], description=message, private=True, target=forum_project, tags=tags)
except lazr.restfulclient.errors.HTTPError as error:
logging.warning('Bug not created!')
logging.warning(error)
sys.exit(1)
logging.info('Bug with id: %d successfully created' % new_bug.id)
# Search if there are projects with the same message tag and mark it as duplicate
for task in forum_project.searchTasks(tags=msg_id):
# Check if the bug itself is not already a duplicate
bug = task.bug
if not bug.duplicate_of:
new_bug.duplicate_of = bug
new_bug.lp_save()
logging.info('Bug is marked as duplicate of %d' % bug.id)
break
logging.info('Program ended without errors')
Het werkt op dit moment redelijk goed (als zijn er sinds vandaag login problemen bij Launchpad), dus ik kan het vandaag niet meer testen.
Het programma wordt uitgevoerd, met als input een Mail die het forum verstuurd aan de hand van de 'meld knop'. De mail wordt uitgelezen en een bug wordt op Launchpad aangemaakt. Bestaat er al een melding van hetzelfde bericht, dan wordt deze als duplicaat van het eerdere bericht gezet. Ook worden er tags toegevoegd per board en topic waar het bericht geplaatst wordt. Zo kunnen jullie een gemakkelijk overzicht krijgen of er bepaalde boards of topic erg veel meldingen oplevert.
Ik heb nog wel een vraag: Hoe antwoorden jullie nu via OTRS, gebeurt dit met een forum bericht naar de persoon van het gemelde bericht, of gebeurt dit met het email adres dat opgegeven wordt op het forum?
En willen jullie bijvoorbeeld ook de persoon die de post (die gemeld is) heeft geschreven als tag, zodat jullie een overzicht kunnen krijgen of deze persoon vaker ongepaste berichten op het forum plaatst?