Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit f7d33e4

Browse files
author
Ashley Chaloner
committed
Add stdout and stderr iterator functionality
1 parent 33705b4 commit f7d33e4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class Packer(object):
1313
"""
1414

1515
def __init__(self, packerfile, exc=None, only=None, vars=None,
16-
var_file=None, exec_path=DEFAULT_PACKER_PATH):
16+
var_file=None, exec_path=DEFAULT_PACKER_PATH, out_iter=None,
17+
err_iter=None):
1718
"""
1819
:param string packerfile: Path to Packer template file
1920
:param list exc: List of builders to exclude
@@ -31,7 +32,16 @@ def __init__(self, packerfile, exc=None, only=None, vars=None,
3132
self.only = self._validate_argtype(only or [], list)
3233
self.vars = self._validate_argtype(vars or {}, dict)
3334

35+
kwargs = dict()
36+
if out_iter is not None:
37+
kwargs["_out"] = out_iter
38+
kwargs["_out_bufsize"] = 1
39+
if err_iter is not None:
40+
kwargs["_err"] = err_iter
41+
kwargs["_out_bufsize"] = 1
42+
3443
self.packer = sh.Command(exec_path)
44+
self.packer = self.packer.bake(**kwargs)
3545

3646
def build(self, parallel=True, debug=False, force=False):
3747
"""Executes a `packer build`

0 commit comments

Comments
 (0)