| 1 |
#!/usr/bin/env python
|
| 2 |
|
| 3 |
# Show all bugs with a specific keyword
|
| 4 |
# Copyright (C) 2002, 2004 Martin Michlmayr <tbm@cyrius.com>
|
| 5 |
# $Id$
|
| 6 |
|
| 7 |
# This program is free software; you can redistribute it and/or modify
|
| 8 |
# it under the terms of the GNU General Public License as published by
|
| 9 |
# the Free Software Foundation; either version 2 of the License, or
|
| 10 |
# (at your option) any later version.
|
| 11 |
|
| 12 |
# This program is distributed in the hope that it will be useful,
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
# GNU General Public License for more details.
|
| 16 |
|
| 17 |
# You should have received a copy of the GNU General Public License
|
| 18 |
# along with this program; if not, write to the Free Software
|
| 19 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 20 |
|
| 21 |
import ldap, string, sys, os.path, re
|
| 22 |
import apt_pkg
|
| 23 |
|
| 24 |
def help():
|
| 25 |
print """Usage: bts-keywords [OPTION]... keywords
|
| 26 |
Show all bugs with a specific keyword
|
| 27 |
|
| 28 |
Options:
|
| 29 |
-a, --all-keywords Only show bugs which have all specified keywords
|
| 30 |
-f, --file Write output to file in specific format
|
| 31 |
-v, --verbose Display verbose messages
|
| 32 |
"""
|
| 33 |
sys.exit(1)
|
| 34 |
|
| 35 |
def parse_args(config):
|
| 36 |
global Options
|
| 37 |
|
| 38 |
apt_pkg.init()
|
| 39 |
Cnf = apt_pkg.newConfiguration()
|
| 40 |
apt_pkg.ReadConfigFileISC(Cnf, config)
|
| 41 |
|
| 42 |
Arguments = [("h", "help", "BTS-Keywords::Options::Help"),
|
| 43 |
("a", "all-keywords", "BTS-Keywords::Options::All-Keywords", "IntVal"),
|
| 44 |
("f", "file", "BTS-Keywords::Options::File", "HasArg"),
|
| 45 |
("v", "verbose", "BTS-Keywords::Options::Verbose", "IntLevel")]
|
| 46 |
|
| 47 |
keywords = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
|
| 48 |
Options = Cnf.SubTree("BTS-Keywords::Options")
|
| 49 |
|
| 50 |
if Options["Help"]:
|
| 51 |
help()
|
| 52 |
if not keywords:
|
| 53 |
print "You didn't specify any keywords. Run bts-keywords --help for help."
|
| 54 |
sys.exit(1)
|
| 55 |
return keywords
|
| 56 |
|
| 57 |
def main(keywords):
|
| 58 |
try:
|
| 59 |
bts = ldap.open("master.debian.org", 10101)
|
| 60 |
except ldap.LDAPError, error:
|
| 61 |
print "Cannot connect to LDAP server: %s" % error[1]
|
| 62 |
sys.exit(1)
|
| 63 |
base = "dc=current,dc=bugs,dc=debian,dc=org"
|
| 64 |
bts.bind(base, "", ldap.AUTH_SIMPLE)
|
| 65 |
attrs = ["debbugsPackage", "debbugsID", "debbugsTitle", "debbugsState", "debbugsSeverity", "debbugsTag"]
|
| 66 |
# Create a well formed LDAP query
|
| 67 |
query = string.join(map(lambda tag: "(debbugsTag=%s)" % tag, keywords), "")
|
| 68 |
if len(keywords) > 1:
|
| 69 |
if int(Options["All-Keywords"]):
|
| 70 |
logic_op = "&"
|
| 71 |
else:
|
| 72 |
logic_op = "|"
|
| 73 |
query = "(" + logic_op + query + ")"
|
| 74 |
result = bts.search_s(base, ldap.SCOPE_BASE, query, attrs)
|
| 75 |
bts.unbind()
|
| 76 |
|
| 77 |
if int(Options["Verbose"]):
|
| 78 |
try:
|
| 79 |
input = open("/org/qa.debian.org/data/ftp/Maintainers", "r")
|
| 80 |
except (IOError, OSError):
|
| 81 |
print "Maintainers file not found!"
|
| 82 |
sys.exit(1)
|
| 83 |
|
| 84 |
maintainers = { }
|
| 85 |
for line in input.readlines():
|
| 86 |
# Python 1.5 ignores maxsplit in re.split() so this won't work:
|
| 87 |
## package, maintainer = re.split("\s+', line, 2)
|
| 88 |
# Thus using the following solution:
|
| 89 |
line = string.rstrip(re.sub('\s+', ' ', line))
|
| 90 |
package, maintainer = string.split(line, ' ', 1)
|
| 91 |
maintainers[package] = maintainer
|
| 92 |
input.close()
|
| 93 |
|
| 94 |
bug_count = 0
|
| 95 |
info = {}
|
| 96 |
bugs_per_package = {}
|
| 97 |
for _, dict in result:
|
| 98 |
if dict["debbugsState"] == "done":
|
| 99 |
continue
|
| 100 |
if dict.has_key("debbugsTag") and "fixed" in dict["debbugsTag"]:
|
| 101 |
continue
|
| 102 |
bugid = int(dict["debbugsID"][0])
|
| 103 |
package = string.strip(dict["debbugsPackage"][0])
|
| 104 |
if not bugs_per_package.has_key(package):
|
| 105 |
bugs_per_package[package] = []
|
| 106 |
bugs_per_package[package].append(bugid)
|
| 107 |
info[bugid] = {}
|
| 108 |
info[bugid]["package"] = package
|
| 109 |
info[bugid]["subject"] = dict["debbugsTitle"][0]
|
| 110 |
info[bugid]["keywords"] = dict.get("debbugsTags", [""])
|
| 111 |
info[bugid]["severity"] = dict["debbugsSeverity"][0]
|
| 112 |
bug_count = bug_count + 1
|
| 113 |
|
| 114 |
if Options["File"]:
|
| 115 |
try:
|
| 116 |
output = open(Options["File"], "w")
|
| 117 |
except (IOError, OSError):
|
| 118 |
print "Cannot open file '%s' for writing." % Options["File"]
|
| 119 |
sys.exit(1)
|
| 120 |
output.write(`bug_count` + "\n")
|
| 121 |
output.write("\n")
|
| 122 |
|
| 123 |
packages = bugs_per_package.keys()
|
| 124 |
packages.sort()
|
| 125 |
first_package = 1
|
| 126 |
for package in packages:
|
| 127 |
bugs_per_package[package].sort()
|
| 128 |
if int(Options["Verbose"]):
|
| 129 |
if not first_package: print
|
| 130 |
if maintainers.has_key(package):
|
| 131 |
print "%s - %s" % (package, maintainers[package])
|
| 132 |
else:
|
| 133 |
print package
|
| 134 |
|
| 135 |
for bugid in bugs_per_package[package]:
|
| 136 |
if Options["File"]:
|
| 137 |
output.write(package + "\n")
|
| 138 |
output.write(`bugid` + "\n")
|
| 139 |
output.write(info[bugid]["subject"] + "\n")
|
| 140 |
output.write(info[bugid]["severity"] + "\n")
|
| 141 |
output.write(info[bugid]["keywords"] + "\n")
|
| 142 |
output.write("\n")
|
| 143 |
else:
|
| 144 |
if int(Options["Verbose"]):
|
| 145 |
print " #%s: %s" % (bugid, info[bugid]["subject"])
|
| 146 |
else:
|
| 147 |
print "%s: #%s: %s" % (package, bugid, info[bugid]["subject"])
|
| 148 |
first_package = 0
|
| 149 |
|
| 150 |
if Options["File"]:
|
| 151 |
output.close()
|
| 152 |
|
| 153 |
# main
|
| 154 |
|
| 155 |
keywords = parse_args(os.path.dirname(sys.argv[0]) + "/bts.conf")
|
| 156 |
main(keywords)
|
| 157 |
|