1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#!/usr/bin/python
#
# popbugs - Find RC bugs in packages you commonly use
# Matt Zimmerman <mdz@debian.org> 2001
#
import sys
import re
import os
import urllib2
import tempfile
import getopt
usage = '''Usage: popbugs [{-o|--output=} {outputfile|-}] [popularity-contest log]\n'''
popconfile = '/var/log/popularity-contest'
bugurl = 'http://bugs.debian.org/release-critical/other/all.html'
outputfile = None
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:",
["help","output="])
except getopt.GetoptError:
sys.stderr.write(usage)
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
sys.stdout.write(usage)
sys.exit()
elif o in ("-o", "--output"):
outputfile = a
if len(args) >= 1:
popconfile = args[0]
if not os.path.exists(popconfile):
sys.stderr.write('''
I cannot file the popularity-contest data you pointed me to.
This program requires the data collected from popularity-contest
in order to work.
''')
sys.exit(1)
else:
if not os.path.exists(popconfile):
if not os.path.exists('/usr/sbin/popularity-contest'):
sys.stderr.write('''
The popularity-contest package does not appear to be installed.
This program requires the data collected from popularity-contest
in order to work.
''')
sys.exit(1)
sys.stderr.write('''
There is no popularity-contest data present on your system. This
probably means that popularity-contest has not yet run since it
was installed. Try running /etc/cron.weekly/popularity-contest by
hand to collect some data.
''')
sys.exit(1)
if outputfile == None:
output = tempfile.NamedTemporaryFile(suffix='.html')
outputfile = output.name
view = 1
elif outputfile == '-':
output = sys.stdout
view = 0
else:
output = open(outputfile, 'w')
view = 0
class Package:
def __init__(self, name, atime):
self.name = name
self.atime = atime
packages = {}
pkglist = []
popcon = open(popconfile,'r')
for line in popcon.readlines():
if len(line) == 0 or line.find(':') != -1:
continue
fields = line.split()
if len(fields) != 4:
continue
if (fields[0] == 'POPULARITY-CONTEST-0' or
fields[0] == 'END-POPULARITY-CONTEST-0'):
continue
(atime, ctime, package, pathname) = fields
# if pathname == '<NOFILES>' or pathname == '<RECENT-CTIME>':
# continue
packages[package] = Package(package,atime)
pkglist.append(packages[package])
popcon.close()
page = urllib2.urlopen(bugurl).readlines()
while page:
line = page.pop(0)
output.write(line)
if line.startswith('<pre>'):
break
packagere = re.compile('^<a name="([^"]+)"><strong>Package:.*')
while page:
m = packagere.match(page[0])
if m:
html = ''
while page:
line = page.pop(0)
html += line
if line == '\n' or (page and packagere.match(page[0])):
# another paragraph started with no newline
break
pkgname = m.group(1)
if pkgname in packages:
packages[pkgname].html = html
else:
if page[0].startswith('</pre>'):
break
page.pop(0)
pkglist.sort(lambda a,b: -cmp(a.atime,b.atime))
for package in pkglist:
if hasattr(package,'html'):
output.write(package.html)
output.write('\n')
output.writelines(page)
output.flush()
if view:
os.system('sensible-browser file://' + outputfile)
|