3 import urllib, sys, optparse, re, subprocess
5 kernel_pkg_re = re.compile('linux-(generic|firmware|headers|image|backports|ec2|source|virtual|preempt)')
10 Return (options, manifest) tuple.
13 optparser = optparse.OptionParser('''%prog [options] <manifest>
15 Install/remove packages according to a CD build manifest.
16 <manifest> can be a local file or URL.''')
17 optparser.add_option('-k', '--keep-kernel',
18 help='Do not change kernel packages', action='store_true',
19 dest='keep_kernel', default=False)
20 options, args = optparser.parse_args()
23 optparser.error('You need to specify exactly one manifest argument, see --help')
26 return (options, args[0])
32 (options, manifest) = parse_argv()
35 for l in urllib.urlopen(manifest):
37 if options.keep_kernel and kernel_pkg_re.match(pkg):
39 selection += '%s\tinstall\n' % pkg
41 # add local kernel packages on --keep-kernel
42 if options.keep_kernel:
43 dpkg = subprocess.Popen(['dpkg', '--get-selections'],
44 stdout=subprocess.PIPE)
46 pkg, status = l.split()
47 if status != 'install':
49 if kernel_pkg_re.match(pkg):
50 selection += '%s\tinstall\n' % pkg
52 if subprocess.call(['which', 'dselect'], stdout=subprocess.PIPE) != 0:
53 print >> sys.stderr, 'INFO: installing dselect (needed by this script)'
54 assert subprocess.call(['apt-get', '-y', 'install', 'dselect']) == 0
56 # now apply the new selections
57 assert subprocess.call(['dpkg', '--clear-selections']) == 0
58 dpkg = subprocess.Popen(['dpkg', '--set-selections'], stdin=subprocess.PIPE)
59 dpkg.communicate(selection)
60 assert dpkg.returncode == 0
63 subprocess.call(['dselect', 'install'])