def dist(branch=None, default=exception.CantGuess): if branch is None: try: branch = current_branch() except exception.CantGuess as ex: if default is exception.CantGuess: raise exception.CantGuess(what="dist", why=ex.kwargs['why']) else: return default m = re.search(r'\brhel-?(\d+)\b', branch, re.I) if m: return 'rhel-' + m.group(1) m = re.search(r'\be(?:pe)?l-?(\d+)\b', branch, re.I) if m: return 'epel-' + m.group(1) _branch = branch if branch == 'master': _branch = FEDORA_MASTER m = re.search(r'\bf(?:edora)?-?(\d+)\b', _branch, re.I) if m: fedn = int(m.group(1)) # XXX: RDO provides packages for Fedora N-1 fedn -= 1 return 'fedora-%d' % fedn if default is exception.CantGuess: raise exception.CantGuess(what="dist", why="unknown branch '%s'" % branch) else: return default
def current_branch(default=exception.CantGuess): try: branch = git.current_branch() except exception.CommandFailed: if default is exception.CantGuess: raise exception.CantGuess( what="branch", why="git command failed (not in a git repo?)") else: return default if not branch: if default is exception.CantGuess: raise exception.CantGuess(what="branch", why="git command returned no output") else: return default return branch
def current_version(default=exception.CantGuess): version = None try: spec = specfile.Spec() version, _ = spec.get_patches_base(expand_macros=True) if version: version, _ = tag2version(version) else: version = spec.get_tag('Version', expand_macros=True) if not version: raise exception.CantGuess(msg="got empty .spec Version") except Exception as ex: if default is exception.CantGuess: raise exception.CantGuess(what="current package version", why=str(ex)) else: return default return version
def package(default=exception.CantGuess): pkg = os.path.basename(os.getcwd()) if not pkg: if default is exception.CantGuess: raise exception.CantGuess(what="package", why="failed to parse current directory") else: return default return pkg
def osreleasedist(branch=None, default=exception.CantGuess): if branch is None: try: branch = current_branch() except exception.CantGuess as ex: if default is exception.CantGuess: raise exception.CantGuess(what="release", why=ex.kwargs['why']) else: return default rls, dist = osreleasedist_rdoinfo(branch) if rls: return rls, dist if default is exception.CantGuess: raise exception.CantGuess(what="release", why="unknown branch '%s'" % branch) else: return default
def nvr(pkg=None, branch=None, default=exception.CantGuess): if not pkg: try: pkg = package() except exception.CantGuess: if default is exception.CantGuess: raise else: return default if not branch: try: branch = current_branch() except Exception: if default is exception.CantGuess: raise else: return default tag = branch if tag.startswith('el6-'): tag = "dist-6E-epel-testing-candidate" kojiout = run("koji", "latest-pkg", "--quiet", tag, pkg, fatal=False, print_output=True) if not kojiout.success: if default is exception.CantGuess: raise exception.CantGuess(what="nvr", why="koji query failed") else: return default m = re.match('^(\S+)\s+\S+\s+\S+$', kojiout) if not m: if default is exception.CantGuess: raise exception.CantGuess(what="nvr", why="can't parse koji output") else: return default return m.group(1)
def email(): email = git('config', 'user.email', log_cmd=False, fatal=False) if not email: raise exception.CantGuess(what="user email", why='git config user.email not set') return email
def user(): user = git('config', 'user.name', log_cmd=False, fatal=False) if not user: raise exception.CantGuess(what="user name", why='git config user.name not set') return user.decode('utf-8')