2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
4 from __future__ import print_function
8 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
9 from common import checkdir
10 from config import ftp_dir,all_ftp_archs
15 opts, args = getopt.getopt(sys.argv[1:], 'q',
18 "nopoldek", "noyum", "norpmrepo",
19 "poldek", "yum", "rpmrepo"
22 except getopt.GetoptError:
23 print("ERR: not enough parameters given", file=sys.stderr)
24 print("gen-indexes.py [--quiet] [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]", file=sys.stderr)
31 # update only if changed (applicable to yum)
39 if o == "--norpmrepo":
49 if o == "-q" or o == "--quiet":
53 do_poldek = do_yum = do_rpmrepo = False
54 for v in a.split(','):
63 print("poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo))
65 if not do_poldek and not do_yum and not do_rpmrepo:
66 print("ERR: speciy at least one action", file=sys.stderr)
74 ftpio.connect('gen-indexes')
79 if ftpio.lock(tree, True):
82 print("ERR: %s tree already locked" % tree, file=sys.stderr)
87 home = os.environ['HOME']
93 poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir)
96 print('\n-------------------------- %s --------------------------' % tree)
97 for arch in all_ftp_archs:
98 print('\ngenerate poldek index for %s' % arch)
99 print('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch))
100 os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch))
101 if arch != 'noarch' and config.separate_debuginfo:
102 os.system('%s -s %s%s/%s/debuginfo/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch))
105 os.system('%s cd %s.stat/repodata && git checkout %s HEAD repodata/comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "--quiet"))
106 yum = '%s.stat/bin/createrepo_c --database --update --skip-stat --workers=12 --xz --groupfile=%s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir)
107 comps_file = '%s.stat/repodata/comps.xml' % ftp_dir
109 print('\n-------------------------- %s --------------------------' % tree)
110 cachedir = '%s/tmp/createrepo/%s' % (home, tree)
111 os.makedirs(cachedir, mode=711, exist_ok=True)
112 treedir = "%s%s" % (ftp_dir, tree)
113 for arch in all_ftp_archs:
114 print('\ngenerate repodata for %s using createrepo' % arch)
115 archdir = "%s/%s" % (treedir, arch)
116 poldek_idx = "%s/RPMS/packages.ndir.md" % archdir
117 repodata_idx = "%s/RPMS/repodata/repomd.xml" % archdir
118 if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \
119 and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \
120 and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx):
121 print("repodata indexes already fresh")
123 print('%s %s --cachedir=%s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir))
124 os.system('%s %s --cachedir=%s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir))
125 if arch != 'noarch' and config.separate_debuginfo:
126 os.system('%s %s --cachedir=%s-%s %s/debuginfo' % ("" if quiet else "time", yum, cachedir, arch, archdir))
129 os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q"))
131 print('\n-------------------------- %s --------------------------' % tree)
132 for arch in all_ftp_archs:
133 dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch)
135 print('\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir))
136 os.system('%s rpmrepo %s -o %s' % ("" if quiet else "set -x;", dir, dir))
138 print('copy comps.xml')
139 comps = '%s.stat/repodata/comps.xml' % ftp_dir
140 os.system('%s cp -p %s %s/repodata' % ("" if quiet else "set -x;", comps, dir))