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.break_deps = []
00058         self.bugs = []
00059         self.htmlline = []
00060 
00061     def set_vers(self, tver, uver):
00062         """Set the testing and unstable versions"""
00063         if tver: self.ver = (tver, self.ver[1])
00064         if uver: self.ver = (self.ver[0], uver)
00065 
00066     def set_maint(self, maint):
00067         """Set the package maintainer's name"""
00068         self.maint = self.reemail.sub("", maint)
00069 
00070     def set_section(self, section):
00071         """Set the section of the package"""
00072         self.section = section
00073 
00074     def set_priority(self, pri):
00075         """Set the priority of the package"""
00076         self.pri = pri
00077 
00078     def set_date(self, date):
00079         """Set the date of upload of the package"""
00080         self.date = date
00081 
00082     def set_urgency(self, date):
00083         """Set the urgency of upload of the package"""
00084         self.urgency = date
00085 
00086     def add_dep(self, name):
00087         """Add a dependency"""
00088         if name not in self.deps: self.deps.append(name)
00089 
00090     def add_break_dep(self, name, arch):
00091         """Add a break dependency"""
00092         if (name, arch) not in self.break_deps:
00093             self.break_deps.append( (name, arch) )
00094 
00095     def invalidate_dep(self, name):
00096         """Invalidate dependency"""
00097         if name not in self.invalid_deps: self.invalid_deps.append(name)
00098 
00099     def setdaysold(self, daysold, mindays):
00100         """Set the number of days from the upload and the minimum number of days for the update"""
00101         self.daysold = daysold
00102         self.mindays = mindays
00103 
00104     def addhtml(self, note):
00105         """Add a note in HTML"""
00106         self.htmlline.append(note)
00107 
00108     def html(self):
00109         """Render the excuse in HTML"""
00110         res = "<a id=\"%s\" name=\"%s\">%s</a> (%s to %s)\n<ul>\n" % \
00111             (self.name, self.name, self.name, self.ver[0], self.ver[1])
00112         if self.maint:
00113             res = res + "<li>Maintainer: %s\n" % (self.maint)
00114         if self.section and string.find(self.section, "/") > -1:
00115             res = res + "<li>Section: %s\n" % (self.section)
00116         if self.daysold != None:
00117             if self.daysold < self.mindays:
00118                 res = res + ("<li>Too young, only %d of %d days old\n" %
00119                 (self.daysold, self.mindays))
00120             else:
00121                 res = res + ("<li>%d days old (needed %d days)\n" %
00122                 (self.daysold, self.mindays))
00123         for x in self.htmlline:
00124             res = res + "<li>" + x + "\n"
00125         for x in self.deps:
00126             if x in self.invalid_deps:
00127                 res = res + "<li>Depends: %s <a href=\"#%s\">%s</a> (not considered)\n" % (self.name, x, x)
00128             else:
00129                 res = res + "<li>Depends: %s <a href=\"#%s\">%s</a>\n" % (self.name, x, x)
00130         for (n,a) in self.break_deps:
00131             if n not in self.deps:
00132                 res += "<li>Ignoring %s depends: <a href=\"#%s\">%s</a>\n" % (a, n, n)
00133         res = res + "</ul>\n"
00134         return res

Generated on Sat Jun 24 18:50:20 2006 for briteny by  doxygen 1.4.6