chiark / gitweb /
Spec: incompatible change: no-build-needed is the default
[autopkgtest.git] / virt-subproc / adt-virt-chroot
1 #!/usr/bin/python2.4
2 #
3 # adt-virt-chroot is part of autopkgtest
4 # autopkgtest is a tool for testing Debian binary packages
5 #
6 # autopkgtest is Copyright (C) 2006-2007 Canonical Ltd.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #
22 # See the file CREDITS for a full list of credits information (often
23 # installed as /usr/share/doc/autopkgtest/CREDITS).
24
25 import sys
26 import os
27 import string
28 from optparse import OptionParser
29
30 try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib'
31 except KeyError: our_base = '/usr/share/autopkgtest/python';
32 sys.path.insert(1, our_base)
33
34 import VirtSubproc as vsp
35 capabilities = []
36
37 def parse_args():
38         global down, debuglevel
39
40         usage = "%prog [<options>] =<dchroot>|/path/to/chroot"
41         parser = OptionParser(usage=usage)
42         pa = parser.add_option
43         pe = parser.error
44
45         pa('-r', '--gain-root', type='string', dest='gain_root');
46         pa('-d', '--debug', action='store_true', dest='debug');
47
48         (opts,args) = parser.parse_args()
49         if len(args) != 1: pe("need exactly one arg, chroot specification")
50
51         vsp.debuglevel = opts.debug
52
53         chroot_arg = args[0]
54         if not chroot_arg: pe("chroot specification may not be empty")
55         if chroot_arg == '=':
56                 down = ['dchroot','-q','--']
57         elif chroot_arg == '=':
58                 down = ['dchroot','-q','--']
59         elif chroot_arg[0] == '=':
60                 down = ['dchroot','-q','-c',chroot_arg[1:],'--']
61         elif chroot_arg[0] == '/':
62                 down = ['chroot',chroot_arg]
63         else:
64                 pe("chroot spec must be =[DCHROOT] or /PATH/TO/CHROOT")
65
66         if down[0] == 'chroot':
67                 vsp.downkind = 'auxverb'
68         elif down[0] == 'dchroot':
69                 vsp.downkind = 'shstring'
70         else:
71                 print >>sys.stderr, 'down[0]=%s' % `down[0]`
72                 assert(False)
73
74         if opts.gain_root != None:
75                 down = opts.gain_root.split() + down
76
77         if opts.gain_root or os.getuid()==0:
78                 capabilities.append('root-on-testbed')
79
80         vsp.down = down
81
82 def hook_open():
83         pass
84
85 def hook_downtmp():
86         return vsp.downtmp_mktemp()
87
88 def hook_cleanup():
89         vsp.downtmp_remove()
90
91 def hook_forked_inchild():
92         pass
93
94 def hook_capabilities():
95         return capabilities
96
97 parse_args()
98 vsp.main()