| 1 |
tbm |
161 |
# The module which forms the heart of the MIA scripts
|
| 2 |
tbm |
5 |
# Copyright (C) 2001 Martin Michlmayr <tbm@cyrius.com>
|
| 3 |
tbm |
21 |
# $Id$
|
| 4 |
tbm |
5 |
|
| 5 |
|
|
# This program is free software; you can redistribute it and/or modify
|
| 6 |
|
|
# it under the terms of the GNU General Public License as published by
|
| 7 |
|
|
# the Free Software Foundation; either version 2 of the License, or
|
| 8 |
|
|
# (at your option) any later version.
|
| 9 |
|
|
|
| 10 |
|
|
# This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
# GNU General Public License for more details.
|
| 14 |
|
|
|
| 15 |
|
|
# You should have received a copy of the GNU General Public License
|
| 16 |
|
|
# along with this program; if not, write to the Free Software
|
| 17 |
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
# This is a collection of software to track down developers who are
|
| 21 |
|
|
# Missing In Action (MIA).
|
| 22 |
|
|
|
| 23 |
|
|
# To Veronika, who is missing in action -- action's not the same without her.
|
| 24 |
|
|
# -- tbm
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
tbm |
134 |
import os, stat, sys, re, time, string
|
| 28 |
tbm |
5 |
|
| 29 |
|
|
days = 21
|
| 30 |
|
|
origin = '/org/qa.debian.org/mia/db'
|
| 31 |
|
|
|
| 32 |
|
|
info = { }
|
| 33 |
tbm |
154 |
matches = { }
|
| 34 |
tbm |
5 |
|
| 35 |
|
|
def find_status(path=origin):
|
| 36 |
|
|
files = []
|
| 37 |
|
|
|
| 38 |
tbm |
164 |
try:
|
| 39 |
|
|
for file in os.listdir(path):
|
| 40 |
|
|
root, ext = os.path.splitext(file)
|
| 41 |
|
|
if ext == '.summary':
|
| 42 |
|
|
files.append(root)
|
| 43 |
|
|
except OSError:
|
| 44 |
|
|
print 'Cannot find directory of database: %s' % path
|
| 45 |
|
|
sys.exit(1)
|
| 46 |
tbm |
5 |
|
| 47 |
|
|
return files
|
| 48 |
|
|
|
| 49 |
tbm |
150 |
|
| 50 |
tbm |
5 |
def read_status(files):
|
| 51 |
|
|
for file in files:
|
| 52 |
|
|
try:
|
| 53 |
|
|
summary = open(origin + '/' + file + '.summary', 'r')
|
| 54 |
|
|
except IOError:
|
| 55 |
|
|
print 'Cannot open summary file %s' % file
|
| 56 |
|
|
sys.exit(1)
|
| 57 |
|
|
|
| 58 |
|
|
info[file] = { }
|
| 59 |
|
|
|
| 60 |
|
|
for line in summary.readlines():
|
| 61 |
|
|
result = re.search("(\d+):\s*(.*)", line)
|
| 62 |
|
|
|
| 63 |
|
|
if result is not None:
|
| 64 |
tbm |
155 |
info[file][int(result.group(1))] = result.group(2)
|
| 65 |
tbm |
5 |
else:
|
| 66 |
|
|
print 'Error parsing file %s: %s' % (file, line)
|
| 67 |
|
|
sys.exit(1)
|
| 68 |
|
|
|
| 69 |
|
|
summary.close()
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
def write_status(file, id, summary):
|
| 73 |
|
|
try:
|
| 74 |
|
|
status = open(origin + '/' + file + '.summary', 'a')
|
| 75 |
|
|
except IOError:
|
| 76 |
|
|
print 'Cannot open summary file to write!'
|
| 77 |
|
|
sys.exit(1)
|
| 78 |
|
|
|
| 79 |
tbm |
12 |
string = str(id) + ': ' + summary + '\n'
|
| 80 |
tbm |
5 |
status.write(string)
|
| 81 |
|
|
status.close()
|
| 82 |
|
|
|
| 83 |
tbm |
150 |
|
| 84 |
tbm |
158 |
def get_all_files():
|
| 85 |
tbm |
159 |
files = info.keys()
|
| 86 |
tbm |
158 |
files.sort()
|
| 87 |
|
|
return files
|
| 88 |
|
|
|
| 89 |
|
|
|
| 90 |
tbm |
166 |
def get_selected_files(pattern):
|
| 91 |
|
|
files = get_all_files()
|
| 92 |
|
|
selection = [ ]
|
| 93 |
|
|
cpattern = re.compile(pattern, re.I)
|
| 94 |
|
|
for file in files:
|
| 95 |
|
|
if grep_items(file, cpattern):
|
| 96 |
|
|
selection.append(file)
|
| 97 |
|
|
return selection
|
| 98 |
|
|
|
| 99 |
|
|
|
| 100 |
|
|
def grep_items(file, cpattern):
|
| 101 |
|
|
for item in info[file].values():
|
| 102 |
|
|
if cpattern.search(item):
|
| 103 |
|
|
return 1
|
| 104 |
|
|
|
| 105 |
|
|
|
| 106 |
tbm |
5 |
def print_history(file):
|
| 107 |
|
|
all_contacts = info[file].keys()
|
| 108 |
|
|
all_contacts.sort()
|
| 109 |
|
|
for when in all_contacts:
|
| 110 |
|
|
date = time.gmtime(int(when))
|
| 111 |
|
|
print ' %s: %.60s' % (time.strftime('%Y-%m-%d', date), info[file][when])
|
| 112 |
|
|
|
| 113 |
tbm |
134 |
|
| 114 |
|
|
def latest(file):
|
| 115 |
tbm |
155 |
return max(info[file].keys())
|
| 116 |
tbm |
134 |
|
| 117 |
|
|
|
| 118 |
tbm |
162 |
def should_check(file, ttl=days):
|
| 119 |
|
|
if (time.time() - latest(file)) > (ttl * 3600 * 24):
|
| 120 |
tbm |
160 |
return 1
|
| 121 |
|
|
|
| 122 |
|
|
|
| 123 |
tbm |
150 |
def compile_matches():
|
| 124 |
tbm |
134 |
matches['ignore'] = [ 'willfix' ]
|
| 125 |
tbm |
191 |
matches['in'] = [ 'S-V', 'FHS', 'RC', 'NMU', 'Hint', 'email' ]
|
| 126 |
tbm |
143 |
matches['out'] = [ 'Fixed', 'Orphaned', 'Orphaning', 'Removed',
|
| 127 |
tbm |
187 |
'Removing', 'Hijack' ]
|
| 128 |
tbm |
147 |
matches['latest'] = [ 'Maintainer has no packages anymore', 'Retired',
|
| 129 |
|
|
'Retiring' ]
|
| 130 |
tbm |
134 |
|
| 131 |
|
|
for key in matches.keys():
|
| 132 |
|
|
matches[key] = map(string.lower, matches[key])
|
| 133 |
|
|
|
| 134 |
tbm |
150 |
|
| 135 |
|
|
def last_is_final(file):
|
| 136 |
tbm |
155 |
if string.lower(info[file][latest(file)]) in matches['latest']:
|
| 137 |
tbm |
150 |
return 1
|
| 138 |
|
|
|
| 139 |
|
|
|
| 140 |
|
|
def has_stuff_todo(file):
|
| 141 |
|
|
if last_is_final(file):
|
| 142 |
tbm |
134 |
return
|
| 143 |
|
|
|
| 144 |
tbm |
154 |
found = { }
|
| 145 |
|
|
for key in matches.keys():
|
| 146 |
|
|
found[key] = { }
|
| 147 |
|
|
|
| 148 |
tbm |
134 |
for entry in info[file].values():
|
| 149 |
|
|
fields = re.split(':\s+', entry, 2)
|
| 150 |
|
|
if len(fields) > 1:
|
| 151 |
tbm |
136 |
what = re.split('\s+|&', fields[0])[0]
|
| 152 |
tbm |
171 |
packages = re.split(',\s*', string.lower(fields[1]))
|
| 153 |
tbm |
134 |
for key in matches.keys():
|
| 154 |
|
|
if string.lower(what) in matches[key]:
|
| 155 |
tbm |
148 |
for package in packages:
|
| 156 |
|
|
found[key][package] = 1
|
| 157 |
tbm |
144 |
break
|
| 158 |
tbm |
134 |
else:
|
| 159 |
|
|
print 'Error: do not know what to do with "%s"' % what
|
| 160 |
|
|
sys.exit(1)
|
| 161 |
|
|
|
| 162 |
tbm |
192 |
# show cases without any INs.
|
| 163 |
tbm |
165 |
if not found['in']:
|
| 164 |
tbm |
135 |
return [ 'no-todo-list' ]
|
| 165 |
|
|
|
| 166 |
tbm |
148 |
for item in found['out'].keys():
|
| 167 |
tbm |
134 |
try:
|
| 168 |
tbm |
148 |
del found['in'][item]
|
| 169 |
|
|
except KeyError:
|
| 170 |
tbm |
134 |
print 'Warning: "%s" was not on the TODO list' % item
|
| 171 |
|
|
|
| 172 |
tbm |
165 |
if found['in']:
|
| 173 |
tbm |
134 |
# something has not been dealt with yet
|
| 174 |
tbm |
149 |
outstanding = found['in'].keys()
|
| 175 |
|
|
outstanding.sort()
|
| 176 |
|
|
return outstanding
|
| 177 |
tbm |
134 |
|
| 178 |
tbm |
151 |
|
| 179 |
|
|
# 'main()'
|
| 180 |
|
|
|
| 181 |
tbm |
153 |
compile_matches()
|
| 182 |
tbm |
151 |
|