From f2e1ab11af81bab56df5a20d119ed516e030bde5 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 23 Jul 2014 21:46:31 -0400 Subject: [PATCH] Add argument parsing --- dox/cmd.py | 32 +++++++++++++++++++++++++++++--- dox/locations.py | 11 ----------- dox/payloads.py | 6 +++++- dox/tests/test_payloads.py | 4 ++-- requirements.txt | 1 + 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/dox/cmd.py b/dox/cmd.py index d265165..0fa02c8 100644 --- a/dox/cmd.py +++ b/dox/cmd.py @@ -13,11 +13,37 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse + import dox.locations import dox.payloads +import dox.runner def main(): - location = dox.locations.Location() - payload = dox.payloads.Payload() - return location.run(payload) + parser = argparse.ArgumentParser(description='Run tests in docker.') + parser.add_argument(dest='extra_args', nargs='*', + help='args to append to command, or command to run' + ' if -c is given') + parser.add_argument('-i', '--image', dest='image', + help='Base image to use') + parser.add_argument('-c', '--command', dest='command', default=False, + action='store_true', + help='Treat arguments as the entire command to run') + parser.add_argument('-r', '--rebuild', dest='rebuild', default=False, + action='store_true', + help='Rebuild the test image') + parser.add_argument('--rebuild-all', dest='rebuild_all', default=False, + action='store_true', help='Rebuild all images') + args = parser.parse_args() + + image = args.image + if args.image is None: + image = dox.locations.get_image() + if args.command: + command = " ".join(args.extra_args) + else: + command = dox.payloads.Payload() + if args.extra_args: + command.append(args.extra_args) + return dox.runner.Runner(args).run(image, command) diff --git a/dox/locations.py b/dox/locations.py index 87e24be..ede7020 100644 --- a/dox/locations.py +++ b/dox/locations.py @@ -15,7 +15,6 @@ __all__ = [ 'get_image', - 'Location', ] import dox.config.dockerfile @@ -41,13 +40,3 @@ def get_image(): elif tox_ini.exists(): image = tox_ini.get_image(image) return image - - -class Location(object): - - def __init__(self): - self.image = get_image() - - def run(self, payload): - print("Going to run {0} in {1}".format( - payload, self.image)) diff --git a/dox/payloads.py b/dox/payloads.py index cbdfb1f..8abf4f5 100644 --- a/dox/payloads.py +++ b/dox/payloads.py @@ -41,8 +41,12 @@ class Payload(object): def __init__(self): self.payload = get_payload() + self.args = [] def __str__(self): if hasattr(self.payload, 'append'): return "\n".join(self.payload) - return self.payload + return self.payload + ' ' + ' '.join(self.args) + + def append(self, args): + self.args = args diff --git a/dox/tests/test_payloads.py b/dox/tests/test_payloads.py index f283b95..27ef060 100644 --- a/dox/tests/test_payloads.py +++ b/dox/tests/test_payloads.py @@ -38,8 +38,8 @@ class TestPayloads(base.TestCase): ('dox_yaml_ignore_others', dict( dox_yaml=True, tox_ini=True, travis_yaml=True, dox_value="testr run", tox_value="setup.py test", - travis_value="gem test" - , payload="testr run")), + travis_value="gem test", + payload="testr run")), ('tox_ini', dict( dox_yaml=False, tox_ini=True, travis_yaml=False, dox_value=None, tox_value="setup.py test", travis_value=None, diff --git a/requirements.txt b/requirements.txt index 1e4bae2..d0f397e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pbr>=0.5.21,<1.0 +argparse PyYAML sh