extras-repoclosure PackageOwnersTests.py, 1.6, 1.7 PackageOwners.py, 1.11, 1.12

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Tue Aug 21 00:21:49 UTC 2007


Author: mschwendt

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

Modified Files:
	PackageOwnersTests.py PackageOwners.py 
Log Message:
use FAS for username->email mapping / still keep the old code, too


Index: PackageOwnersTests.py
===================================================================
RCS file: /cvs/fedora/extras-repoclosure/PackageOwnersTests.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PackageOwnersTests.py	17 Aug 2007 10:45:56 -0000	1.6
+++ PackageOwnersTests.py	21 Aug 2007 00:21:47 -0000	1.7
@@ -11,12 +11,12 @@
 
 class TestDownloadFromURL(unittest.TestCase):
     def testFromURL(self):
-        po.FromURL(retries=1,retrysecs=1,url='https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain',domain='localhost.localdomain')
+        po.FromURL(retries=1,retrysecs=1,url='https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain')
 
 
 class TestDownloadFromOldURL(unittest.TestCase):
     def testFromURL(self):
-        po.FromURL(retries=1,retrysecs=1,url='http://cvs.fedora.redhat.com/viewcvs/*checkout*/owners/owners.list?root=extras',domain='')
+        po.FromURL(retries=1,retrysecs=1,url='http://cvs.fedora.redhat.com/viewcvs/*checkout*/owners/owners.list?root=extras',pkgdb=False)
 
 
 class TestDownloadFromCVS(unittest.TestCase):
@@ -24,7 +24,7 @@
         po.FromCVS(retries=1,retrysecs=1,workdir=os.getcwd())
 
 
-class TestSequenceFunctionsOld(unittest.TestCase):
+class TestSequenceFunctions(unittest.TestCase):
 
     def testowner(self):
         self.assertEqual( po.GetOwner('sylpheed'),
@@ -56,43 +56,11 @@
                           ['fedora-perl-devel-list at redhat.com'] )
 
 
-class TestSequenceFunctions(unittest.TestCase):
-
-    def testowner(self):
-        self.assertEqual( po.GetOwner('sylpheed'),
-                          'mschwendt at localhost.localdomain' )
-
-    def testowners(self):
-        a = po.GetOwners('perl-MailTools')
-        a.sort()
-        b = ['pghmcfc at localhost.localdomain','perl-sig at localhost.localdomain']
-        b.sort()
-        self.assertEqual(a,b)
-    
-    def testownersmultiple(self):
-        po._parse(['Test|testpkg|test desc|owner,co-owner|qa|observer,upstream'])
-        self.assertEqual( po.GetOwner('testpkg'), 'owner at localhost.localdomain')
-
-    def testownersmultiple2(self):
-        a = po.GetOwners('testpkg')
-        a.sort()
-        b = ['owner at localhost.localdomain','co-owner at localhost.localdomain','observer at localhost.localdomain','upstream at localhost.localdomain']
-        b.sort()
-        self.assertEqual(a,b)
-
-    def testwrongpackage(self):
-        self.assertEqual( po.GetOwner('thisPkgDoesNotExist'), '' )
-    
-    def testcc(self):
-        self.assertEqual( po.GetCoOwnerList('perl-MIME-tools'),
-                          ['perl-sig at localhost.localdomain'] )
-
-
 if __name__ == '__main__':
     suite1 = unittest.makeSuite(TestDownloadFromCVS)
     suite2 = unittest.makeSuite(TestDownloadFromOldURL)
     suite3 = unittest.makeSuite(TestDownloadFromURL)
-    suitemain1 = unittest.makeSuite(TestSequenceFunctionsOld)
+    suitemain1 = unittest.makeSuite(TestSequenceFunctions)
     suitemain2 = unittest.makeSuite(TestSequenceFunctions)
 
     alltests = unittest.TestSuite((suite1,suitemain1,


Index: PackageOwners.py
===================================================================
RCS file: /cvs/fedora/extras-repoclosure/PackageOwners.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- PackageOwners.py	17 Aug 2007 10:45:56 -0000	1.11
+++ PackageOwners.py	21 Aug 2007 00:21:47 -0000	1.12
@@ -30,13 +30,15 @@
         self.how = 'unknown'
 
 
-    def FromURL(self, retries=3, retrysecs=300, url='https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain',domain='fedoraproject.org'):
+    def FromURL(self, retries=3, retrysecs=300, url='https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain',pkgdb=True):
         # old url='http://cvs.fedora.redhat.com/viewcvs/*checkout*/owners/owners.list?root=extras'
-        self.how = 'url'
+        if pkgdb:
+            self.how = 'pkgdb'
+        else:
+            self.how = 'url'
         self.url = url
         self.retries = retries
         self.retrysecs = retrysecs
-        self.domain = domain
         return self._refresh()
     
     
@@ -45,7 +47,6 @@
         self.command = command
         self.retries = retries
         self.retrysecs = retrysecs
-        self.domain = ''
         self.workdir = workdir
         self.ownersfile = os.path.join('owners', 'owners.list')
         self.cwdstack = []
@@ -109,13 +110,11 @@
                 def fixaddr(a):
                     # Old Fedora CVS owners.list contains e-mail addresses.
                     # PkgDb plain output contains usernames only.
-                    if not len(self.domain):
-                        if (a.find('@') < 0):  # unexpected, no addr
-                            raise Exception
+                    if not self.how == 'pkgdb':
+                        return a
+                    if not self.usermap.has_key(a):
                         return a
-                    if a.find('@') >= 0:  # unexpected, no username
-                        raise Exception
-                    return a+'@'+self.domain
+                    return self.usermap[a]
                 
                 addrs = []
                 mailto = '' # primary pkg owner
@@ -188,30 +187,55 @@
         return True
 
 
-    def _downloadfromurl(self):
+    def _getlinesfromurl(self,url):
+        err = 0
+        strerr = ''
         # Retry URL download a few times.
         for count in range(self.retries):
+            if count != 0:
+                time.sleep(self.retrysecs)
             try:
-                f = urllib.urlopen(self.url)
+                f = urllib.urlopen(url)
                 rc = 0
                 break
-            except IOError, (err, strerr):
+            except IOError, (_err, _strerr):
                 rc = 1
-                time.sleep(self.retrysecs)
+                print url
+                print _strerr
+                (err,strerr) = (_err,_strerr)
         if rc:
-            # TODO: customise behaviour on error conditions
-            print 'ERROR: Could not download owners.list from %s' % self.url
-            return False
+            raise IOError, (err, strerr)
         else:
-            ownerslist = f.readlines()
+            l = f.readlines()
             f.close()
-            self._parse(ownerslist)
-            return True
+            return l
+
+    
+    def _downloadfromurl(self):
+        self._parse(self._getlinesfromurl(self.url))
+        return True
+
+
+    def _downloadfrompkgdb(self):
+        fasdump = self._getlinesfromurl('https://admin.fedoraproject.org/accounts/dump-group.cgi')
+        self.usermap = {}
+        for line in fasdump:
+            fields = line.split(',')
+            user = fields[0]
+            addr = fields[1]
+            if (addr.find('@') < 0):  # unexpected, no addr
+                print 'No email in:', line
+                raise Exception
+            self.usermap[user] = addr
+        self._parse(self._getlinesfromurl(self.url))
+        return True
 
 
     def _download(self):
         if self.how == 'url':
             return self._downloadfromurl()
+        elif self.how == 'pkgdb':
+            return self._downloadfrompkgdb()
         elif self.how == 'cvs':
             return self._downloadfromcvs()
         else:




More information about the fedora-extras-commits mailing list