]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame_incremental - bin/pfa-genindex
Switch to Python 3 for rpm.org rpm
[projects/pld-ftp-admin.git] / bin / pfa-genindex
... / ...
CommitLineData
1#!/usr/bin/env python3
2# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
4from __future__ import print_function
5
6import getopt
7import sys, os
8sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
9from common import checkdir
10from config import ftp_dir,all_ftp_archs
11import config
12import ftpio
13
14try:
15 opts, args = getopt.getopt(sys.argv[1:], 'q',
16 [
17 "quiet", "index=",
18 "nopoldek", "noyum", "norpmrepo",
19 "poldek", "yum", "rpmrepo"
20 ]
21 )
22except 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)
25 sys.exit(1)
26
27do_poldek = True
28do_yum = False
29do_rpmrepo = False
30quiet = False
31# update only if changed (applicable to yum)
32freshen = True
33
34for o, a in opts:
35 if o == "--nopoldek":
36 do_poldek = False
37 if o == "--noyum":
38 do_yum = False
39 if o == "--norpmrepo":
40 do_rpmrepo = False
41
42 if o == "--poldek":
43 do_poldek = True
44 if o == "--yum":
45 do_yum = True
46 if o == "--rpmrepo":
47 do_rpmrepo = True
48
49 if o == "-q" or o == "--quiet":
50 quiet = True
51
52 if o == "--index":
53 do_poldek = do_yum = do_rpmrepo = False
54 for v in a.split(','):
55 if v == 'poldek':
56 do_poldek = True
57 if v == 'yum':
58 do_yum = True
59 if v == 'rpmrepo':
60 do_rpmrepo = True
61
62if not quiet:
63 print("poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo))
64
65if not do_poldek and not do_yum and not do_rpmrepo:
66 print("ERR: speciy at least one action", file=sys.stderr)
67 sys.exit(1)
68
69trees = args
70
71for tree in trees:
72 checkdir(tree)
73
74ftpio.connect('gen-indexes')
75
76locked = []
77
78for tree in trees:
79 if ftpio.lock(tree, True):
80 locked.append(tree)
81 else:
82 print("ERR: %s tree already locked" % tree, file=sys.stderr)
83 for i in locked:
84 ftpio.unlock(i)
85 sys.exit(1)
86
87home = os.environ['HOME']
88
89os.umask(0o022)
90os.nice(19)
91
92if do_poldek:
93 poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir)
94
95 for tree in trees:
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))
103
104if do_yum:
105 os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q"))
106 yum = '%s.stat/bin/createrepo -d -v --update --checkts --skip-stat --workers=12 -g %s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir)
107 comps_file = '%s.stat/repodata/comps.xml' % ftp_dir
108 for tree in trees:
109 print('\n-------------------------- %s --------------------------' % tree)
110 cachedir = '%s/tmp/createrepo/%s' % (home, tree)
111 treedir = "%s%s" % (ftp_dir, tree)
112 for arch in all_ftp_archs:
113 print('\ngenerate repodata for %s using createrepo' % arch)
114 archdir = "%s/%s" % (treedir, arch)
115 poldek_idx = "%s/RPMS/packages.ndir.md" % archdir
116 repodata_idx = "%s/RPMS/repodata/repomd.xml" % archdir
117 if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \
118 and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \
119 and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx):
120 print("repodata indexes already fresh")
121 continue
122 print('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir))
123 os.system('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir))
124 if arch != 'noarch' and config.separate_debuginfo:
125 os.system('%s %s --cache %s-%s %s/debuginfo' % ("" if quiet else "time", yum, cachedir, arch, archdir))
126
127if do_rpmrepo:
128 os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q"))
129 for tree in trees:
130 print('\n-------------------------- %s --------------------------' % tree)
131 for arch in all_ftp_archs:
132 dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch)
133 if not quiet:
134 print('\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir))
135 os.system('%s rpmrepo %s -o %s' % ("" if quiet else "set -x;", dir, dir))
136 if not quiet:
137 print('copy comps.xml')
138 comps = '%s.stat/repodata/comps.xml' % ftp_dir
139 os.system('%s cp -p %s %s/repodata' % ("" if quiet else "set -x;", comps, dir))
140
141for tree in trees:
142 ftpio.unlock(tree)
This page took 0.03894 seconds and 4 git commands to generate.