]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - release/scripts/package-split.py
Update default FreeBSD version.
[FreeBSD/stable/8.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 if 'PKG_MEMSTICK' in os.environ:
27     doing_memstick = 1
28 else:
29     doing_memstick = 0
30
31 if 'PKG_DVD' in os.environ:
32     doing_dvd = 1
33 else:
34     doing_dvd = 0
35
36 # List of packages.  At this point only the English documentation fits
37 # on disc1.  Add in the rest of the documentation for the memstick image.
38 # And add in enough packages to make a basic graphical workstation for the
39 # dvd image.
40 def disc1_packages():
41     pkgs = ['misc/freebsd-doc-en'] 
42
43     if doing_memstick or doing_dvd:
44         pkgs.extend(['misc/freebsd-doc-bn', 
45             'misc/freebsd-doc-da',
46             'misc/freebsd-doc-de',
47             'misc/freebsd-doc-el',
48             'misc/freebsd-doc-es',
49             'misc/freebsd-doc-fr',
50             'misc/freebsd-doc-hu',
51             'misc/freebsd-doc-it',
52             'misc/freebsd-doc-ja',
53             'misc/freebsd-doc-mn',
54             'misc/freebsd-doc-nl',
55             'misc/freebsd-doc-pl',
56             'misc/freebsd-doc-pt',
57             'misc/freebsd-doc-ru',
58             'misc/freebsd-doc-sr',
59             'misc/freebsd-doc-tr',
60             'misc/freebsd-doc-zh_cn',
61             'misc/freebsd-doc-zh_tw'])
62
63     if doing_dvd:
64         pkgs.extend(['archivers/unzip',
65             'emulators/linux_base-f10',
66             'lang/perl5.12',
67             'misc/freebsd-doc-all',
68             'net/mpd5',
69             'net/rsync',
70             'ports-mgmt/portaudit',
71             'ports-mgmt/portmaster',
72             'shells/bash',
73             'shells/zsh',
74             'security/sudo',
75             'sysutils/screen',
76             'www/firefox',
77             'www/links',
78             'x11-drivers/xf86-video-vmware',
79             'x11/gnome2',
80             'x11/kde4',
81             'x11/xorg'])
82     return pkgs
83
84 # The list of desired packages
85 def desired_packages():
86     disc1 = disc1_packages()
87     return [disc1]
88
89 # Suck the entire INDEX file into a two different dictionaries.  The first
90 # dictionary maps port names (origins) to package names.  The second
91 # dictionary maps a package name to a list of its dependent packages.
92 PACKAGE_COL=0
93 ORIGIN_COL=1
94 DEPENDS_COL=8
95
96 def load_index(index):
97     deps = {}
98     pkgs = {}
99     line_num = 1
100     for line in index:
101         fields = line.split('|')
102         name = fields[PACKAGE_COL]
103         if name in deps:
104             sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
105             sys.exit(1)
106         origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
107         if origin in pkgs:
108             sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
109             sys.exit(1)
110         deps[name] = fields[DEPENDS_COL].split()
111         pkgs[origin] = name
112         line_num = line_num + 1
113     return (deps, pkgs)
114
115 # Layout the packages on the various CD images.  Here's how it works.  We walk
116 # each disc in the list of discs.  Within each disc we walk the list of ports.
117 # For each port, we add the package name to a dictionary with the value being
118 # the current disc number.  We also add all of the dependent packages.  If
119 # a package is already in the dictionary when we go to add it, we just leave
120 # the dictionary as it is.  This means that each package ends up on the first
121 # disc that either lists it or contains it as a dependency.
122 def layout_discs(discs, pkgs, deps):
123     disc_num = 1
124     layout = {}
125     for disc in discs:
126         for port in disc:
127             if port not in pkgs:
128                 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
129                                  (disc_num, port))
130                 continue
131             pkg = pkgs[port]
132             pkg_list = [pkg] + deps[pkg]
133             for pkg in pkg_list:
134                 if pkg not in layout:
135                     if verbose:
136                         print "--> Adding %s to Disc %d" % (pkg, disc_num)
137                     layout[pkg] = disc_num
138         disc_num = disc_num + 1
139     return layout
140
141 # Generate a master INDEX file based on the generated layout.  The way this
142 # works is that for each INDEX line, we check to see if the package is in the
143 # layout.  If it is, we put that INDEX line into the master INDEX and append
144 # a new field with the disc number to the line.
145 def generate_index(index, layout, master_index):
146     for line in index:
147         pkg = line.split('|')[PACKAGE_COL]
148         if pkg in layout:
149             new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
150             master_index.write(new_line)
151
152 # Verify the command line arguments
153 if len(sys.argv) != 3:
154     sys.stderr.write('Invalid number of arguments\n')
155     sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
156     sys.exit(1)
157
158 print "Loading %s..." % (sys.argv[1])
159 index = file(sys.argv[1])
160 (deps, pkgs) = load_index(index)
161 discs = desired_packages()
162 layout = layout_discs(discs, pkgs, deps)
163 index.seek(0)
164 print "Generating %s..." % (sys.argv[2])
165 master_index = file(sys.argv[2], 'w')
166 generate_index(index, layout, master_index)
167 index.close()
168 master_index.close()