]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - bin/pfa-genindex
- code formatting
[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:], None, ["nopoldek", "noyum", "norpmrepo", "poldek", "yum", "rpmrepo"])
14 except getopt.GetoptError:
15     print >>sys.stderr, "ERR: not enough parameters given"
16     print >>sys.stderr, "gen-indexes.py [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]"
17     sys.exit(1)
18
19 do_poldek = True
20 do_yum = True
21 do_rpmrepo = False
22
23 for o, a in opts:
24     if o == "--nopoldek":
25         do_poldek = False
26     if o == "--noyum":
27         do_yum = False
28     if o == "--norpmrepo":
29         do_rpmrepo = False
30
31     if o == "--poldek":
32         do_poldek = True
33     if o == "--yum":
34         do_yum = True
35     if o == "--rpmrepo":
36         do_rpmrepo = True
37
38 if not do_poldek and not do_yum and not do_rpmrepo:
39     print >>sys.stderr, "ERR: speciy at least one action"
40     sys.exit(1)
41
42 trees = args
43
44 for tree in trees:
45     checkdir(tree)
46
47 ftpio.connect('gen-indexes')
48
49 locked = []
50
51 for tree in trees:
52     if ftpio.lock(tree, True):
53         locked.append(tree)
54     else:
55         print >>sys.stderr, "ERR: %s tree already locked" % tree
56         for i in locked:
57             ftpio.unlock(i)
58         sys.exit(1)
59
60 home = os.environ['HOME']
61
62 os.umask(022)
63 os.nice(19)
64
65 if do_poldek:
66     poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir)
67
68     for tree in trees:
69         print '-------------------------- %s --------------------------' % tree
70         for arch in all_ftp_archs:
71             print 'generate poldek index for %s' % arch
72             if config.poldek_indexes != "old":
73                 os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch))
74             if config.poldek_indexes != "new":
75                 os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pdir' % (poldek, ftp_dir, tree, arch))
76
77 if do_yum:
78     os.system('set -x; cd %s.stat/repodata && cvs up comps.xml' % ftp_dir)
79     yum = '%s.stat/bin/createrepo -d -g %s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir)
80     for tree in trees:
81         print '-------------------------- %s --------------------------' % tree
82         cachedir = '%s/tmp/createrepo/%s' % (home, tree)
83         for arch in all_ftp_archs:
84             print 'generate repodata for %s using createrepo' % arch
85             # Creating indexes for yum and other supporting xml repodata.
86             os.system('time %s --cache %s-%s %s%s/%s/RPMS' % (yum, cachedir, arch, ftp_dir, tree, arch))
87
88 if do_rpmrepo:
89     os.system('set -x; cd %s.stat/repodata && cvs up comps.xml' % ftp_dir)
90     for tree in trees:
91         print '-------------------------- %s --------------------------' % tree
92         for arch in all_ftp_archs:
93             dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch)
94             print 'generate repodata for %s using rpmrepo (in %s)' % (arch, dir)
95             os.system('time rpmrepo %s -o %s' % (dir, dir))
96             print 'copy comps.xml'
97             comps = '%s.stat/repodata/comps.xml' % ftp_dir
98             os.system('set -x; cp -p %s %s/repodata' % (comps, dir))
99
100 for tree in trees:
101     ftpio.unlock(tree)
This page took 0.042874 seconds and 4 git commands to generate.