excuse.py

00001 # -*- coding: utf-8 -*-
00002 
00003 # Copyright (C) 2001-2004 Anthony Towns <ajt@debian.org>
00004 #                         Andreas Barth <aba@debian.org>
00005 #                         Fabio Tranchitella <kobold@debian.org>
00006 
00007 # This program is free software; you can redistribute it and/or modify
00008 # it under the terms of the GNU General Public License as published by
00009 # the Free Software Foundation; either version 2 of the License, or
00010 # (at your option) any later version.
00011 
00012 # This program is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 # GNU General Public License for more details.
00016 
00017 import re
00018 import string
00019 
00020 
00021 class Excuse:
00022     """Excuse class
00023     
00024     This class represents an update excuse, which is a detailed explanation
00025     of why a package can or cannot be updated in the testing distribution from
00026     a newer package in another distribution (like for example unstable).
00027 
00028     The main purpose of the excuses is to be written in an HTML file which
00029     will be published over HTTP. The maintainers will be able to parse it
00030     manually or automatically to find the explanation of why their packages
00031     have been updated or not.
00032     """
00033 
00034     ## @var reemail
00035     # Regular expression for removing the email address
00036     reemail = re.compile(r"<.*?>")
00037 
00038     def __init__(self, name):
00039         """Class constructor
00040         
00041         This method initializes the excuse with the specified name and
00042         the default values.
00043         """
00044         self.name = name
00045         self.ver = ("-", "-")
00046         self.maint = None
00047         self.pri = None
00048         self.date = None
00049         self.urgency = None
00050         self.daysold = None
00051         self.mindays = None
00052         self.section = None
00053         self.dontinvalidate = 0
00054 
00055         self.invalid_deps = []
00056         self.deps = []
00057         self.sane_deps = []
00058         self.break_deps = []
00059         self.unsat_deps = {}
00060         self.bugs = []
00061         self.htmlline = []
00062 
00063     def set_vers(self, tver, uver):
00064         """Set the testing and unstable versions"""
00065         if tver: self.ver = (tver, self.ver[1])
00066         if uver: self.ver = (self.ver[0], uver)
00067 
00068     def set_maint(self, maint):
00069         """Set the package maintainer's name"""
00070         self.maint = self.reemail.sub("", maint)
00071 
00072     def set_section(self, section):
00073         """Set the section of the package"""
00074         self.section = section
00075 
00076     def set_priority(self, pri):
00077         """Set the priority of the package"""
00078         self.pri = pri
00079 
00080     def set_date(self, date):
00081         """Set the date of upload of the package"""
00082         self.date = date
00083 
00084     def set_urgency(self, date):
00085         """Set the urgency of upload of the package"""
00086         self.urgency = date
00087 
00088     def add_dep(self, name):
00089         """Add a dependency"""
00090         if name not in self.deps: self.deps.append(name)
00091 
00092     def add_sane_dep(self, name):
00093         """Add a sane dependency"""
00094         if name not in self.sane_deps: self.sane_deps.append(name)
00095 
00096     def add_break_dep(self, name, arch):
00097         """Add a break dependency"""
00098         if (name, arch) not in self.break_deps:
00099             self.break_deps.append( (name, arch) )
00100 
00101     def add_unsat_dep(self, arch):
00102         """Add a flag for unsatisfied dependencies"""
00103         self.unsat_deps[arch] = True
00104 
00105     def invalidate_dep(self, name):
00106         """Invalidate dependency"""
00107         if name not in self.invalid_deps: self.invalid_deps.append(name)
00108 
00109     def setdaysold(self, daysold, mindays):
00110         """Set the number of days from the upload and the minimum number of days for the update"""
00111         self.daysold = daysold
00112         self.mindays = mindays
00113 
00114     def addhtml(self, note):
00115         """Add a note in HTML"""
00116         self.htmlline.append(note)
00117 
00118     def html(self):
00119         """Render the excuse in HTML"""
00120         res = "<a id=\"%s\" name=\"%s\">%s</a> (%s to %s)\n<ul>\n" % \
00121             (self.name, self.name, self.name, self.ver[0], self.ver[1])
00122         if self.maint:
00123             res = res + "<li>Maintainer: %s\n" % (self.maint)
00124         if self.section and string.find(self.section, "/") > -1:
00125             res = res + "<li>Section: %s\n" % (self.section)
00126         if self.daysold != None:
00127             if self.daysold < self.mindays:
00128                 res = res + ("<li>Too young, only %d of %d days old\n" %
00129                 (self.daysold, self.mindays))
00130             else:
00131                 res = res + ("<li>%d days old (needed %d days)\n" %
00132                 (self.daysold, self.mindays))
00133         for x in self.htmlline:
00134             res = res + "<li>" + x + "\n"
00135         for x in self.deps:
00136             if x in self.invalid_deps:
00137                 res = res + "<li>Depends: %s <a href=\"#%s\">%s</a> (not considered)\n" % (self.name, x, x)
00138             else:
00139                 res = res + "<li>Depends: %s <a href=\"#%s\">%s</a>\n" % (self.name, x, x)
00140         for (n,a) in self.break_deps:
00141             if n not in self.deps:
00142                 res += "<li>Ignoring %s depends: <a href=\"#%s\">%s</a>\n" % (a, n, n)
00143         res = res + "</ul>\n"
00144         return res

Generated on Fri Aug 18 23:23:25 2006 for briteny by  doxygen 1.4.7