ubuntu-dev-tools/massfile

124 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
#
# (C) Canonical, 2007, GPL v3
2007-09-27 09:44:58 +02:00
import os
import sys
import email
import subprocess
2007-09-27 09:44:58 +02:00
import launchpadbugs.connector as Connector
2007-09-27 09:44:58 +02:00
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":
instr[field] = instructions.get(field)
return instr
2007-09-27 09:44:58 +02:00
def read_list():
pack_list = set()
2007-09-27 09:44:58 +02:00
listfile = open("list")
for line in listfile.readlines():
if line.strip()!="":
pack_list.add(line.strip("\n"))
2007-09-27 09:44:58 +02:00
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 = os.path.expanduser("~/.lpcookie")
# try:
bug = Bug.New(product={"name": config["sourcepackage"], "target": "ubuntu"},
summary=config["subject"],
description=config["text"])
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"]
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 main():
if not check_configfiles():
sys.exit(1)
if not os.path.exists(os.path.expanduser("~/.lpcookie")):
print >> sys.stderr, \
"Launchpad cookie not found in ~/.lpcookie."
sys.exit(1)
config = read_config()
pack_list = read_list()
buglist = read_buglist(config["buglist-url"])
2007-09-27 09:44:58 +02:00
for pack in pack_list:
if pack not in buglist:
config["text"] = config["text"].replace("$pack", pack)
config["subject"] = config["subject"].replace("$pack", pack)
config["sourcepackage"] = pack
2007-09-27 09:44:58 +02:00
file_bug(config)
if __name__ == '__main__':
main()
2007-09-27 09:44:58 +02:00