From 1069ca43d60d8f4e3a1dc8e0d4a270ee202989a9 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 22 Jul 2019 19:34:08 +0100 Subject: [PATCH] [stream-refactor] port mitogen.buildah, added to master since work began --- mitogen/buildah.py | 44 +++++++++++++++++++++---------------------- tests/buildah_test.py | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/mitogen/buildah.py b/mitogen/buildah.py index eec415f3..f850234d 100644 --- a/mitogen/buildah.py +++ b/mitogen/buildah.py @@ -37,37 +37,37 @@ import mitogen.parent LOG = logging.getLogger(__name__) -class Stream(mitogen.parent.Stream): - child_is_immediate_subprocess = False - +class Options(mitogen.parent.Options): container = None username = None buildah_path = 'buildah' - # TODO: better way of capturing errors such as "No such container." - create_child_args = { - 'merge_stdio': True - } - - def construct(self, container=None, - buildah_path=None, username=None, - **kwargs): - assert container or image - super(Stream, self).construct(**kwargs) - if container: - self.container = container + def __init__(self, container=None, buildah_path=None, username=None, + **kwargs): + super(Options, self).__init__(**kwargs) + assert container is not None + self.container = container if buildah_path: self.buildah_path = buildah_path if username: self.username = username + +class Connection(mitogen.parent.Connection): + options_class = Options + child_is_immediate_subprocess = False + + # TODO: better way of capturing errors such as "No such container." + create_child_args = { + 'merge_stdio': True + } + def _get_name(self): - return u'buildah.' + self.container + return u'buildah.' + self.options.container def get_boot_command(self): - args = [] - if self.username: - args += ['--user=' + self.username] - bits = [self.buildah_path, 'run'] + args + ['--', self.container] - - return bits + super(Stream, self).get_boot_command() + args = [self.options.buildah_path, 'run'] + if self.options.username: + args += ['--user=' + self.options.username] + args += ['--', self.options.container] + return args + super(Connection, self).get_boot_command() diff --git a/tests/buildah_test.py b/tests/buildah_test.py index dad2534f..874205cd 100644 --- a/tests/buildah_test.py +++ b/tests/buildah_test.py @@ -21,7 +21,7 @@ class ConstructorTest(testlib.RouterMixin, testlib.TestCase): self.assertEquals(argv[1], 'run') self.assertEquals(argv[2], '--') self.assertEquals(argv[3], 'container_name') - self.assertEquals(argv[4], stream.python_path) + self.assertEquals(argv[4], stream.conn.options.python_path) if __name__ == '__main__':