def build_repos(self): # TODO(eli): it really needs to be refactored # it was written right before the demo on the fly if utils.which(self.pre_build_hook_path): utils.exec_cmd(self.pre_build_hook_path) utils.create_dir(self.build_dir) utils.exec_cmd('rm -rf {0}'.format(os.path.join(self.build_dir, '*'))) utils.exec_cmd('cp -r {0} {1}'.format( os.path.join(self.plugin_path, '*'), self.build_dir)) releases_paths = {} for release in self.meta['releases']: releases_paths.setdefault(release['os'], []) releases_paths[release['os']].append( os.path.join(self.build_dir, release['repository_path'])) for repo_path in releases_paths.get('centos', []): repo_packages = os.path.join(repo_path, 'Packages') utils.create_dir(repo_packages) rpms = os.path.join(repo_path, '*.rpm') if glob.glob(rpms): utils.exec_cmd('cp {0} {1}'.format( os.path.join(repo_path, '*.rpm'), repo_packages)) utils.exec_cmd('createrepo -o {0} {1}'.format( repo_path, repo_packages)) for repo_path in releases_paths.get('ubuntu', []): utils.exec_cmd('dpkg-scanpackages {0} | gzip -c9 > {1}'.format( repo_path, os.path.join(repo_path, 'Packages.gz')))
def build_repos(self): # TODO(eli): it really needs to be refactored # it was written right before the demo on the fly if utils.which(self.pre_build_hook_path): utils.exec_cmd(self.pre_build_hook_path) utils.create_dir(self.build_dir) utils.exec_cmd('rm -rf {0}'.format(os.path.join(self.build_dir, '*'))) utils.exec_cmd( 'cp -r {0} {1}'.format( os.path.join(self.plugin_path, '*'), self.build_dir)) releases_paths = {} for release in self.meta['releases']: releases_paths.setdefault(release['os'], []) releases_paths[release['os']].append( os.path.join(self.build_dir, release['repository_path'])) for repo_path in releases_paths.get('centos', []): repo_packages = os.path.join(repo_path, 'Packages') utils.create_dir(repo_packages) rpms = os.path.join(repo_path, '*.rpm') if glob.glob(rpms): utils.exec_cmd('cp {0} {1}'.format( os.path.join(repo_path, '*.rpm'), repo_packages)) utils.exec_cmd('createrepo -o {0} {1}'.format(repo_path, repo_packages)) for repo_path in releases_paths.get('ubuntu', []): utils.exec_cmd( 'dpkg-scanpackages {0} | gzip -c9 > {1}'.format( repo_path, os.path.join(repo_path, 'Packages.gz')))
def _check_requirements(self): not_found = filter(lambda r: not utils.which(r), self.requires) if not_found: raise errors.FuelCannotFindCommandError( 'Cannot find commands "{0}", ' 'install required commands and try again'.format( ', '.join(not_found)))
def check(self): not_found = filter(lambda r: not utils.which(r), self.requires) if not_found: raise errors.FuelCannotFindCommandError( 'Cannot find commands "{0}", ' 'install required commands and try again'.format( ','.join(not_found)))
def run_pre_build_hook(self): if utils.which(self.pre_build_hook_path): utils.exec_cmd(self.pre_build_hook_path)
def run_pre_build_hook(self): if utils.which(join_path(self.plugin_path, self.pre_build_hook_cmd)): utils.exec_cmd(self.pre_build_hook_cmd, self.plugin_path)
def test_which_returns_none(self, _): with patch.dict('os.environ', {'PATH': '/usr/bin:/bin'}): self.assertIsNone(utils.which('some_exec'))
def test_which_returns_if_exec_in_env_path(self, _): # some_exec is in /bin directory path = 'some_exec' with patch.dict('os.environ', {'PATH': '/usr/bin:/bin'}): self.assertEqual(utils.which(path), '/bin/some_exec')
def test_which_returns_for_absolute_path_exec(self, _, os_mock): path = '/usr/bin/some_exec' os_mock.path.split.return_value = ('/usr/bin/', 'some_exec') self.assertEqual(utils.which(path), path)