]>
Commit | Line | Data |
---|---|---|
a1e62e44 | 1 | #!/usr/bin/env python3 |
df78f748 MM |
2 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et |
3 | ||
2ec96333 JR |
4 | from __future__ import print_function |
5 | ||
fdf5d714 | 6 | import getopt |
df78f748 MM |
7 | import sys, os |
8 | sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') | |
9 | from common import checkdir | |
796b7867 | 10 | from config import ftp_dir,all_ftp_archs |
0bf1ad60 | 11 | import config |
df78f748 MM |
12 | import ftpio |
13 | ||
fdf5d714 | 14 | try: |
b4c008d4 ER |
15 | opts, args = getopt.getopt(sys.argv[1:], 'q', |
16 | [ | |
17 | "quiet", "index=", | |
18 | "nopoldek", "noyum", "norpmrepo", | |
19 | "poldek", "yum", "rpmrepo" | |
20 | ] | |
21 | ) | |
fdf5d714 | 22 | except getopt.GetoptError: |
2ec96333 JR |
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) | |
df78f748 MM |
25 | sys.exit(1) |
26 | ||
fdf5d714 | 27 | do_poldek = True |
15ae1c82 | 28 | do_yum = True |
bc8134ee | 29 | do_rpmrepo = False |
b4c008d4 | 30 | quiet = False |
a7ab51cd ER |
31 | # update only if changed (applicable to yum) |
32 | freshen = True | |
fdf5d714 AM |
33 | |
34 | for o, a in opts: | |
35 | if o == "--nopoldek": | |
36 | do_poldek = False | |
37 | if o == "--noyum": | |
38 | do_yum = False | |
bc8134ee ER |
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 | ||
b4c008d4 ER |
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 | ||
62 | if not quiet: | |
2ec96333 | 63 | print("poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo)) |
fbfae074 | 64 | |
bc8134ee | 65 | if not do_poldek and not do_yum and not do_rpmrepo: |
2ec96333 | 66 | print("ERR: speciy at least one action", file=sys.stderr) |
fdf5d714 AM |
67 | sys.exit(1) |
68 | ||
8911f226 | 69 | trees = args |
df78f748 MM |
70 | |
71 | for tree in trees: | |
72 | checkdir(tree) | |
73 | ||
74 | ftpio.connect('gen-indexes') | |
75 | ||
8911f226 | 76 | locked = [] |
df78f748 MM |
77 | |
78 | for tree in trees: | |
79 | if ftpio.lock(tree, True): | |
80 | locked.append(tree) | |
81 | else: | |
2ec96333 | 82 | print("ERR: %s tree already locked" % tree, file=sys.stderr) |
df78f748 MM |
83 | for i in locked: |
84 | ftpio.unlock(i) | |
85 | sys.exit(1) | |
86 | ||
8911f226 | 87 | home = os.environ['HOME'] |
df78f748 | 88 | |
ce26983c | 89 | os.umask(0o022) |
728ca432 | 90 | os.nice(19) |
65473a80 | 91 | |
fdf5d714 | 92 | if do_poldek: |
8911f226 ER |
93 | poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir) |
94 | ||
fdf5d714 | 95 | for tree in trees: |
2ec96333 | 96 | print('\n-------------------------- %s --------------------------' % tree) |
fdf5d714 | 97 | for arch in all_ftp_archs: |
2ec96333 JR |
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)) | |
255b5e63 ER |
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)) | |
fdf5d714 AM |
103 | |
104 | if do_yum: | |
a7343854 JR |
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) | |
865770d5 | 107 | comps_file = '%s.stat/repodata/comps.xml' % ftp_dir |
fdf5d714 | 108 | for tree in trees: |
2ec96333 | 109 | print('\n-------------------------- %s --------------------------' % tree) |
8911f226 | 110 | cachedir = '%s/tmp/createrepo/%s' % (home, tree) |
a7343854 | 111 | os.makedirs(cachedir, mode=711, exist_ok=True) |
b1b2ab1f | 112 | treedir = "%s%s" % (ftp_dir, tree) |
fdf5d714 | 113 | for arch in all_ftp_archs: |
2ec96333 | 114 | print('\ngenerate repodata for %s using createrepo' % arch) |
b1b2ab1f | 115 | archdir = "%s/%s" % (treedir, arch) |
a7ab51cd ER |
116 | poldek_idx = "%s/RPMS/packages.ndir.md" % archdir |
117 | repodata_idx = "%s/RPMS/repodata/repomd.xml" % archdir | |
865770d5 ER |
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): | |
2ec96333 | 121 | print("repodata indexes already fresh") |
a7ab51cd | 122 | continue |
a7343854 JR |
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)) | |
f7ba8f7b | 125 | if arch != 'noarch' and config.separate_debuginfo: |
a7343854 | 126 | os.system('%s %s --cachedir=%s-%s %s/debuginfo' % ("" if quiet else "time", yum, cachedir, arch, archdir)) |
df78f748 | 127 | |
bc8134ee | 128 | if do_rpmrepo: |
b4c008d4 | 129 | os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q")) |
bc8134ee | 130 | for tree in trees: |
2ec96333 | 131 | print('\n-------------------------- %s --------------------------' % tree) |
bc8134ee ER |
132 | for arch in all_ftp_archs: |
133 | dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch) | |
b4c008d4 | 134 | if not quiet: |
2ec96333 | 135 | print('\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir)) |
b4c008d4 ER |
136 | os.system('%s rpmrepo %s -o %s' % ("" if quiet else "set -x;", dir, dir)) |
137 | if not quiet: | |
2ec96333 | 138 | print('copy comps.xml') |
7444a3de | 139 | comps = '%s.stat/repodata/comps.xml' % ftp_dir |
b4c008d4 | 140 | os.system('%s cp -p %s %s/repodata' % ("" if quiet else "set -x;", comps, dir)) |
bc8134ee | 141 | |
df78f748 MM |
142 | for tree in trees: |
143 | ftpio.unlock(tree) |