3838]
3939
4040DEFAULT_CLOUDIFY_AGENT_URL = 'https://github.com/cloudify-cosmo/cloudify-agent/archive/{0}.tar.gz' # NOQA
41+ VENV_ROOT = ['cloudify' , 'env' ]
4142
4243lgr = logger .init ()
4344verbose_output = False
@@ -77,30 +78,6 @@ def _import_config(config_file=DEFAULT_CONFIG_FILE):
7778 sys .exit (codes .errors ['invalid_yaml_file' ])
7879
7980
80- def _make_venv (venv , python , force ):
81- """Handles the virtualenv.
82-
83- removes the virtualenv if required, else, notifies
84- that it already exists. If it doesn't exist, it will be
85- created.
86- :param string venv: path of virtualenv to install in.
87- :param string python: python binary path to use.
88- :param bool force: whether to force creation or not if it
89- already exists.
90- """
91- if utils .is_virtualenv (venv ):
92- if force :
93- lgr .info ('Installing within existing virtualenv: {0}' .format (venv ))
94- else :
95- lgr .error ('Virtualenv already exists at {0}. '
96- 'You can use the -f flag to install within the '
97- 'existing virtualenv.' .format (venv ))
98- sys .exit (codes .errors ['virtualenv_already_exists' ])
99- else :
100- lgr .debug ('Creating virtualenv: {0}' .format (venv ))
101- utils .make_virtualenv (venv , python )
102-
103-
10481def _handle_output_file (destination_tar , force ):
10582 """Handles the output tar.
10683
@@ -333,7 +310,7 @@ def _name_archive(distro, release, version, milestone, build):
333310
334311
335312def create (config = None , config_file = None , force = False , dryrun = False ,
336- no_validate = False , verbose = True , virtualenv = None ):
313+ no_validate = False , verbose = True ):
337314 """Creates an agent package (tar.gz)
338315
339316 This will try to identify the distribution of the host you're running on.
@@ -384,8 +361,8 @@ def create(config=None, config_file=None, force=False, dryrun=False,
384361 '({0})' .format (ex .message ))
385362 sys .exit (codes .errors ['could_not_identify_distribution' ])
386363 python = config .get ('python_path' , '/usr/bin/python' )
387- venv = virtualenv or tempfile .mkdtemp (prefix = 'agent-packager' )
388- venv_already_exists = utils . is_virtualenv ( venv )
364+ work_root = tempfile .mkdtemp (prefix = 'agent-packager' )
365+ venv = os . path . join ( work_root , * VENV_ROOT )
389366 destination_tar = config .get ('output_tar' , _name_archive (** name_params ))
390367
391368 lgr .debug ('Distibution is: {0}' .format (name_params ['distro' ]))
@@ -394,7 +371,8 @@ def create(config=None, config_file=None, force=False, dryrun=False,
394371 lgr .debug ('Destination tarfile is: {0}' .format (destination_tar ))
395372
396373 if not dryrun :
397- _make_venv (venv , python , force )
374+ lgr .debug ('Creating virtualenv: {0}' .format (venv ))
375+ utils .make_virtualenv (venv , python )
398376
399377 _handle_output_file (destination_tar , force )
400378
@@ -413,19 +391,18 @@ def create(config=None, config_file=None, force=False, dryrun=False,
413391 _uninstall_excluded (modules , venv )
414392 if not no_validate :
415393 _validate (final_set , venv )
416- utils .tar (venv , destination_tar )
394+ utils .tar (work_root , os . path . join ( * VENV_ROOT ) , destination_tar )
417395
418396 lgr .info ('The following modules and plugins were installed '
419397 'in the agent:\n {0}' .format (utils .get_installed (venv )))
420398
421399 # if keep_virtualenv is explicitly specified to be false, the virtualenv
422400 # will not be deleted.
423- # if keep_virtualenv is not in the config but the virtualenv already
424- # existed, it will not be deleted.
425- if ('keep_virtualenv' in config and not config ['keep_virtualenv' ]) \
426- or ('keep_virtualenv' not in config and not venv_already_exists ):
427- lgr .info ('Removing origin virtualenv...' )
428- shutil .rmtree (venv )
401+ if not config .get ('keep_virtualenv' , False ):
402+ lgr .info ('Removing virtualenv...' )
403+ shutil .rmtree (work_root )
404+ else :
405+ lgr .info ('Virtualenv kept: {0}' .format (work_root ))
429406
430407 # duh!
431408 lgr .info ('Process complete!' )
0 commit comments