You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
9.4 KiB
269 lines
9.4 KiB
19 years ago
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
# Copyright (C) 2001-2004 Anthony Towns <ajt@debian.org>
|
||
|
# Andreas Barth <aba@debian.org>
|
||
|
# Fabio Tranchitella <kobold@debian.org>
|
||
|
|
||
|
# This program is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
|
||
9 years ago
|
from collections import defaultdict
|
||
19 years ago
|
import re
|
||
|
|
||
9 years ago
|
|
||
13 years ago
|
class Excuse(object):
|
||
19 years ago
|
"""Excuse class
|
||
|
|
||
|
This class represents an update excuse, which is a detailed explanation
|
||
19 years ago
|
of why a package can or cannot be updated in the testing distribution from
|
||
19 years ago
|
a newer package in another distribution (like for example unstable).
|
||
|
|
||
|
The main purpose of the excuses is to be written in an HTML file which
|
||
|
will be published over HTTP. The maintainers will be able to parse it
|
||
|
manually or automatically to find the explanation of why their packages
|
||
|
have been updated or not.
|
||
|
"""
|
||
|
|
||
|
## @var reemail
|
||
|
# Regular expression for removing the email address
|
||
11 years ago
|
reemail = re.compile(r" *<.*?>")
|
||
19 years ago
|
|
||
|
def __init__(self, name):
|
||
19 years ago
|
"""Class constructor
|
||
|
|
||
|
This method initializes the excuse with the specified name and
|
||
|
the default values.
|
||
|
"""
|
||
19 years ago
|
self.name = name
|
||
|
self.ver = ("-", "-")
|
||
|
self.maint = None
|
||
|
self.urgency = None
|
||
|
self.daysold = None
|
||
|
self.mindays = None
|
||
|
self.section = None
|
||
13 years ago
|
self._is_valid = False
|
||
|
self._dontinvalidate = False
|
||
9 years ago
|
self.needs_approval = False
|
||
|
self.hints = []
|
||
11 years ago
|
self.forced = False
|
||
19 years ago
|
|
||
|
self.invalid_deps = []
|
||
13 years ago
|
self.deps = {}
|
||
19 years ago
|
self.sane_deps = []
|
||
19 years ago
|
self.break_deps = []
|
||
|
self.bugs = []
|
||
11 years ago
|
self.newbugs = set()
|
||
|
self.oldbugs = set()
|
||
11 years ago
|
self.reason = {}
|
||
19 years ago
|
self.htmlline = []
|
||
9 years ago
|
self.missing_builds = set()
|
||
|
self.missing_builds_ood_arch = set()
|
||
|
self.old_binaries = defaultdict(set)
|
||
9 years ago
|
self.policy_info = {}
|
||
19 years ago
|
|
||
10 years ago
|
def sortkey(self):
|
||
|
if self.daysold == None:
|
||
|
return (-1, self.name)
|
||
|
return (self.daysold, self.name)
|
||
|
|
||
13 years ago
|
@property
|
||
|
def is_valid(self):
|
||
|
return self._is_valid
|
||
|
|
||
|
@is_valid.setter
|
||
|
def is_valid(self, value):
|
||
|
self._is_valid = value
|
||
|
|
||
|
@property
|
||
|
def dontinvalidate(self):
|
||
|
return self._dontinvalidate
|
||
|
|
||
|
@dontinvalidate.setter
|
||
|
def dontinvalidate(self, value):
|
||
|
self._dontinvalidate = value
|
||
|
|
||
19 years ago
|
def set_vers(self, tver, uver):
|
||
19 years ago
|
"""Set the testing and unstable versions"""
|
||
19 years ago
|
if tver: self.ver = (tver, self.ver[1])
|
||
|
if uver: self.ver = (self.ver[0], uver)
|
||
|
|
||
|
def set_maint(self, maint):
|
||
19 years ago
|
"""Set the package maintainer's name"""
|
||
19 years ago
|
self.maint = self.reemail.sub("", maint)
|
||
|
|
||
|
def set_section(self, section):
|
||
19 years ago
|
"""Set the section of the package"""
|
||
19 years ago
|
self.section = section
|
||
|
|
||
|
def set_urgency(self, date):
|
||
19 years ago
|
"""Set the urgency of upload of the package"""
|
||
19 years ago
|
self.urgency = date
|
||
|
|
||
13 years ago
|
def add_dep(self, name, arch):
|
||
19 years ago
|
"""Add a dependency"""
|
||
13 years ago
|
if name not in self.deps: self.deps[name]=[]
|
||
|
self.deps[name].append(arch)
|
||
19 years ago
|
|
||
19 years ago
|
def add_sane_dep(self, name):
|
||
|
"""Add a sane dependency"""
|
||
|
if name not in self.sane_deps: self.sane_deps.append(name)
|
||
|
|
||
19 years ago
|
def add_break_dep(self, name, arch):
|
||
19 years ago
|
"""Add a break dependency"""
|
||
19 years ago
|
if (name, arch) not in self.break_deps:
|
||
|
self.break_deps.append( (name, arch) )
|
||
|
|
||
|
def invalidate_dep(self, name):
|
||
19 years ago
|
"""Invalidate dependency"""
|
||
19 years ago
|
if name not in self.invalid_deps: self.invalid_deps.append(name)
|
||
|
|
||
|
def setdaysold(self, daysold, mindays):
|
||
19 years ago
|
"""Set the number of days from the upload and the minimum number of days for the update"""
|
||
19 years ago
|
self.daysold = daysold
|
||
|
self.mindays = mindays
|
||
|
|
||
11 years ago
|
def force(self):
|
||
|
"""Add force hint"""
|
||
|
self.forced = True
|
||
|
|
||
19 years ago
|
def addhtml(self, note):
|
||
19 years ago
|
"""Add a note in HTML"""
|
||
19 years ago
|
self.htmlline.append(note)
|
||
|
|
||
9 years ago
|
def missing_build_on_arch(self, arch):
|
||
|
"""Note that the item is missing a build on a given architecture"""
|
||
|
self.missing_builds.add(arch)
|
||
|
|
||
|
def missing_build_on_ood_arch(self, arch):
|
||
|
"""Note that the item is missing a build on a given "out of date" architecture"""
|
||
|
self.missing_builds.add(arch)
|
||
|
|
||
|
def add_old_binary(self, binary, from_source_version):
|
||
|
"""Denote than an old binary ("cruft") is available from a previous source version"""
|
||
|
self.old_binaries[from_source_version].add(binary)
|
||
|
|
||
9 years ago
|
def add_hint(self, hint):
|
||
|
self.hints.append(hint)
|
||
|
|
||
19 years ago
|
def html(self):
|
||
19 years ago
|
"""Render the excuse in HTML"""
|
||
19 years ago
|
res = "<a id=\"%s\" name=\"%s\">%s</a> (%s to %s)\n<ul>\n" % \
|
||
|
(self.name, self.name, self.name, self.ver[0], self.ver[1])
|
||
|
if self.maint:
|
||
|
res = res + "<li>Maintainer: %s\n" % (self.maint)
|
||
10 years ago
|
if self.section and self.section.find("/") > -1:
|
||
19 years ago
|
res = res + "<li>Section: %s\n" % (self.section)
|
||
|
if self.daysold != None:
|
||
11 years ago
|
if self.mindays == 0:
|
||
|
res = res + ("<li>%d days old\n" % self.daysold)
|
||
|
elif self.daysold < self.mindays:
|
||
19 years ago
|
res = res + ("<li>Too young, only %d of %d days old\n" %
|
||
|
(self.daysold, self.mindays))
|
||
|
else:
|
||
|
res = res + ("<li>%d days old (needed %d days)\n" %
|
||
|
(self.daysold, self.mindays))
|
||
|
for x in self.htmlline:
|
||
|
res = res + "<li>" + x + "\n"
|
||
12 years ago
|
lastdep = ""
|
||
10 years ago
|
for x in sorted(self.deps, key=lambda x: x.split('/')[0]):
|
||
12 years ago
|
dep = x.split('/')[0]
|
||
|
if dep == lastdep: continue
|
||
|
lastdep = dep
|
||
19 years ago
|
if x in self.invalid_deps:
|
||
12 years ago
|
res = res + "<li>Depends: %s <a href=\"#%s\">%s</a> (not considered)\n" % (self.name, dep, dep)
|
||
19 years ago
|
else:
|
||
12 years ago
|
res = res + "<li>Depends: %s <a href=\"#%s\">%s</a>\n" % (self.name, dep, dep)
|
||
19 years ago
|
for (n,a) in self.break_deps:
|
||
|
if n not in self.deps:
|
||
|
res += "<li>Ignoring %s depends: <a href=\"#%s\">%s</a>\n" % (a, n, n)
|
||
13 years ago
|
if self.is_valid:
|
||
13 years ago
|
res += "<li>Valid candidate\n"
|
||
9 years ago
|
else:
|
||
|
res += "<li>Not considered\n"
|
||
19 years ago
|
res = res + "</ul>\n"
|
||
|
return res
|
||
11 years ago
|
|
||
11 years ago
|
def setbugs(self, oldbugs, newbugs):
|
||
|
""""Set the list of old and new bugs"""
|
||
11 years ago
|
self.newbugs.update(newbugs)
|
||
|
self.oldbugs.update(oldbugs)
|
||
11 years ago
|
|
||
11 years ago
|
def addreason(self, reason):
|
||
|
""""adding reason"""
|
||
|
self.reason[reason] = 1
|
||
|
|
||
9 years ago
|
# TODO: remove
|
||
|
def _text(self):
|
||
11 years ago
|
"""Render the excuse in text"""
|
||
|
res = []
|
||
|
for x in self.htmlline:
|
||
|
res.append("" + x + "")
|
||
|
return res
|
||
|
|
||
|
def excusedata(self):
|
||
|
"""Render the excuse in as key-value data"""
|
||
9 years ago
|
source = self.name
|
||
|
if '/' in source:
|
||
|
source = source.split("/")[0]
|
||
|
if source[0] == '-':
|
||
|
source = source[1:]
|
||
11 years ago
|
excusedata = {}
|
||
9 years ago
|
excusedata["excuses"] = self._text()
|
||
9 years ago
|
excusedata["item-name"] = self.name
|
||
|
excusedata["source"] = source
|
||
11 years ago
|
excusedata["old-version"] = self.ver[0]
|
||
|
excusedata["new-version"] = self.ver[1]
|
||
9 years ago
|
if self.maint:
|
||
|
excusedata['maintainer'] = self.maint
|
||
|
if self.section and self.section.find("/") > -1:
|
||
|
excusedata['component'] = self.section.split('/')[0]
|
||
9 years ago
|
if self.policy_info:
|
||
|
excusedata['policy_info'] = self.policy_info
|
||
9 years ago
|
if self.missing_builds or self.missing_builds_ood_arch:
|
||
|
excusedata['missing-builds'] = {
|
||
|
'on-architectures': sorted(self.missing_builds),
|
||
|
'on-unimportant-architectures': sorted(self.missing_builds_ood_arch),
|
||
|
}
|
||
9 years ago
|
if self.deps or self.invalid_deps or self.break_deps:
|
||
|
excusedata['dependencies'] = dep_data = {}
|
||
|
migrate_after = sorted(x for x in self.deps if x not in self.invalid_deps)
|
||
|
break_deps = [x for x, _ in self.break_deps if x not in self.deps]
|
||
|
|
||
|
if self.invalid_deps:
|
||
|
dep_data['blocked-by'] = sorted(self.invalid_deps)
|
||
|
if migrate_after:
|
||
|
dep_data['migrate-after'] = migrate_after
|
||
|
if break_deps:
|
||
|
dep_data['unimportant-dependencies'] = sorted(break_deps)
|
||
9 years ago
|
if self.needs_approval:
|
||
|
status = 'not-approved'
|
||
|
for h in self.hints:
|
||
|
if h.type == 'unblock':
|
||
|
status = 'approved'
|
||
|
break
|
||
|
excusedata['manual-approval-status'] = status
|
||
|
if self.hints:
|
||
|
hint_info = [{
|
||
|
'hint-type': h.type,
|
||
|
'hint-from': h.user,
|
||
|
} for h in self.hints]
|
||
|
|
||
|
excusedata['hints'] = hint_info
|
||
9 years ago
|
if self.old_binaries:
|
||
|
excusedata['old-binaries'] = {x: sorted(self.old_binaries[x]) for x in self.old_binaries}
|
||
11 years ago
|
if self.forced:
|
||
9 years ago
|
excusedata["forced-reason"] = sorted(list(self.reason.keys()))
|
||
11 years ago
|
excusedata["reason"] = []
|
||
|
else:
|
||
9 years ago
|
excusedata["reason"] = sorted(list(self.reason.keys()))
|
||
11 years ago
|
excusedata["is-candidate"] = self.is_valid
|
||
11 years ago
|
return excusedata
|
||
|
|