]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/scripts/package-split.py
This commit was generated by cvs2svn to compensate for changes in r171831,
[FreeBSD/FreeBSD.git] / release / scripts / package-split.py
1 #!/usr/local/bin/python
2 #
3 # This script generates a master INDEX file for the CD images built by the
4 # FreeBSD release engineers.  Each disc is given a list of desired packages.
5 # Dependencies of these packages are placed on either the same disc or an
6 # earlier disc.  The resulting master INDEX file is then written out.
7 #
8 # Usage: package-split.py <INDEX> <master INDEX>
9 #
10 # $FreeBSD$
11
12 import os
13 import sys
14
15 try:
16     arch = os.environ["PKG_ARCH"]
17 except:
18     arch = os.uname()[4]
19 print "Using arch %s" % (arch)
20
21 if 'PKG_VERBOSE' in os.environ:
22     verbose = 1
23 else:
24     verbose = 0
25
26 # List of packages for disc1.  This just includes packages sysinstall can
27 # install as a distribution
28 def disc1_packages():
29     # 5.x only
30     pkgs = ['lang/perl5.8']
31     pkgs.extend(['x11/xorg',
32                  'x11/xorg-manpages',
33                  'devel/imake-6'])
34     if arch == 'i386':
35         pkgs.append('emulators/linux_base-fc4')
36     return pkgs
37
38 # List of packages for disc2.  This includes packages that the X desktop
39 # menu depends on (if it still exists) and other "nice to have" packages.
40 # For architectures that use a separate livefs, this is actually disc3.
41 def disc2_packages():
42             # X Desktops
43     if arch == 'ia64':
44         pkgs = ['x11/gnome2-lite',
45                 'x11/kde-lite']
46     else:
47         pkgs = ['x11/gnome2',
48                 'x11/kde3']
49     pkgs.extend(['x11-wm/afterstep',
50             'x11-wm/windowmaker',
51             'x11-wm/fvwm2',
52             # "Nice to have"
53             'archivers/unzip',
54             'astro/xearth',                 
55             'devel/gmake',
56             'editors/emacs',
57             'editors/vim-lite',
58             'emulators/mtools',
59             'graphics/png',
60             'graphics/xv',
61             'irc/xchat',
62             'mail/exim',
63             'mail/fetchmail',
64             'mail/mutt',
65             'mail/pine4',
66             'mail/popd',
67             'mail/xfmail',
68             'mail/postfix',
69             'net/cvsup-without-gui',
70             'net/rsync',
71             'net/samba3',
72             'news/slrn',
73             'news/tin',
74             'print/a2ps-letter',
75             'print/apsfilter',
76             'print/ghostscript-gnu-nox11',
77             'print/gv',
78             'print/psutils-letter',
79             'shells/bash2',
80             'shells/pdksh',
81             'shells/zsh',
82             'security/sudo',
83             'sysutils/portupgrade',
84             'www/links',
85             'www/lynx',
86             'x11/rxvt',
87             # Formerly on disc3
88             'security/portaudit'])
89     return pkgs
90
91 # The list of desired packages
92 def desired_packages():
93     disc1 = disc1_packages()
94     disc2 = disc2_packages()
95     return [disc1, disc2]
96
97 # Suck the entire INDEX file into a two different dictionaries.  The first
98 # dictionary maps port names (origins) to package names.  The second
99 # dictionary maps a package name to a list of its dependent packages.
100 PACKAGE_COL=0
101 ORIGIN_COL=1
102 DEPENDS_COL=8
103
104 def load_index(index):
105     deps = {}
106     pkgs = {}
107     line_num = 1
108     for line in index:
109         fields = line.split('|')
110         name = fields[PACKAGE_COL]
111         if name in deps:
112             sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
113             sys.exit(1)
114         origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
115         if origin in pkgs:
116             sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
117             sys.exit(1)
118         deps[name] = fields[DEPENDS_COL].split()
119         pkgs[origin] = name
120         line_num = line_num + 1
121     return (deps, pkgs)
122
123 # Layout the packages on the various CD images.  Here's how it works.  We walk
124 # each disc in the list of discs.  Within each disc we walk the list of ports.
125 # For each port, we add the package name to a dictionary with the value being
126 # the current disc number.  We also add all of the dependent packages.  If
127 # a package is already in the dictionary when we go to add it, we just leave
128 # the dictionary as it is.  This means that each package ends up on the first
129 # disc that either lists it or contains it as a dependency.
130 def layout_discs(discs, pkgs, deps):
131     disc_num = 1
132     layout = {}
133     for disc in discs:
134         for port in disc:
135             if port not in pkgs:
136                 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
137                                  (disc_num, port))
138                 continue
139             pkg = pkgs[port]
140             pkg_list = [pkg] + deps[pkg]
141             for pkg in pkg_list:
142                 if pkg not in layout:
143                     if verbose:
144                         print "--> Adding %s to Disc %d" % (pkg, disc_num)
145                     layout[pkg] = disc_num
146         disc_num = disc_num + 1
147     return layout
148
149 # Generate a master INDEX file based on the generated layout.  The way this
150 # works is that for each INDEX line, we check to see if the package is in the
151 # layout.  If it is, we put that INDEX line into the master INDEX and append
152 # a new field with the disc number to the line.
153 def generate_index(index, layout, master_index):
154     for line in index:
155         pkg = line.split('|')[PACKAGE_COL]
156         if pkg in layout:
157             new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
158             master_index.write(new_line)
159
160 # Verify the command line arguments
161 if len(sys.argv) != 3:
162     sys.stderr.write('Invalid number of arguments\n')
163     sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
164     sys.exit(1)
165
166 print "Loading %s..." % (sys.argv[1])
167 index = file(sys.argv[1])
168 (deps, pkgs) = load_index(index)
169 discs = desired_packages()
170 layout = layout_discs(discs, pkgs, deps)
171 index.seek(0)
172 print "Generating %s..." % (sys.argv[2])
173 master_index = file(sys.argv[2], 'w')
174 generate_index(index, layout, master_index)
175 index.close()
176 master_index.close()