]> CyberLeo.Net >> Repos - FreeBSD/releng/9.1.git/blob - release/scripts/package-split.py
MFC r239655:
[FreeBSD/releng/9.1.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 dvd1.
27 def dvd1_packages():
28     pkgs = ['archivers/unzip',
29             'emulators/linux_base-f10',
30             'lang/perl5.12',
31             'misc/freebsd-doc-all',
32             'net/mpd5',
33             'net/rsync',
34             'ports-mgmt/portaudit',
35             'ports-mgmt/portmaster',
36             'shells/bash',
37             'shells/zsh',
38             'security/sudo',
39             'sysutils/screen',
40             'www/firefox',
41             'www/links',
42             'x11-drivers/xf86-video-vmware',
43             'x11/gnome2',
44             'x11/kde4',
45             'x11/xorg'];
46     return pkgs
47
48 # The list of desired packages
49 def desired_packages():
50     dvd1 = dvd1_packages()
51     return [dvd1]
52
53 # Suck the entire INDEX file into a two different dictionaries.  The first
54 # dictionary maps port names (origins) to package names.  The second
55 # dictionary maps a package name to a list of its dependent packages.
56 PACKAGE_COL=0
57 ORIGIN_COL=1
58 DEPENDS_COL=8
59
60 def load_index(index):
61     deps = {}
62     pkgs = {}
63     line_num = 1
64     for line in index:
65         fields = line.split('|')
66         name = fields[PACKAGE_COL]
67         if name in deps:
68             sys.stderr.write('%d: Duplicate package %s\n' % (line_num, name))
69             sys.exit(1)
70         origin = fields[ORIGIN_COL].replace('/usr/ports/', '', 1)
71         if origin in pkgs:
72             sys.stderr.write('%d: Duplicate port %s\n' % (line_num, origin))
73             sys.exit(1)
74         deps[name] = fields[DEPENDS_COL].split()
75         pkgs[origin] = name
76         line_num = line_num + 1
77     return (deps, pkgs)
78
79 # Layout the packages on the various CD images.  Here's how it works.  We walk
80 # each disc in the list of discs.  Within each disc we walk the list of ports.
81 # For each port, we add the package name to a dictionary with the value being
82 # the current disc number.  We also add all of the dependent packages.  If
83 # a package is already in the dictionary when we go to add it, we just leave
84 # the dictionary as it is.  This means that each package ends up on the first
85 # disc that either lists it or contains it as a dependency.
86 def layout_discs(discs, pkgs, deps):
87     disc_num = 1
88     layout = {}
89     for disc in discs:
90         for port in disc:
91             if port not in pkgs:
92                 sys.stderr.write('Disc %d: Unable to find package for %s\n' %
93                                  (disc_num, port))
94                 continue
95             pkg = pkgs[port]
96             pkg_list = [pkg] + deps[pkg]
97             for pkg in pkg_list:
98                 if pkg not in layout:
99                     if verbose:
100                         print "--> Adding %s to Disc %d" % (pkg, disc_num)
101                     layout[pkg] = disc_num
102         disc_num = disc_num + 1
103     return layout
104
105 # Generate a master INDEX file based on the generated layout.  The way this
106 # works is that for each INDEX line, we check to see if the package is in the
107 # layout.  If it is, we put that INDEX line into the master INDEX and append
108 # a new field with the disc number to the line.
109 def generate_index(index, layout, master_index):
110     for line in index:
111         pkg = line.split('|')[PACKAGE_COL]
112         if pkg in layout:
113             new_line = '%s|%d\n' % (line.splitlines()[0], layout[pkg])
114             master_index.write(new_line)
115
116 # Verify the command line arguments
117 if len(sys.argv) != 3:
118     sys.stderr.write('Invalid number of arguments\n')
119     sys.stderr.write('Usage: package-split.py <source INDEX> <master INDEX>\n')
120     sys.exit(1)
121
122 print "Loading %s..." % (sys.argv[1])
123 index = file(sys.argv[1])
124 (deps, pkgs) = load_index(index)
125 discs = desired_packages()
126 layout = layout_discs(discs, pkgs, deps)
127 index.seek(0)
128 print "Generating %s..." % (sys.argv[2])
129 master_index = file(sys.argv[2], 'w')
130 generate_index(index, layout, master_index)
131 index.close()
132 master_index.close()