extras-buildsys/utils/pushscript extras-repoprune, NONE, 1.1 RepoPrune.py, NONE, 1.1 README, 1.4, 1.5 Push.py, 1.5, 1.6 extras-repomanage, 1.1, NONE RepoManage.py, 1.1, NONE

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Mon Oct 23 11:24:38 UTC 2006


Author: mschwendt

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

Modified Files:
	README Push.py 
Added Files:
	extras-repoprune RepoPrune.py 
Removed Files:
	extras-repomanage RepoManage.py 
Log Message:
Replace "repomanage" usage with repoprune. It not just gets rid
of obsolete and forgotten sub-packages, but is also 4x faster. 



--- NEW FILE extras-repoprune ---
#!/usr/bin/python -t
# 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

cfg = 'Extras'

if __name__ == '__main__':
    import os, sys, errno
    if len(sys.argv) < 2:
        print 'Usage: %s <release>\n' % os.path.basename(sys.argv[0])
        sys.exit(errno.EINVAL)
    cmd = os.path.join(sys.path[0],'RepoPrune.py')
    args = [cmd]+[cfg]+sys.argv[1:]
    os.execvp(cmd,args)


--- NEW FILE RepoPrune.py ---
#!/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 fnmatch, re
import rpmUtils.transaction, rpmUtils.miscutils

import Utils

DEBUG = False
Utils.setdebug(DEBUG)

def pruneRepo(keep,whitelist,srcdir,bindirlist):
    ts = rpmUtils.transaction.initReadOnlyTransaction()
    changed = False
    
    # Create list of src.rpm files.
    # We don't use "glob", so sub-directories are supported.
    print 'Expiring (keep=%d):' % keep, srcdir
    srcfiles = []
    for root, dirs, files in os.walk(srcdir):
            for f in fnmatch.filter(files,'*.src.rpm'):
                srcfiles.append(os.path.join(root,f))
    if not len(srcfiles):
        print '  Nothing found.'
        return changed
    assert srcfiles[0].startswith(srcdir)

    # Create map: rpm %name -> list of tuples (filename,name,e,v,r)
    newestsrcrpms = {}
    for f in srcfiles:
        hdr = rpmUtils.miscutils.hdrFromPackage(ts,f)
        n = hdr['name']
        v = hdr['version']
        r = hdr['release']
        e = hdr['epoch']
        if e is None:
            e = 0
        newestsrcrpms.setdefault(n,[])
        newestsrcrpms[n].append((f,n,e,v,r))

    # Now purge old src.rpm unless their %name matches a white-list pattern.
    for l in newestsrcrpms.values():
        x = len(l)

        if x > 1:
            # White-listing.
            (f,n,e,v,r) = l[0]
            keepthis = False
            for r in whitelist:
                if re.compile(r).search(n):
                    keepthis = True
                    break
            if keepthis:
                print '  Skipping',n
                continue

            def sortByEVR(fnevr1, fnevr2):
                (f1,n1,e1,v1,r1) = fnevr1
                (f2,n2,e2,v2,r2) = fnevr2
                rc = rpmUtils.miscutils.compareEVR((e1,v1,r1),(e2,v2,r2))
                if rc == 0:
                    return 0
                if rc > 0:
                    return -1
                if rc < 0:
                    return 1
            
            l.sort(sortByEVR)  # highest first in list
        
        oldies = []
        if len(l) > abs(keep):
            oldies = l[keep:]
        for (f,n,e,v,r) in oldies:
            print '  Removing', os.path.basename(f)
            srcfiles.remove(f)
            if not DEBUG:
                os.remove(f)
            changed = True

    if not len(srcfiles):
        print 'WARNING: No src.rpms left. Stopping here.'
        return changed

    # Examine binary repository directories and remove everything which
    # is missing its corresponding src.rpm.
    for bindir in bindirlist:
        print 'Pruning:', bindir
        for root, dirs, files in os.walk(bindir):
            for f in fnmatch.filter(files,'*.rpm'):
                fullname = os.path.join(root,f)
                hdr = rpmUtils.miscutils.hdrFromPackage(ts,fullname)
                sourcerpm = hdr['sourcerpm']
                if not sourcerpm.endswith('.rpm'):
                    continue
                if not os.path.join(srcdir,sourcerpm) in srcfiles:
                    print '  Removing', f
                    if not DEBUG:
                        os.remove(fullname)
                    changed = True
    return changed


def main(cfg,dist):
    assert rpmUtils.miscutils.compareEVR((1,2,3),(1,2,0)) > 0
    assert rpmUtils.miscutils.compareEVR((0,1,2),(0,1,2)) == 0
    assert rpmUtils.miscutils.compareEVR((1,2,3),(4,0,99)) < 0

    keep = (dist == 'development') and 1 or 2
    whitelist = cfg.repoprune_keepdict[dist]

    srcdir = os.path.join(cfg.treedir,dist,'SRPMS')
    bindirs = []
    for arch in cfg.archdict[dist]:  # list of repo archs
        bindirs.append(os.path.join(cfg.treedir,dist,arch))
        
    return pruneRepo(keep,whitelist,srcdir,bindirs)


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print 'Usage: %s <project> <release> [release]...\n' % os.path.basename(sys.argv[0])
        sys.exit(errno.EINVAL)

    cfg = Utils.load_config_module(sys.argv[1])

    Utils.signer_gid_check(cfg.signersgid)
    os.umask(cfg.signersumask)
    
    for dist in sys.argv[2:]:
        if not cfg.archdict.has_key(dist):
            print "No distribution release named '%s' found" % dist
            sys.exit(errno.EINVAL)
        main(cfg,dist)
    sys.exit(0)


Index: README
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/pushscript/README,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- README	15 Oct 2006 12:30:38 -0000	1.4
+++ README	23 Oct 2006 11:24:35 -0000	1.5
@@ -14,16 +14,19 @@
 
 Scripts we need in $PATH:
 
-extras-push          -> pushscript/extras-push
-extras-repobuild     -> pushscript/extras-repobuild
-extras-repomanage    -> pushscript/extras-repomanage
-extras-repoview      -> pushscript/extras-repoview
-extras-sync          -> pushscript/extras-sync
+  extras-push          -> pushscript/extras-push
+  extras-sync          -> pushscript/extras-sync
 
-rc-modified          -> extras-repoclosure/rc-modified
-rc-report.py         -> extras-repoclosure
-rc-run.py            -> extras-buildsys/utils/rc-run.py
-rc-run-all.py        -> rc-run.py
+  rc-modified          -> extras-repoclosure/rc-modified
+  rc-report.py         -> extras-repoclosure/rc-report.py
+  rc-run.py            -> extras-buildsys/utils/rc-run.py
+  rc-run-all.py        -> rc-run.py
 
-upgradecheck.py
+  upgradecheck.py
+
+Optional:
+
+  extras-repobuild     -> pushscript/extras-repobuild
+  extras-repoview      -> pushscript/extras-repoview
+  extras-repoprune     -> pushscript/extras-repoprune
 


Index: Push.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/pushscript/Push.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Push.py	15 Oct 2006 12:37:20 -0000	1.5
+++ Push.py	23 Oct 2006 11:24:35 -0000	1.6
@@ -25,7 +25,7 @@
 import time
 
 import Utils, MultiLib
-import RepoBuild, RepoManage, RepoView
+import RepoBuild, RepoPrune, RepoView
 
 DEBUG = False
 Utils.setdebug(DEBUG)
@@ -616,8 +616,8 @@
         changed = diststopush
 
     for dist in changed:
-        if cfg.opts.repomanage:
-            RepoManage.main(cfg,dist)
+        if cfg.opts.repoprune:
+            RepoPrune.main(cfg,dist)
         RepoBuild.main(cfg,dist)
 
     # TODO: multilib resolver hook


--- extras-repomanage DELETED ---


--- RepoManage.py DELETED ---




More information about the scm-commits mailing list