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

Commit e706e4c

Browse files
committed
added packer installer
1 parent 271dd0b commit e706e4c

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CHANGELOG

Whitespace-only changes.

packer/__init__.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import sh
22
import os
33
import json
4+
import zipfile
45

5-
__version__ = '0.0.1'
6+
__version__ = '0.0.2'
67

78
DEFAULT_PACKER_PATH = 'packer'
89

@@ -203,9 +204,26 @@ def _parse_inspection_output(self, output):
203204
return parts
204205

205206

206-
# class Install():
207-
# def __init__(self):
208-
# self.installer_path = os.environ['PACKER_INSTALLER_PATH']
207+
class Install():
208+
def __init__(self, packer_path, installer_path):
209+
self.packer_path = packer_path
210+
self.installer_path = installer_path
211+
212+
def install(self):
213+
with open(self.installer_path, 'rb') as f:
214+
zip = zipfile.ZipFile(f)
215+
for path in zip.namelist():
216+
zip.extract(path, self.packer_path)
217+
exec_path = os.path.join(self.packer_path, 'packer')
218+
if not self._verify(exec_path):
219+
raise PackerException('packer installation failed. '
220+
'Executable could not be found under: '
221+
'{0}'.format(exec_path))
222+
else:
223+
return exec_path
224+
225+
def _verify(self, packer):
226+
return True if os.path.isfile(packer) else False
209227

210228

211229
class ValidationObject():
@@ -214,3 +232,6 @@ class ValidationObject():
214232

215233
class PackerException(Exception):
216234
pass
235+
236+
237+
# 0587508070

tester.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
vars = {}
1010
vars_file = '/x'
1111

12-
p = packer.Packer(packerfile, exc=exc, only=only, vars=vars)
12+
p = packer.Install('packer_executables/', 'packer_0.7.5_linux_amd64.zip')
13+
# If we installed packer using the provided installer, it will return
14+
# packer's executable path. We can use it below:
15+
# packer_exec = p.install()
16+
packer_exec = 'packer'
17+
p = packer.Packer(packerfile, exc=exc, only=only, vars=vars,
18+
exec_path=packer_exec)
1319
# print(p.version())
1420
# validation = p.validate(syntax_only=True)
1521
# print(validation.succeeded)

0 commit comments

Comments
 (0)