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