#!/usr/bin/env python # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import getopt import sys, os sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') from common import checkdir from config import ftp_dir,all_ftp_archs import config import ftpio try: opts, args = getopt.getopt(sys.argv[1:], None, ["nopoldek", "noyum", "norpmrepo", "poldek", "yum", "rpmrepo"]) except getopt.GetoptError: print >>sys.stderr, "ERR: not enough parameters given" print >>sys.stderr, "gen-indexes.py [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]" sys.exit(1) do_poldek = True do_yum = True do_rpmrepo = False for o, a in opts: if o == "--nopoldek": do_poldek = False if o == "--noyum": do_yum = False if o == "--norpmrepo": do_rpmrepo = False if o == "--poldek": do_poldek = True if o == "--yum": do_yum = True if o == "--rpmrepo": do_rpmrepo = True if not do_poldek and not do_yum and not do_rpmrepo: print >>sys.stderr, "ERR: speciy at least one action" sys.exit(1) trees = args for tree in trees: checkdir(tree) ftpio.connect('gen-indexes') locked = [] for tree in trees: if ftpio.lock(tree, True): locked.append(tree) else: print >>sys.stderr, "ERR: %s tree already locked" % tree for i in locked: ftpio.unlock(i) sys.exit(1) home = os.environ['HOME'] os.umask(022) os.nice(19) if do_poldek: poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir) for tree in trees: print '-------------------------- %s --------------------------' % tree for arch in all_ftp_archs: print 'generate poldek index for %s' % arch if config.poldek_indexes != "old": os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) if config.poldek_indexes != "new": os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pdir' % (poldek, ftp_dir, tree, arch)) if do_yum: os.system('set -x; cd %s.stat/repodata && cvs up comps.xml' % ftp_dir) yum = '%s.stat/bin/createrepo -d -g %s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir) for tree in trees: print '-------------------------- %s --------------------------' % tree cachedir = '%s/tmp/createrepo/%s' % (home, tree) for arch in all_ftp_archs: print 'generate repodata for %s using createrepo' % arch # Creating indexes for yum and other supporting xml repodata. os.system('time %s --cache %s-%s %s%s/%s/RPMS' % (yum, cachedir, arch, ftp_dir, tree, arch)) if do_rpmrepo: os.system('set -x; cd %s.stat/repodata && cvs up comps.xml' % ftp_dir) for tree in trees: print '-------------------------- %s --------------------------' % tree for arch in all_ftp_archs: dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch) print 'generate repodata for %s using rpmrepo (in %s)' % (arch, dir) os.system('time rpmrepo %s -o %s' % (dir, dir)) print 'copy comps.xml' comps = '%s.stat/repodata/comps.xml' % ftp_dir os.system('set -x; cp -p %s %s/repodata' % (comps, dir)) for tree in trees: ftpio.unlock(tree)