From 85c98967781713ebddf30f2201c315e497beb69e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 29 Jul 2011 15:34:24 +0100 Subject: [PATCH] python libs: new Autopkgtest.py module - This makes shellscript quoting available to adt-run too - Python modules moved to lib/ directory - AUTOPKGTEST_BASE semantics have changed slightly --- Makefile | 3 ++- lib/Autopkgtest.py | 28 ++++++++++++++++++++++++++++ lib/VirtSubproc.py | 2 ++ runner/adt-run | 10 ++++++---- virt-subproc/adt-virt-chroot | 6 +++--- virt-subproc/adt-virt-null | 6 +++--- virt-subproc/adt-virt-schroot | 6 +++--- virt-subproc/adt-virt-xenlvm | 6 +++--- 8 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 lib/Autopkgtest.py diff --git a/Makefile b/Makefile index 75de23d..f346c6f 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,8 @@ programs = virt-subproc/adt-virt-chroot \ examples = runner/onepackage-config \ runner/ubuntu-config -pythonfiles = virt-subproc/VirtSubproc.py +pythonfiles = lib/Autopkgtest.py \ + lib/VirtSubproc.py all: cd xen && $(MAKE) diff --git a/lib/Autopkgtest.py b/lib/Autopkgtest.py new file mode 100644 index 0000000..59465e6 --- /dev/null +++ b/lib/Autopkgtest.py @@ -0,0 +1,28 @@ +# Autopkgtest is part of autopkgtest +# autopkgtest is a tool for testing Debian binary packages +# +# autopkgtest is Copyright (C) 2006-2007 Canonical Ltd. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# See the file CREDITS for a full list of credits information (often +# installed as /usr/share/doc/autopkgtest/CREDITS). + +import re as regexp + +_shellquote_re = regexp.compile("'") +def shellquote_arg(s): return "'" + _shellquote_re.sub(r"'\''", s) + "'" +def shellquote_cmdl(l): return ' '.join(map(shellquote_arg,l)) + diff --git a/lib/VirtSubproc.py b/lib/VirtSubproc.py index f1f735d..07ae4a5 100644 --- a/lib/VirtSubproc.py +++ b/lib/VirtSubproc.py @@ -32,6 +32,8 @@ import traceback import errno import re as regexp +from Autopkgtest import * + debuglevel = None progname = "" devnull_read = file('/dev/null','r') diff --git a/runner/adt-run b/runner/adt-run index 0c4a12d..27b33a9 100755 --- a/runner/adt-run +++ b/runner/adt-run @@ -40,6 +40,12 @@ import copy from optparse import OptionParser signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing +try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib' +except KeyError: our_base = '/usr/share/autopkgtest/python'; +sys.path.insert(1, our_base) + +from Autopkgtest import * + #---------- global variables tmpdir = None # pathstring on host @@ -782,10 +788,6 @@ class Testbed: if len(pec) < 1: tb.bomb('too few results from print-execute-command') cmdl = map(urllib.unquote, pec[0].split(',')) - shellquote_re = regexp.compile('"') - def shellquote_arg(s): return "'" + shellquote_re.sub(r"'\''", s) + "'" - def shellquote_cmdl(l): return ' '.join(map(shellquote_arg,l)) - tb._debug('cmdl = %s' % (`cmdl`)) tb.ec_auxverbscript = TemporaryFile('satdep-auxverb') diff --git a/virt-subproc/adt-virt-chroot b/virt-subproc/adt-virt-chroot index b722153..7c1b0d9 100755 --- a/virt-subproc/adt-virt-chroot +++ b/virt-subproc/adt-virt-chroot @@ -27,9 +27,9 @@ import os import string from optparse import OptionParser -try: our_base = os.environ['AUTOPKGTEST_BASE'] -except KeyError: our_base = '/usr/share/autopkgtest'; -sys.path.insert(1, our_base+'/python') +try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib' +except KeyError: our_base = '/usr/share/autopkgtest/python'; +sys.path.insert(1, our_base) import VirtSubproc as vsp capabilities = [] diff --git a/virt-subproc/adt-virt-null b/virt-subproc/adt-virt-null index 10b6b86..761d13f 100755 --- a/virt-subproc/adt-virt-null +++ b/virt-subproc/adt-virt-null @@ -27,9 +27,9 @@ import os import string from optparse import OptionParser -try: our_base = os.environ['AUTOPKGTEST_BASE'] -except KeyError: our_base = '/usr/share/autopkgtest'; -sys.path.insert(1, our_base+'/python') +try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib' +except KeyError: our_base = '/usr/share/autopkgtest/python'; +sys.path.insert(1, our_base) import VirtSubproc as vsp capabilities = [] diff --git a/virt-subproc/adt-virt-schroot b/virt-subproc/adt-virt-schroot index cb7477d..d0473b6 100755 --- a/virt-subproc/adt-virt-schroot +++ b/virt-subproc/adt-virt-schroot @@ -30,9 +30,9 @@ import grp import pwd from optparse import OptionParser -try: our_base = os.environ['AUTOPKGTEST_BASE'] -except KeyError: our_base = '/usr/share/autopkgtest'; -sys.path.insert(1, our_base+'/python') +try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib' +except KeyError: our_base = '/usr/share/autopkgtest/python'; +sys.path.insert(1, our_base) import VirtSubproc as vsp capabilities = [] diff --git a/virt-subproc/adt-virt-xenlvm b/virt-subproc/adt-virt-xenlvm index e82a35b..7a7ced1 100755 --- a/virt-subproc/adt-virt-xenlvm +++ b/virt-subproc/adt-virt-xenlvm @@ -31,9 +31,9 @@ import fnmatch import signal from optparse import OptionParser -try: our_base = os.environ['AUTOPKGTEST_BASE'] -except KeyError: our_base = '/usr/share/autopkgtest'; -sys.path.insert(1, our_base+'/python') +try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib' +except KeyError: our_base = '/usr/share/autopkgtest/python'; +sys.path.insert(1, our_base) import VirtSubproc as vsp -- 2.30.2