ubuntu-dev-tools/massfile
2008-08-04 20:51:47 +02:00

156 lines
4.3 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (C) Canonical, 2007, GPL v3
#
# Modified by Iain Lane <iain@orangesquash.org.uk>, taking some code written by
# Daniel Hahler <ubuntu@thequod.de>
import os
import sys
import email
import subprocess
import glob
import launchpadbugs.connector as Connector
def read_config():
instructions_file = open("instructions")
instructions = email.message_from_file(instructions_file)
instructions_file.close()
instr = dict()
for field in "subject", "assignee", "subscribers", "tags", "text", \
"buglist-url", "status":
instr[field] = instructions.get(field)
return instr
def read_list():
pack_list = set()
listfile = open("list")
for line in listfile.readlines():
if line.strip()!="":
pack_list.add(line.strip("\n"))
listfile.close()
return pack_list
def file_bug():
Bug = Connector.ConnectBug()
Bug.authentication = os.path.expanduser("~/.lpcookie")
def check_configfiles():
result = True
bin_path = os.path.dirname(os.path.abspath(__file__))
if bin_path == "/usr/bin":
example_dir = "/usr/share/doc/ubuntu-dev-tools/examples"
else:
example_dir = "%s/examples" % bin_path
if not os.path.exists("instructions"):
os.system("cp %s/massfile.instructions instructions" % example_dir)
print >> sys.stderr, \
"No 'instructions' file found. Copied template from %s." % \
example_dir
result = False
if not os.path.exists("list"):
os.system("cp %s/massfile.list list" % example_dir)
print >> sys.stderr, \
"No 'list' file found. Copied template from %s." % example_dir
result = False
return result
def file_bug(config):
Bug = Connector.ConnectBug()
Bug.authentication = cookie
try:
summary = config["subject"].replace("$pack", config["sourcepackage"])
description = config["text"].replace("$pack", config["sourcepackage"])
bug = Bug.New(product={"name": config["sourcepackage"],
"target": "ubuntu"},
summary=summary,
description=description)
print "Successfully filed bug %s: http://launchpad.net/bugs/%s" % \
(bug.bugnumber, bug.bugnumber)
for sub in config["subscribers"].split(","):
if sub.strip("\n").strip():
bug.subscribers.add(sub.strip("\n").strip())
for tag in config["tags"].split(","):
if tag.strip("\n").strip():
bug.tags.append(tag.strip("\n").strip())
bug.assignee = config["assignee"]
if config["status"]:
bug.status = config["status"].capitalize()
else:
bug.status = "Confirmed"
bug.commit()
except:
"Bug for '%s' was not filed." % config["sourcepackage"]
def read_buglist(url):
BugList = Connector.ConnectBugList()
packages = set()
if url:
buglist = BugList(url)
for bug in buglist.bugs:
packages.add(bug.sourcepackage)
return packages
def lp_cookie():
global cookie
cookie = None
# Search cookiefile (for authentication to lp)
if cookie == None:
try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite', '~/.mozilla/*/*/cookies.txt')
for try_glob in try_globs:
try:
cookiefile = glob.glob(os.path.expanduser(try_glob))[0]
except IndexError:
continue
# Found:
print "Using cookie file at «%s».\n" % cookiefile
cookie = cookiefile
break
if cookie == None:
raise RuntimeError("Could not find cookie file for Launchpad \
(looked in %s). You should be able to create a valid file by logging into \
Launchpad with Firefox") % ", ".join(try_globs)
def main():
if not check_configfiles():
sys.exit(1)
try:
lp_cookie()
except RuntimeError, e:
print e
sys.exit(1)
config = read_config()
pack_list = read_list()
buglist = read_buglist(config["buglist-url"])
for pack in pack_list:
if pack not in buglist:
config["sourcepackage"] = pack
file_bug(config)
if __name__ == '__main__':
main()