def setup(): require( "directory", "venv_directory", "www_directory", "package_name", "repository", "project_name") # 1. clone project utils.clone_project() # 2. create virtualenv utils.create_virtualenv() # 3. install requirements utils.install_requirements() # 4. configure supervisor env.supervisor = { "command": supervisor.tornado_command() } supervisor.setup() supervisor.reload() # 5. configure nginx nginx.setup() nginx.reload()
def run_all(): config = loadConfig('settings.conf') LOCAL_DIRECTORY = config.get('ATTACHMENTS', 'LOCAL_DIRECTORY') EXECUTABLE = config.get('EXECUTION', 'EXECUTABLE') solutions = os.listdir(LOCAL_DIRECTORY) results = [] for solution in solutions: print('Running {}'.format(term.blue(solution))) path = os.path.join(LOCAL_DIRECTORY, solution) try: check_bandit(path) venv_path = create_virtualenv(path) install_requirements(venv_path, path) start_time = datetime.now() for test in TEST_TRIANGLES: failure_message = check_triangle( path, python_executable=os.path.join(venv_path, 'bin', 'python3'), executable=EXECUTABLE, **test) if failure_message: result = Result(solution, failure_reason=failure_message) results.append(result) break else: finish_time = datetime.now() result = Result(solution, time=finish_time - start_time) results.append(result) except StopExecution: raise except Exception as e: print(term.red('Got exception running {}'.format(solution))) print(term.red(str(e))) failure_message = str(e) if hasattr(e, 'stdout') and e.stdout: print(term.red(e.stdout)) failure_message = failure_message + '\nFrom stdout:\n{stdout}'.format( stdout=e.stdout) result = Result(solution, failure_reason=failure_message) results.append(result) print() return results
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 test_requirements_no_proxy(self): os.environ['PIP_PROXY'] = '' expected = None actual = install_requirements('test_venv', 'test_dir') assert expected == actual self.mock_walk.assert_called_once_with('test_dir') self.mock_run.assert_called_once_with( ['test_venv/bin/pip', 'install', '-r', 'root/requirements.txt'], check=False)
def test_no_requirements_file(self): self.mock_walk.return_value = [( 'root', ['dir1', 'dir2'], ['test1.py', 'main.py', 'test2.py'], )] expected = None actual = install_requirements('test_venv', 'test_dir') assert expected == actual self.mock_walk.assert_called_once_with('test_dir') assert not self.mock_run.called