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