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