extras-buildsys/utils extras-push-new,1.10,1.11

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Fri May 19 00:18:46 UTC 2006


Author: mschwendt

Update of /cvs/fedora/extras-buildsys/utils
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv27960

Modified Files:
	extras-push-new 
Log Message:
- Add code which prunes old unwanted builds from the needsign queue
  prior to pushing.
- Turn DEBUG on again, although I'm confident this works.



Index: extras-push-new
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/extras-push-new,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- extras-push-new	17 May 2006 09:58:53 -0000	1.10
+++ extras-push-new	19 May 2006 00:18:43 -0000	1.11
@@ -15,13 +15,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-import fcntl
+import fcntl, fnmatch
 import os, sys
 import rpmUtils
 import shutil
 import string
 
-DEBUG = False
+DEBUG = True
 
 signersgid = 100581  # extras_signers group
 
@@ -47,15 +47,15 @@
 """
 smtp_server = ''
 
-config = { 'repoview' : True,
-           'repoclosure' : False,
-           'gidcheck' : True,
-           'setumask' : True,
-           'signkeycheck' : True,
-           'mail' : True,
-           'doublesync' : False,
-           'force' : False
-           }
+class opts:
+    repoview = True
+    repoclosure = False
+    gidcheck = True
+    setumask = True
+    signkeycheck = True
+    mail = True
+    doublesync = False
+    force = False
 
 alldists = [ 'development', '5', '4', '3' ]
 
@@ -158,6 +158,69 @@
 
 
 # ====================================================================
+
+def find_srcrpms(rootpath):
+    """returns a list of source rpm path names in given tree"""
+    srcrpms = []
+    if not os.path.isdir(rootpath):
+        return srcrpms
+    for root, dirs, files in os.walk(rootpath):
+        for f in fnmatch.filter(files,'*.src.rpm'):
+            srcrpms.append(os.path.join(root,f))
+    return srcrpms
+
+
+def prune_needsign_tree(repodir):
+    # The root dir contains a directory for every pushed package "name".
+    pkgnames = os.listdir(repodir)
+    try:
+        pkgnames.remove('repodata')
+    except:
+        pass
+
+    for name in pkgnames:
+        pkgroot = os.path.join(repodir,name)
+        if not os.path.isdir(pkgroot):
+            continue
+        # Every version-release is stored in an own sub-dir.
+        pkgreldirs = os.listdir(pkgroot)
+        debugprint( '%s releases for %s: %s' % (len(pkgreldirs),name,' '.join(pkgreldirs)) )
+        if len(pkgreldirs) < 2: # only one release
+            continue
+        # We assume this release to be the newest.
+        relroot = os.path.join(pkgroot,pkgreldirs[0])
+        # There can be only one src.rpm in this dir, since relroot
+        # and src.rpm filename are unique (due to NVR).
+        srcrpms = find_srcrpms(relroot)
+        # Currently, directories can be empty though, unless we clean up
+        # the repodir regularly.
+        if not len(srcrpms):
+            continue
+        srcrpm = srcrpms[0]
+        (n,a,e,v,r) = naevr(srcrpm)
+        # Now compare with the other releases.
+        for vr in pkgreldirs[1:]:
+            nextrelroot = os.path.join(pkgroot,vr)
+            nextsrcrpms = find_srcrpms(nextrelroot)
+            if not len(nextsrcrpms):
+                continue
+            nextsrcrpm = nextsrcrpms[0]
+            (nextn,nexta,nexte,nextv,nextr) = naevr(nextsrcrpm)
+            # 1 means: e,v,r is higher than nexte,nextv,nextr
+            if rpmUtils.miscutils.compareEVR((e,v,r),(nexte,nextv,nextr)) == 1:
+                debugprint('Removing: %s' % nextrelroot)
+                if not DEBUG:
+                    shutil.rmtree(nextrelroot)
+            else:
+                debugprint('Removing: %s' % relroot)
+                if not DEBUG:
+                    shutil.rmtree(relroot)
+                # Make this the next newest package for ongoing comparison.
+                relroot = nextrelroot
+                (n,a,e,v,r) = (nextn,nexta,nexte,nextv,nextr)
+
+
+# ====================================================================
 # (previously in extras-sign-move.py)
 
 # get the path to where to look for the packages to be signed
@@ -251,6 +314,7 @@
 
     distdir = '%s-%s-%s' % (distro, dist, project)
     needsign = os.path.join(stagesdir, distdir)
+    #prune_needsign_tree(needsign)
     files = find_files(needsign)
     rpms = files['rpm'] + files['srpm'] + files['debuginfo']    
     rpms.sort()
@@ -417,22 +481,22 @@
 # ====================================================================
 
 if __name__ == '__main__':
-    if config['gidcheck']:
+    if opts.gidcheck:
         if os.getgid() != signersgid:
             print 'ERROR: Change into extras_signers group before running this!  Use "newgrp extras_signers".'
             sys.exit(13)
 
-    if config['signkeycheck']:
+    if opts.signkeycheck:
         if 'extras at fedoraproject.org' != os.popen('rpm --eval %_gpg_name','r').read().rstrip():
             print 'ERROR: Configure ~/.rpmmacros for proper GPG signing before running this!'
             sys.exit(13)
 
-    if config['setumask']:
+    if opts.setumask:
         os.umask(0002)
 
     if '-f' in sys.argv[1:]:
         sys.argv.remove('-f')
-        config['force'] = True
+        opts.force = True
     
     if len(sys.argv) < 2:
         print 'SYNTAX: %s <dist|all> [dist]...' % sys.argv[0]
@@ -453,7 +517,7 @@
     # If we are called as 'extras-sign-move.py' we simulate old
     # behaviour and only do: sign, move, repobuild, sync
     if sys.argv[0].endswith('extras-sign-move.py'):
-        config['repoview'] = False
+        opts.repoview = False
 
     if not os.path.exists(rundir):
         os.makedirs(rundir)
@@ -470,27 +534,27 @@
     # Option -f re-runs repobuild/repoview for all dists, even if
     # no new packages have been pushed for a dist.
     changed = dists
-    if config['force']:
+    if opts.force:
         changed = alldists
 
     # len(getlinesfromrunfile(dist)) is the number of packages
     # per dist which have been pushed.
 
     for dist in changed:
-        if config['force'] or len( getlinesfromrunfile(dist) ):
+        if opts.force or len( getlinesfromrunfile(dist) ):
             run_and_check('extras-repobuild.py %s' % dist)
 
-    if config['doublesync']:
+    if opts.doublesync:
         run_and_check('extras-sync')
 
     for dist in changed:
-        if config['force'] or len( getlinesfromrunfile(dist) ):
-            if config['repoview']:
+        if opts.force or len( getlinesfromrunfile(dist) ):
+            if opts.repoview:
                 run_and_check('extras-repoview.py %s' % dist)
 
     run_and_check('extras-sync')
 
-    if config['mail']:
+    if opts.mail:
         for dist in dists:
             email_list( getlinesfromrunfile(dist), dist )
             emptyrunfile(dist)




More information about the fedora-extras-commits mailing list