extras-repoclosure PackageOwners.py, NONE, 1.1 PackageOwnersTests.py, NONE, 1.1 rc-report.py, 1.8, 1.9

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Sat Jul 15 23:30:31 UTC 2006


Author: mschwendt

Update of /cvs/fedora/extras-repoclosure
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv1984

Modified Files:
	rc-report.py 
Added Files:
	PackageOwners.py PackageOwnersTests.py 
Log Message:
move OwnersList class into separate module and enhance it a tiny bit for reusability


--- NEW FILE PackageOwners.py ---
#!/usr/bin/python
# -*- 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 Library 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 commands
import errno
import os, sys, time
import shutil
import tempfile

class PackageOwners:
    """interface to Fedora Extras CVS owners/owners.list file"""
    
    def __init__(self, retries=3, retrysecs=300, workdir=''):
        self.retries = retries
        self.retrysecs = retrysecs
        self.workdir = workdir
        self.ownersfile = os.path.join('owners', 'owners.list')
        self._refresh()

    def GetOwner(self,rpmname):
        """return e-mail address from initialowner field"""
        try:
            r = self.dict[rpmname]['mailto']
        except KeyError:
            r = ''
        return r

    def GetCoOwnerList(self,rpmname):
        """return list of e-mail addresses from initialcclist field"""
        try:
            r = self.dict[rpmname]['cc']
        except KeyError:
            r = []
        return r

    def _enterworkdir(self):
        self.cwd = os.getcwd()
        if self.workdir != '':
            os.chdir(self.workdir)

    def _leaveworkdir(self):
        os.chdir(self.cwd)
        
    def _refresh(self):
        self.dict = {}  # map package name to email address, dict[name]
        self._enterworkdir()
        # Dumb caching. Check that file exists and is "quite recent".
        try:
            fstats = os.stat(self.ownersfile)
            if ( not fstats.st_size or
                 ((time.time() - fstats.st_ctime) > 3600*2) ):
                raise Exception
        except:
            self._download()
        try:
            f = file( self.ownersfile )
        except IOError, (err, strerr):
            print 'ERROR: %s' % strerr
            # TODO: customise behaviour on error conditions
            sys.exit(err)
        for line in f:
            if line.startswith('#') or line.isspace():
                continue
            try:
                (repo,pkgname,summary,email,qacontact,cc) = line.rstrip().split('|')
                (ccowners) = cc.split(',')
                if email.find('@') < 0:  # owners.list is broken
                    raise Exception
                self.dict[pkgname] = {
                    'mailto' : email,
                    'cc' : ccowners
                    }
                #print '%s -> %s' % (pkgname, self.dict[pkgname]['mailto'])
            except:
                print 'ERROR: owners.list is broken'
                print line
        f.close()
        self._leaveworkdir()

    def _download(self):
        self._enterworkdir()
        # Remove 'owners' directory contents, if it exists.
        for root, dirs, files in os.walk( 'owners', topdown=False ):
            for fname in files:
                os.remove(os.path.join( root, fname ))
            for dname in dirs:
                os.rmdir(os.path.join( root, dname ))
        # Retry CVS checkout a few times.
        for count in range(self.retries):
            (rc, rv) = commands.getstatusoutput('LC_ALL=C CVS_RSH=ssh cvs -f -d :pserver:anonymous at cvs.fedora.redhat.com:/cvs/extras co owners')
            if not rc:
                break
            print rv
            time.sleep(self.retrysecs)
        if rc:
            # TODO: customise behaviour on error conditions
            sys.exit(1)
        self._leaveworkdir()



--- NEW FILE PackageOwnersTests.py ---
#!/usr/bin/python
# -*- mode: Python; indent-tabs-mode: nil; -*-

import os
import unittest

import sys
sys.path.append('.')
from PackageOwners import PackageOwners

class TestSequenceFunctions(unittest.TestCase):

    o = PackageOwners(retries=1,retrysecs=1,workdir='.')

    def setUp(self):
        pass
    
    def testowner(self):
        self.assertEqual( self.o.GetOwner('sylpheed'),
                          'bugs.michael at gmx.net' )
    
    def testwrongpackage(self):
        self.assertEqual( self.o.GetOwner('thisPkgDoesNotExist'), '' )
    
    def testcc(self):
        self.assertEqual( self.o.GetCoOwnerList('perl-MIME-tools'),
                          ['fedora-perl-devel-list at redhat.com'] )

if __name__ == '__main__':
    unittest.main()


Index: rc-report.py
===================================================================
RCS file: /cvs/fedora/extras-repoclosure/rc-report.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- rc-report.py	14 Jun 2006 14:09:46 -0000	1.8
+++ rc-report.py	15 Jul 2006 23:30:28 -0000	1.9
@@ -7,6 +7,8 @@
 import re
 import smtplib
 
+from PackageOwners import PackageOwners
+
 domail = 1
 mailsummary = 1
 savehistory = 1
@@ -26,70 +28,6 @@
 waitdelta = datetime.timedelta( days = 14 )
 today = datetime.date.today()
 
-
-# Interface to Fedora Extras CVS owners/owners.list
-class OwnersList:
-    
-    owners = {}  # map package name to email address, owners[name]
-
-    def Download(self):
-        # Remove 'owners' directory.
-        for root, dirs, files in os.walk( 'owners', topdown=False ):
-            for fname in files:
-                os.remove(os.path.join( root, fname ))
-            for dname in dirs:
-                os.rmdir(os.path.join( root, dname ))
-        # Retry CVS checkout a few times.
-        for count in range(3):
-            (rc, rv) = commands.getstatusoutput('LC_ALL=C CVS_RSH=rsh CVSROOT=:pserver:anonymous at cvs.fedora.redhat.com:/cvs/extras cvs co owners')
-            if not rc:
-                break
-            time.sleep(300)
-        if rc:
-            print rv
-            sys.exit(1)
-
-    def Refresh(self):
-        self.ownersfile = 'owners/owners.list'
-        self.owners = {}
-        # Dumb caching. Check that file exists and is "quite recent".
-        try:
-            fstats = os.stat(self.ownersfile)
-            if ( not fstats.st_size or ((time.time() - fstats.st_ctime) > 3600*2) ):
-                raise Exception
-        except:
-            self.Download()
-        try:
-            f = file( self.ownersfile )
-        except:
-            print 'ERROR: could not open %s' % self.ownersfile
-            sys.exit(5)
-        for line in f:
-            if line.startswith('#') or line.isspace():
-                continue
-            try:
-                (repo,pkgname,summary,email,qacontact,cc) = line.split('|')
-                if email.find('@') < 0:  # owners.list is broken
-                    raise Exception
-                self.owners[pkgname] = email
-                #print '%s -> %s' % (pkgname, self.owners[pkgname])
-            except:
-                print 'ERROR: owners.list is broken'
-                print line
-        f.close()
-
-    def GetOwner(self,name):
-        try:
-            r = self.owners[name]
-        except KeyError:
-            r = ''
-        return r
-        
-    def __init__(self):
-        self.Refresh()
-
-
-
 # We identify broken packages based on their src.rpm name and don't report
 # them more than once until expiration.
 class History:
@@ -222,7 +160,7 @@
 subject += (' %s - %s' % (release,datestring))
 summail = ''
 
-owners = OwnersList()
+owners = PackageOwners()
 history = History()
 report = {}  # map, report[email], mail message body to be sent to somebody
 pkgbyowner = {}  # map, pkgbyowner[email], list of pkgids for all owner's broken packages




More information about the scm-commits mailing list