#!/usr/bin/python -t # -*- mode: Python; indent-tabs-mode: nil; -*- # # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import errno, os, sys import pickle class BuildInfo: def __init__(self,pkgid=None,summary=None,new=False,invalid=False): self.pkgid = pkgid self.summary = summary self.new = new self.invalid = invalid class BuildReportManager: def __init__(self,workdir,id): self.fname = os.path.join(workdir,'%s.buildreport.pickle'%id.replace('/','_')) self.builds = [] self._load(self.fname) def Add(self,buildinfo): if not buildinfo: return self.builds.append(buildinfo) self._save(self.fname) def Clear(self): self.builds = [] self._save(self.fname) def GetCount(self): return len(self.builds) def GetReport(self): def cmplc(a,b): # case-insensitive cmp for Python < 2.4 sort() return cmp(a.lower(),b.lower()) def cmpbuilds(a,b): return cmplc(a.pkgid,b.pkgid) builds = self.builds builds.sort(cmpbuilds) report = [] for b in builds: if b.new: s = 'NEW ' elif b.invalid: s = '(!) ' else: s = ' ' s += b.pkgid if b.summary: s += ' : ' + b.summary report.append(s) return '\n'.join(report) def _load(self,fname): try: f = file(fname,'r') self.builds = pickle.load(f) f.close() except IOError, (err, strerr): if err != 2: # everything but file_not_found is unexpected print 'ERROR: %s: %s' % (strerr,self.fname) raise IOError, (err, strerr) def _save(self,fname): f = file(fname,'w') pickle.dump(self.builds,f) f.close() class NoBuildReportManager(BuildReportManager): def __init__(self,workdir=None,id=None): self.builds = [] def Add(self,buildinfo): pass