Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
v0.3.2 - added archive_type=tar support
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Mar 19, 2014
1 parent 01ff6ac commit bc9180b
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/battleschool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.3.1'
__version__ = '0.3.2'
__author__ = 'Spencer Gibb'
35 changes: 32 additions & 3 deletions share/library/mac_pkg
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ class ZipArchive(Archive):
shutil.rmtree(self.target_dir)


class TarArchive(Archive):

def __init__(self, module, pkg):
super(TarArchive, self).__init__(module, pkg)
self.tar_path = module.get_bin_path('tar', True, ['/usr/bin'])
self.tar_opts = self.params['tar_opts']
#TODO: override target_dir
self.target_dir = tempfile.mkdtemp(suffix='-tar-extract', prefix='mac_pkg-')

def open(self):
#self.module.exit_json(changed=False,msg="tar_path %s, tar_opts %s, pkg_path %s, target_dir %s, archive_path %s"
# % (self.tar_path, self.tar_opts, self.pkg_path(), self.target_dir,
# self.params['archive_path']))
rc, out, err = self.module.run_command("%s %s %s -C %s" % (self.tar_path, self.tar_opts, self.pkg_path(),
self.target_dir))
if rc > 0:
self.module.fail_json(msg="failed to extract tar %s: %s\n\t%s" % (self.pkg_path(), out, err))
self._pkg_path = "%s/%s" % (self.target_dir, self.params['archive_path'])

def close(self):
shutil.rmtree(self.target_dir)


class DmgArchive(Archive):

def __init__(self, module, pkg):
Expand Down Expand Up @@ -374,12 +397,17 @@ class AppPackage(Package):
super(AppPackage, self).__init__(module)
if exists(self.params, 'creates'):
self._app_creates = self.params['creates']
if not self._app_creates.startswith("/"):
#not an absolute path, prepend /Applications
self.set_applications_path('creates')
elif exists(self.params, 'archive_path'):
# TODO: parameterize app destination
self._app_creates = '/Applications/%s' % self.params['archive_path']
self.set_applications_path('archive_path')
else:
self.module.fail_json(msg="for pkg_type=app one of app_creates or archive_path must not be empty")

def set_applications_path(self, param_name):
self._app_creates = '/Applications/%s' % self.params[param_name]

def install(self, pkg_path):
shutil.copytree(pkg_path, self._app_creates)

Expand Down Expand Up @@ -492,12 +520,13 @@ def main():
module = AnsibleModule(
argument_spec=dict(
state=dict(default="present", choices=["present", "installed"]),
archive_type=dict(default="none", choices=["zip", "dmg", "none"]),
archive_type=dict(default="none", choices=["zip", "dmg", "tar", "none"]),
src=dict(aliases=["source"], required=False),
url=dict(aliases=[], required=False),
dest=dict(aliases=["destination"], required=False),
force=dict(default='no', type='bool'),
curl_opts=dict(aliases=[], required=False),
tar_opts=dict(aliases=[], default="xf", required=False),
archive_path=dict(required=False),
pkg_type=dict(default="pkg", choices=["pkg", "app", "script"]),
pkg_name=dict(required=False),
Expand Down
2 changes: 1 addition & 1 deletion test/test_app_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ MODULE_PARAMS="$MODULE_PARAMS pkg_type=app"
MODULE_PARAMS="$MODULE_PARAMS archive_type=zip"
MODULE_PARAMS="$MODULE_PARAMS archive_path='Alfred 2.app'"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
8 changes: 8 additions & 0 deletions test/test_app_tar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MODULE_PARAMS="pkg_type=app"
MODULE_PARAMS="$MODULE_PARAMS url=https://github.com/b4winckler/macvim/releases/download/snapshot-72/MacVim-snapshot-72-Mavericks.tbz"
MODULE_PARAMS="$MODULE_PARAMS archive_type=tar"
MODULE_PARAMS="$MODULE_PARAMS archive_path=MacVim-snapshot-72/MacVim.app"
MODULE_PARAMS="$MODULE_PARAMS creates=MacVim.app"

#echo $MODULE_PARAMS
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ MODULE_PARAMS="$MODULE_PARAMS archive_type=dmg"
MODULE_PARAMS="$MODULE_PARAMS src=/tmp/jdk7.dmg"
MODULE_PARAMS="$MODULE_PARAMS archive_path='JDK 7 Update 25.pkg'"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_file_eula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ MODULE_PARAMS="$MODULE_PARAMS src=/tmp/truecrypt.dmg"
MODULE_PARAMS="$MODULE_PARAMS archive_path='TrueCrypt 7.1a.mpkg'"
MODULE_PARAMS="$MODULE_PARAMS dmg_license=yes"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ MODULE_PARAMS="$MODULE_PARAMS curl_opts='--cookie gpw_e24=http%3A%2F%2Fwww.oracl
MODULE_PARAMS="$MODULE_PARAMS archive_type=dmg"
MODULE_PARAMS="$MODULE_PARAMS archive_path='JDK 7 Update 25.pkg'"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_macports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ MODULE_PARAMS="$MODULE_PARAMS pkg_version=0.2.2.0.0.0.0.0.0x"
MODULE_PARAMS="$MODULE_PARAMS force=true"
MODULE_PARAMS="$MODULE_PARAMS url=https://distfiles.macports.org/MacPorts/MacPorts-2.2.0-10.8-MountainLion.pkg"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_vagrant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ MODULE_PARAMS="$MODULE_PARAMS archive_path=Vagrant.pkg"
#MODULE_PARAMS="$MODULE_PARAMS force=true"
MODULE_PARAMS="$MODULE_PARAMS url=https://dl.bintray.com/mitchellh/vagrant/vagrant_1.5.0.dmg"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ MODULE_PARAMS="$MODULE_PARAMS archive_type=zip"
MODULE_PARAMS="$MODULE_PARAMS archive_path=MacPorts-2.1.3-10.8-MountainLion.pkg"

#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
2 changes: 1 addition & 1 deletion test/test_pkg_brew.sh → test/test_script_brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ MODULE_PARAMS="$MODULE_PARAMS script_prefix='echo | '"
MODULE_PARAMS="$MODULE_PARAMS script_exe=ruby"
MODULE_PARAMS="$MODULE_PARAMS url=https://raw.github.com/mxcl/homebrew/go"
#echo $MODULE_PARAMS
~/workspace/32degrees/ansible/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
$ANSIBLE_SRC_PATH/hacking/test-module -m share/library/mac_pkg -a "$MODULE_PARAMS"
6 changes: 5 additions & 1 deletion test/testconfig/playbooks/another_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
debug: msg="in playbooks/another_playbook.yml"

- name: print os version
debug: msg="mac_major_minor_version = {{mac_major_minor_version }}, ansible_distribution = {{ansible_distribution}}, ansible_distribution_version = {{ansible_distribution_version}}"
debug: msg="mac_major_minor_version = {{mac_major_minor_version}}, ansible_distribution = {{ansible_distribution}}, ansible_distribution_version = {{ansible_distribution_version}}"

- name: print mavericks
debug: msg="Mavericks"
when: mac_major_minor_version == "10.9"

- name: print mountain lion
debug: msg="Mountain Lion"
Expand Down

0 comments on commit bc9180b

Please sign in to comment.