diff --git a/.gitignore b/.gitignore index 2c62ee1..fb44163 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ docs/_build/ *COMMIT_MSG .qbcache/ + +.idea/ + diff --git a/agent_packager/cli.py b/agent_packager/cli.py index a9361c8..12c92c2 100644 --- a/agent_packager/cli.py +++ b/agent_packager/cli.py @@ -3,7 +3,7 @@ """Script to run Cloudify's Agent Packager via command line Usage: - cfy-ap [--config= --force --dryrun --no-validation -v] + cfy-ap [--config= --force --dryrun --no-validation -v --env=] cfy-ap --version Options: @@ -12,6 +12,7 @@ -f --force Forces deletion and creation of venv and tar file. -d --dryrun Prints out the modules to be installed without actually installing them. -n --no-validation Does not validate that all modules were installed correctly. + -e --env= Virtualenv to use (defaults to a temporary directory) -v --verbose verbose level logging --version Display current version """ @@ -47,7 +48,8 @@ def _run(test_options=None): force=options.get('--force'), dryrun=options.get('--dryrun'), no_validate=options.get('--no-validation'), - verbose=options.get('--verbose') + verbose=options.get('--verbose'), + virtualenv=options.get('--env') ) def main(): diff --git a/agent_packager/packager.py b/agent_packager/packager.py index 54209f2..16daa64 100644 --- a/agent_packager/packager.py +++ b/agent_packager/packager.py @@ -6,13 +6,13 @@ import shutil import os import sys +import tempfile import utils import codes DEFAULT_CONFIG_FILE = 'config.yaml' DEFAULT_OUTPUT_TAR_PATH = '{0}-{1}-agent.tar.gz' -DEFAULT_VENV_PATH = 'cloudify/env' PREINSTALL_MODULES = [ 'setuptools==36.8.0' @@ -62,6 +62,7 @@ def _import_config(config_file=DEFAULT_CONFIG_FILE): :param string config_file: path to config file """ + config_file = os.path.expanduser(config_file) lgr.debug('Importing config: {0}...'.format(config_file)) try: with open(config_file, 'r') as c: @@ -332,7 +333,7 @@ def _name_archive(distro, release, version, milestone, build): def create(config=None, config_file=None, force=False, dryrun=False, - no_validate=False, verbose=True): + no_validate=False, verbose=True, virtualenv=None): """Creates an agent package (tar.gz) This will try to identify the distribution of the host you're running on. @@ -340,8 +341,6 @@ def create(config=None, config_file=None, force=False, dryrun=False, `distribution` (e.g. Ubuntu) config object in the config.yaml. The same goes for the `release` (e.g. Trusty). - A virtualenv will be created under cloudify/env. - The order of the modules' installation is as follows: cloudify-rest-service cloudify-plugins-common @@ -385,7 +384,7 @@ def create(config=None, config_file=None, force=False, dryrun=False, '({0})'.format(ex.message)) sys.exit(codes.errors['could_not_identify_distribution']) python = config.get('python_path', '/usr/bin/python') - venv = DEFAULT_VENV_PATH + venv = virtualenv or tempfile.mkdtemp(prefix='agent-packager') venv_already_exists = utils.is_virtualenv(venv) destination_tar = config.get('output_tar', _name_archive(**name_params))