def simulated_install(archive_file_or_directory, install_path, django_settings_module, package_cache_dir=None): """Simulate the install process. install_path is the directory under which we extract the archive. We also create a python virtualenv there and install all the required dependencies. """ if not os.path.isdir(install_path): raise Exception( "simulated_install: install_path %s does not exist" % install_path) if os.path.isdir(archive_file_or_directory): app_dir_path = os.path.join( install_path, os.path.basename(archive_file_or_directory)) shutil.copytree(archive_file_or_directory, app_dir_path) else: # we have an archive with create_handler(archive_file_or_directory) as h: common_dir = validate_archive_files(h.get_namelist()) h.extract(install_path) app_dir_path = os.path.join(install_path, common_dir) components_file = os.path.join(app_dir_path, COMPONENTS_FILENAME) if os.path.exists(components_file): with open(components_file, "rb") as cf: components_list = read_components_file(cf, components_file, None) else: components_list = [] undo_ops = generate_settings_file(app_dir_path, django_settings_module, components_list) virtualenv_path = os.path.join(install_path, "python") create_virtualenv(virtualenv_path, package_cache_dir=package_cache_dir) platform_reqs = write_platform_requirements_file(install_path, components_list) logger.info(">> Installing platform requirements into virtualenv") install_requirements( virtualenv_path, platform_reqs, package_cache_dir=package_cache_dir) app_reqs = os.path.join(app_dir_path, "requirements.txt") if os.path.exists(app_reqs): logger.info(">> Installing application requirements into virtualenv") install_requirements( virtualenv_path, app_reqs, package_cache_dir=package_cache_dir) else: logger.debug("No install requirements file at %s" % app_reqs) return (app_dir_path, undo_ops, os.path.join(virtualenv_path, "bin/python"))
def run(self): with create_handler(self.archive_file) as handler: (common_dir, django_config) = run_safe_validations(handler) if self.options.test_install_dir: install_dir = os.path.abspath(os.path.expanduser(self.options.test_install_dir)) os.makedirs(install_dir) else: install_dir = tempfile.mkdtemp(suffix="-engage") try: (app_dir_path, undo_ops, python_exe) = \ simulated_install(self.archive_file, install_dir, django_config.django_settings_module, package_cache_dir=self.options.package_cache_dir) results = run_installed_tests_as_subprocess(app_dir_path, django_config.django_settings_module, python_exe_path=python_exe, read_config_file=True) results.print_final_status_message(logger) return results.get_return_code() finally: if self.options.test_install_dir: shutil.rmtree(install_dir)
def run_safe_validations_on_archive(archive_file): """Wrapper on run_safe_validations that opens the archive, does the validations, and then closes it. """ with create_handler(archive_file) as handler: return run_safe_validations(handler)