]>
Commit | Line | Data |
---|---|---|
df78f748 MM |
1 | #!/usr/bin/env python |
2 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et | |
3 | ||
fdf5d714 | 4 | import getopt |
df78f748 MM |
5 | import sys, os |
6 | sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') | |
7 | from common import checkdir | |
796b7867 | 8 | from config import ftp_dir,all_ftp_archs |
0bf1ad60 | 9 | import config |
df78f748 MM |
10 | import ftpio |
11 | ||
fdf5d714 | 12 | try: |
b4c008d4 ER |
13 | opts, args = getopt.getopt(sys.argv[1:], 'q', |
14 | [ | |
15 | "quiet", "index=", | |
16 | "nopoldek", "noyum", "norpmrepo", | |
17 | "poldek", "yum", "rpmrepo" | |
18 | ] | |
19 | ) | |
fdf5d714 | 20 | except getopt.GetoptError: |
8911f226 | 21 | print >>sys.stderr, "ERR: not enough parameters given" |
053d2c0e | 22 | print >>sys.stderr, "gen-indexes.py [--quiet] [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]" |
df78f748 MM |
23 | sys.exit(1) |
24 | ||
fdf5d714 | 25 | do_poldek = True |
d9bbfa2e | 26 | do_yum = False |
bc8134ee | 27 | do_rpmrepo = False |
b4c008d4 | 28 | quiet = False |
a7ab51cd ER |
29 | # update only if changed (applicable to yum) |
30 | freshen = True | |
fdf5d714 AM |
31 | |
32 | for o, a in opts: | |
33 | if o == "--nopoldek": | |
34 | do_poldek = False | |
35 | if o == "--noyum": | |
36 | do_yum = False | |
bc8134ee ER |
37 | if o == "--norpmrepo": |
38 | do_rpmrepo = False | |
39 | ||
40 | if o == "--poldek": | |
41 | do_poldek = True | |
42 | if o == "--yum": | |
43 | do_yum = True | |
44 | if o == "--rpmrepo": | |
45 | do_rpmrepo = True | |
46 | ||
b4c008d4 ER |
47 | if o == "-q" or o == "--quiet": |
48 | quiet = True | |
49 | ||
50 | if o == "--index": | |
51 | do_poldek = do_yum = do_rpmrepo = False | |
52 | for v in a.split(','): | |
53 | if v == 'poldek': | |
54 | do_poldek = True | |
55 | if v == 'yum': | |
56 | do_yum = True | |
57 | if v == 'rpmrepo': | |
58 | do_rpmrepo = True | |
59 | ||
60 | if not quiet: | |
61 | print "poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo) | |
fbfae074 | 62 | |
bc8134ee | 63 | if not do_poldek and not do_yum and not do_rpmrepo: |
8911f226 | 64 | print >>sys.stderr, "ERR: speciy at least one action" |
fdf5d714 AM |
65 | sys.exit(1) |
66 | ||
8911f226 | 67 | trees = args |
df78f748 MM |
68 | |
69 | for tree in trees: | |
70 | checkdir(tree) | |
71 | ||
72 | ftpio.connect('gen-indexes') | |
73 | ||
8911f226 | 74 | locked = [] |
df78f748 MM |
75 | |
76 | for tree in trees: | |
77 | if ftpio.lock(tree, True): | |
78 | locked.append(tree) | |
79 | else: | |
b4c008d4 | 80 | if not quiet: |
fbfae074 | 81 | print >>sys.stderr, "ERR: %s tree already locked" % tree |
df78f748 MM |
82 | for i in locked: |
83 | ftpio.unlock(i) | |
84 | sys.exit(1) | |
85 | ||
8911f226 | 86 | home = os.environ['HOME'] |
df78f748 | 87 | |
65473a80 | 88 | os.umask(022) |
728ca432 | 89 | os.nice(19) |
65473a80 | 90 | |
fdf5d714 | 91 | if do_poldek: |
8911f226 ER |
92 | poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir) |
93 | ||
fdf5d714 | 94 | for tree in trees: |
fa0549d4 | 95 | print '\n-------------------------- %s --------------------------' % tree |
fdf5d714 | 96 | for arch in all_ftp_archs: |
fa0549d4 | 97 | print '\ngenerate poldek index for %s' % arch |
070be332 | 98 | print '%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch) |
255b5e63 ER |
99 | os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) |
100 | if arch != 'noarch' and config.separate_debuginfo: | |
101 | os.system('%s -s %s%s/%s/debuginfo/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) | |
fdf5d714 AM |
102 | |
103 | if do_yum: | |
b4c008d4 | 104 | os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q")) |
865770d5 ER |
105 | yum = '%s.stat/bin/createrepo -d -v --update --checkts --skip-stat --workers=12 -g %s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir) |
106 | comps_file = '%s.stat/repodata/comps.xml' % ftp_dir | |
fdf5d714 | 107 | for tree in trees: |
fa0549d4 | 108 | print '\n-------------------------- %s --------------------------' % tree |
8911f226 | 109 | cachedir = '%s/tmp/createrepo/%s' % (home, tree) |
b1b2ab1f | 110 | treedir = "%s%s" % (ftp_dir, tree) |
fdf5d714 | 111 | for arch in all_ftp_archs: |
fa0549d4 | 112 | print '\ngenerate repodata for %s using createrepo' % arch |
b1b2ab1f | 113 | archdir = "%s/%s" % (treedir, arch) |
a7ab51cd ER |
114 | poldek_idx = "%s/RPMS/packages.ndir.md" % archdir |
115 | repodata_idx = "%s/RPMS/repodata/repomd.xml" % archdir | |
865770d5 ER |
116 | if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \ |
117 | and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \ | |
118 | and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx): | |
a7ab51cd ER |
119 | print "repodata indexes already fresh" |
120 | continue | |
b1b2ab1f ER |
121 | print ('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir)) |
122 | os.system('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir)) | |
f7ba8f7b | 123 | if arch != 'noarch' and config.separate_debuginfo: |
b1b2ab1f | 124 | os.system('%s %s --cache %s-%s %s/debuginfo' % ("" if quiet else "time", yum, cachedir, arch, archdir)) |
df78f748 | 125 | |
bc8134ee | 126 | if do_rpmrepo: |
b4c008d4 | 127 | os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q")) |
bc8134ee | 128 | for tree in trees: |
fa0549d4 | 129 | print '\n-------------------------- %s --------------------------' % tree |
bc8134ee ER |
130 | for arch in all_ftp_archs: |
131 | dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch) | |
b4c008d4 | 132 | if not quiet: |
386310ed | 133 | print '\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir) |
b4c008d4 ER |
134 | os.system('%s rpmrepo %s -o %s' % ("" if quiet else "set -x;", dir, dir)) |
135 | if not quiet: | |
386310ed | 136 | print 'copy comps.xml' |
7444a3de | 137 | comps = '%s.stat/repodata/comps.xml' % ftp_dir |
b4c008d4 | 138 | os.system('%s cp -p %s %s/repodata' % ("" if quiet else "set -x;", comps, dir)) |
bc8134ee | 139 | |
df78f748 MM |
140 | for tree in trees: |
141 | ftpio.unlock(tree) |