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

Commit a14f2be

Browse files
committed
starting to handle errors correclty
1 parent 0d8d09e commit a14f2be

3 files changed

Lines changed: 48 additions & 11 deletions

File tree

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,36 @@ python-packer
66
* Version [![PypI](http://img.shields.io/pypi/v/python-packer.svg)](http://img.shields.io/pypi/v/python-packer.svg)
77

88

9-
A Python interface for executing [packer.io](http://www.packer.io)
9+
A Python client for [packer.io](http://www.packer.io)
10+
11+
## Installation
12+
13+
You must have Packer installed prior to using this client (DUH!)
14+
15+
```shell
16+
pip install python-packer
17+
# or, for dev:
18+
pip install https://github.com/nir0s/python-packer/archive/master.tar.gz
19+
```
20+
21+
## Usage Example
22+
23+
### Executing a build
24+
25+
```python
26+
import packer
27+
28+
packerfile = 'packer/tests/resources/packerfile.json'
29+
packer_exec_path = '/usr/bin/packer'
30+
exc = []
31+
only = []
32+
vars = {"variable1": "y", "variable2": "value"}
33+
vars_file = 'path/to/vars/file'
34+
35+
p = packer.Packer(packerfile, exc=exc, only=only, vars=vars,
36+
vars_file=vars_file, exec_path=packer_exec_path)
37+
# print(p.validate(syntax_only=True))
38+
print(p.build())
39+
result = p.inspect()
40+
print result.parsed_output
41+
```

packer/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def validate(self, syntax_only=False):
6262
validator = validator.bake('-syntax-only')
6363
validator = self._append_base_arguments(validator)
6464
validator = validator.bake(self.packerfile)
65-
return validator()
65+
try:
66+
validated = validator()
67+
except:
68+
print 'HASDHASD'
69+
validated.succeeded = True if validated.exit_code == 0 else False
70+
validated.failed = not validated.succeeded
71+
return validated
6672

6773
def build(self, parallel=True, debug=False, force=False):
6874
"""Executes a Packer build (`packer build`)
@@ -108,9 +114,10 @@ def inspect(self):
108114
"""
109115
inspector = self.packer.inspect
110116
inspector = inspector.bake('-machine-readable', self.packerfile)
111-
result = inspector()
112-
result.parsed_output = self._parse_inspection_output(result.stdout)
113-
return result
117+
inspected = inspector()
118+
inspected.parsed_output = self._parse_inspection_output(
119+
inspected.stdout)
120+
return inspected
114121

115122
def _parse_inspection_output(self, output):
116123
"""Parses the machine-readable output `packer inspect` provides.

tester.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import packer
2-
import os
3-
4-
packerfile = os.path.expanduser('packer/tests/resources/packerfile.json') # NOQA
52

3+
packerfile = 'packer/tests/resources/packerfile.json'
64
# exc = ['z', 't']
75
exc = []
86
# only = ['x', 'y']
@@ -14,7 +12,7 @@
1412
p = packer.Packer(packerfile, exc=exc, only=only, vars=vars)
1513
# print(p.version())
1614

17-
# print(p.validate(syntax_only=True))
15+
print(p.validate(syntax_only=False))
1816
# print(p.build())
19-
result = p.inspect()
20-
print result.parsed_output
17+
# result = p.inspect()
18+
# print result.parsed_output

0 commit comments

Comments
 (0)