def _checkout(self, branch): self.cmd = 'git checkout "%s"' % branch errc, out, err = run(self.cmd) if errc: raise RuntimeError("git checkout failed: %s" % err or out) self.cmd = 'git pull' errc, out, err = run(self.cmd) if errc: raise RuntimeError("git pull failed: %s" % err or out)
def _get_version(self, pkg_name, branch): ver = {} cmd = "%s latest-pkg \"%s\" \"%s\"" % (self.command, branch, pkg_name) ver['cmd'] = cmd errc, out, err = run(cmd) if errc: ver['error'] = err or out return ver lines = out.strip().split("\n")[2:] if not lines: ver['error'] = 'No results. Bad package name?' return ver if len(lines) > 1: ver['error'] = \ "`%s latest-pkg` returned more than one result. WAT?" \ % self.command return ver line = lines[0] cols = re.split(' +', line) if len(cols) == 1: ver['error'] = '%s output parsing failed: %s' % (self.command, line) return ver nvr = parse_nvr(cols[0], pkg_name) ver.update(nvr) return ver
def _get_version(self, pkg_name, branch): ver = {} cmd = 'bodhi -L %s' % pkg_name ver['cmd'] = cmd if pkg_name not in self.cache: errc, out, err = run(cmd) if errc: ver['error'] = err or out return ver if not out: ver['error'] = 'No version returned.' return ver pkg_vers = {} for line in out.rstrip().split('\n'): line = line.strip() br, nvr = re.split(' +', line) pkg_vers[br] = parse_nvr(nvr, pkg_name) self.cache[pkg_name] = pkg_vers pkg_vers = self.cache[pkg_name] if branch not in pkg_vers: ver['error'] = "Tag not found." return ver ver.update(pkg_vers[branch]) testing_branch = "%s-testing" % branch if testing_branch in pkg_vers: ver['next'] = pkg_vers[testing_branch] ver['next']['cmd'] = cmd return ver
def _get_version(self, pkg_name, branch): hsh = hashlib.md5() hsh.update(self.repo_base) hsh.update(branch) repoid = "verw_%s" % hsh.hexdigest() ver = {} cmd = ("repoquery " "--repofrompath=%(repoid)s,%(repo_base)s/%(branch)s/ " "--repoid=%(repoid)s -q %(pkg_name)s" % { 'repo_base': self.repo_base, 'branch': branch, 'pkg_name': pkg_name, 'repoid': repoid}) ver['cmd'] = cmd errc, out, err = run(cmd) if errc: ver['error'] = err or out return ver if not out: ver['error'] = "No version found." return ver lines = out.strip().split("\n") if len(lines) > 1: # TODO: Select best version. msg = "Got more than 1 version using repoquery... FIXME!" raise NotImplementedError(msg) nvr = parse_nvr(lines[0], pkg_name) ver.update(nvr) return ver
def _koji_get_version(self, pkg_name, branch): ver = {} cmd = "%s latest-pkg \"%s\" \"%s\"" % (self.command, branch, pkg_name) ver['cmd'] = cmd errc, out, err = run(cmd) if errc: ver['error'] = err or out return ver lines = out.strip().split("\n")[2:] if not lines: ver['error'] = 'No results. Bad package name?' return ver if len(lines) > 1: ver['error'] = \ "`%s latest-pkg` returned more than one result. WAT?" \ % self.command return ver line = lines[0] cols = re.split(' +', line) if len(cols) == 1: ver['error'] = '%s output parsing failed: %s' % (self.command, line) return ver nvr = parse_nvr(cols[0], pkg_name) ver.update(nvr) return ver
def _clone_repo(self, pkg_name): os.chdir(self.repo_base_dir) repo_url = '%s%s.git' % (self.repo_base, pkg_name) self.cmd = 'git clone "%s"' % repo_url errc, out, err = run(self.cmd) if errc: raise RuntimeError("git clone failed: %s" % err)
def _prepare_repo(self, pkg_name): """ Clone/fetch repo and chdir into it. """ repo_dir = "%s/%s" % (self.repo_base_dir, pkg_name) if os.path.isdir(repo_dir): os.chdir(repo_dir) self.cmd = 'git fetch --all' errc, out, err = run(self.cmd) if errc: return {'error': 'git fetch failed: %s' % (err or out), 'cmd': self.cmd} else: self._clone_repo(pkg_name) os.chdir(repo_dir)
class GitFetcher(VersionFetcher): name = 'git' def __init__(self, **kwargs): VersionFetcher.__init__(self, **kwargs) if 'options' not in kwargs: raise ValueError("options argument not supplied to git fetcher. " "'repo_base' option is required.") if 'paths' not in kwargs: raise ValueError("paths argument not supplied to git fetcher.") options = kwargs['options'] if not options or 'repo_base' not in options: raise ValueError("'repo_base' option not supplied to git fetcher.") if not options or 'id' not in options: raise RuntimeError("'id' option not supplied to git fetcher. " "verwatch is supposed to supply this internally.") self.paths = kwargs['paths'] self.repo_base = options['repo_base'] # 'id' is supplied by verwatch self.repo_base_dir = "%s/%s/%s" % (self.paths.cache_dir, self.name, options['id']) if not os.path.isdir(self.repo_base_dir): os.makedirs(self.repo_base_dir) self.cmd = None def _clone_repo(self, pkg_name): os.chdir(self.repo_base_dir) repo_url = '%s%s.git' % (self.repo_base, pkg_name) self.cmd = 'git clone "%s"' % repo_url errc, out, err = run(self.cmd) if errc: raise RuntimeError("git clone failed: %s" % err) def _prepare_repo(self, pkg_name): """ Clone/fetch repo and chdir into it. """ repo_dir = "%s/%s" % (self.repo_base_dir, pkg_name) if os.path.isdir(repo_dir): os.chdir(repo_dir) self.cmd = 'git fetch --all' errc, out, err = run(self.cmd) if errc: return {'error': 'git fetch failed: %s' % (err or out), 'cmd': self.cmd} else: self._clone_repo(pkg_name) os.chdir(repo_dir) def _get_version(self, pkg_name, branch): try: self._prepare_repo(pkg_name) except RuntimeError, e: return {'error': e.args[0], 'cmd': self.cmd} ver = {} self.cmd = 'git describe --abbrev=0 --tags origin/%s' % branch ver['cmd'] = self.cmd errc, out, err = run(self.cmd) if errc: err_msg = err or out if err_msg.find("Not a valid object name") >= 0: err_msg = "Branch '%s' doesn't seem to exist." % branch else: err_msg = 'git log failed: %s' % err_msg ver['error'] = err_msg return ver tag = out.rstrip() if tag: ver['version'] = tag else: ver['error'] = "No git tags found in repo." return ver