Skip to content

Remove installer #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The interface has been developed vs. Packer v0.7.5.

## Installation

You must have Packer installed prior to using this client though as installer class is provided to install packer for you.
You must have Packer installed prior to using this client.

```shell
pip install python-packer
Expand Down Expand Up @@ -153,19 +153,6 @@ p = packer.Packer(packerfile, ...)
print(p.version())
```

### PackerInstaller.install()

This installs packer to `packer_path` using the `installer_path` and verifies that the installation was successful.

```python

packer_path = '/usr/bin/'
installer_path = 'Downloads/packer_0.7.5_linux_amd64.zip'

p = packer.Installer(packer_path, installer_path)
p.install()
```

## Shell Interaction

The [sh](http://amoffat.github.io/sh/) Python module is used to execute Packer.
Expand Down
52 changes: 20 additions & 32 deletions packer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import sh
import os
import json
import os
import zipfile

import sh

DEFAULT_PACKER_PATH = 'packer'


class Packer(object):
"""A packer client
"""

def __init__(self, packerfile, exc=None, only=None, vars=None,
var_file=None, exec_path=DEFAULT_PACKER_PATH, out_iter=None,
def __init__(self,
packerfile,
exc=None,
only=None,
vars=None,
var_file=None,
exec_path=DEFAULT_PACKER_PATH,
out_iter=None,
err_iter=None):
"""
:param string packerfile: Path to Packer template file
Expand All @@ -24,8 +31,8 @@ def __init__(self, packerfile, exc=None, only=None, vars=None,
self.packerfile = self._validate_argtype(packerfile, str)
self.var_file = var_file
if not os.path.isfile(self.packerfile):
raise OSError('packerfile not found at path: {0}'.format(
self.packerfile))
raise OSError(
'packerfile not found at path: {0}'.format(self.packerfile))
self.exc = self._validate_argtype(exc or [], list)
self.only = self._validate_argtype(only or [], list)
self.vars = self._validate_argtype(vars or {}, dict)
Expand All @@ -41,7 +48,10 @@ def __init__(self, packerfile, exc=None, only=None, vars=None,
self.packer = sh.Command(exec_path)
self.packer = self.packer.bake(**kwargs)

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

Expand Down Expand Up @@ -115,7 +125,7 @@ def inspect(self, mrf=True):
result = self.packer_cmd()
if mrf:
result.parsed_output = self._parse_inspection_output(
result.stdout.decode())
result.stdout.decode())
else:
result.parsed_output = None
return result
Expand Down Expand Up @@ -176,8 +186,8 @@ def _add_opt(self, option):

def _validate_argtype(self, arg, argtype):
if not isinstance(arg, argtype):
raise PackerException('{0} argument must be of type {1}'.format(
arg, argtype))
raise PackerException(
'{0} argument must be of type {1}'.format(arg, argtype))
return arg

def _append_base_arguments(self):
Expand Down Expand Up @@ -227,28 +237,6 @@ def _parse_inspection_output(self, output):
return parts


class Installer(object):
def __init__(self, packer_path, installer_path):
self.packer_path = packer_path
self.installer_path = installer_path

def install(self):
with open(self.installer_path, 'rb') as f:
zip = zipfile.ZipFile(f)
for path in zip.namelist():
zip.extract(path, self.packer_path)
exec_path = os.path.join(self.packer_path, 'packer')
if not self._verify_packer_installed(exec_path):
raise PackerException('packer installation failed. '
'Executable could not be found under: '
'{0}'.format(exec_path))
else:
return exec_path

def _verify_packer_installed(self, packer_path):
return os.path.isfile(packer_path)


class ValidationObject():
pass

Expand Down