chiark / gitweb /
WIP adt-virt-xenlvm
[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 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
28 try: our_base = os.environ['AUTOPKGTEST_BASE']
29 except KeyError: our_base = '/usr/share/autopkgtest';
30 sys.path.insert(1, our_base+'/python')
31
32 import string
33 from optparse import OptionParser
34 import VirtSubproc as vsp
35
36 def parse_args():
37         global down, debuglevel
38
39         usage = "%prog [options] =<dchroot>|/path/to/chroot"
40         parser = OptionParser(usage=usage)
41         pa = parser.add_option
42         pe = parser.error
43
44         pa('-r', '--gain-root', type='string', dest='gain_root');
45         pa('-d', '--debug', action='store_true', dest='debug');
46
47         (opts,args) = parser.parse_args()
48         if len(args) != 1: pe("need exactly one arg, chroot specification")
49
50         vsp.debuglevel = opts.debug
51
52         chroot_arg = args[0]
53         if not chroot_arg: pe("chroot specification may not be empty")
54         if chroot_arg == '=': down = ['dchroot','-q']
55         elif chroot_arg == '=': down = ['dchroot','-q']
56         elif chroot_arg[0] == '=': down = ['dchroot','-q','-c',chroot_arg[1:]]
57         elif chroot_arg[0] == '/': down = ['chroot',chroot_arg,'--']
58         else: pe("chroot spec must be =[DCHROOT] or /PATH/TO/CHROOT")
59
60         if opts.gain_root != None: down = opts.gain_root.split() + down
61
62         vsp.debug("down = %s" % string.join(down))
63         vsp.down = down
64
65 def hook_open():
66         global downtmp
67         vsp.execute('true', downp=True)
68         downtmp = vsp.execute('mktemp -t -d', downp=True, outp=True)
69         return downtmp
70
71 def hook_stop():
72         vsp.execute('rm -rf --', c[1:2])
73         os.mkdir(c[1])
74
75 def hook_cleanup():
76         vsp.execute('rm -rf --', [downtmp], downp=True)
77
78 parse_args()
79 vsp.main()