Example #1
0
def create_virtualenv(desired_python_dir, logger, package_dir,
                      base_python_exe=None,
                      never_download=False):
    virtualenv_search_dirs = get_python_search_paths()
    python_exe = find_python_executable(logger, explicit_path=base_python_exe)
    # we start our virtualenv executable search at the same place as where we have
    # the python executable. Then, we check a bunch of well-known places to stick
    # virtualenv
    virtualenv_search_dirs = [os.path.dirname(python_exe)] + get_python_search_paths()
    virtualenv = find_executable("virtualenv", virtualenv_search_dirs, logger)
    version = get_virtualenv_version(virtualenv)
    if compare_versions("1.6.1", version)>=0:
        # --never-download and --extra-search-dir were added in 1.6.1
        has_options = True
    else:
        has_options = False
    if compare_versions("1.7", version)>=0:
        site_packages_opt = True
    else:
        site_packages_opt = False
        
    if not os.path.exists(desired_python_dir):
        os.makedirs(desired_python_dir)
    opts = ["--python=%s" % python_exe,]
    if site_packages_opt:
        opts.append("--system-site-packages")
    if has_options:
        opts.append("--extra-search-dir=%s" % package_dir)
        if never_download:
            opts.append("--never-download")
    elif never_download:
        raise Exception("--never-download option requires virtualenv 1.6.1 or later")
    # JF 6/7/2011: removed --no-site-packages command line option, as it makes
    # it hard to use pre-built packages installed by the package manager,
    # like py-mysql
    cmd = "%s %s %s" % (virtualenv, ' '.join(opts), desired_python_dir)
    logger.info('create virtualenv running command: %s' % cmd)
    rc = system(cmd, logger, cwd=desired_python_dir)
    if rc != 0:
        raise Exception("Execution of '%s' failed, rc was %d" % (cmd, rc))
Example #2
0
def setup_slave_host(resource, master_deployment_home,
                     password_file, password_salt_file):
    bootstrap_script = os.path.abspath(os.path.join(master_deployment_home,
                                                    "engage/bootstrap.py"))
    assert os.path.exists(bootstrap_script), "Can't find bootstrap script %s" % \
                                             bootstrap_script
    python_exe = find_python_executable(logger)
    
    dh = resource["config_port"]["genforma_home"]
    logger.info("Bootstrapping slave node %s" % resource["id"])
    deployed_nodes_root = os.path.dirname(dh)
    if not os.path.exists(deployed_nodes_root):
        os.makedirs(deployed_nodes_root)
    try:
        rc = procutils.run_and_log_program([python_exe, bootstrap_script, "-p",
                                            python_exe, dh], None, logger,
                                            cwd=os.path.dirname(bootstrap_script))
    except Exception, e:
        logger.exception("Error in slave bootstrap for %s: %s" % (e, resource["id"]))
        raise UserError(errors[ERR_SLAVE_BOOTSTRAP],
                        msg_args={"host":resource["id"]},
                        developer_msg="deployment home was %s" % dh)