def verify_correct_branch(package_dir, buildopts): """Check that the user is not trying to build from trunk into upcoming, or vice versa. """ package_info = get_package_info(package_dir) url = package_info['canon_url'] for dver in buildopts['enabled_dvers']: if buildopts['targetopts_by_dver'][dver]['koji_target'].endswith( 'osg-upcoming'): if re.search(SVN_TRUNK_PATH, url): raise Error("""\ Error: Incorrect branch for koji build Not allowed to build into the upcoming targets from trunk (SVN/%s)! Either move the package dir into the upcoming area (SVN/%s) or a separate branch, or do not build it for the upcoming targets (i.e. do not pass the --upcoming, or the --koji-target el5-osg-upcoming or el6-osg-upcoming flags).""" % (SVN_TRUNK_PATH, SVN_UPCOMING_PATH)) else: if re.search(SVN_UPCOMING_PATH, url): raise Error("""\ Error: Incorrect branch for koji build Only allowed to build packages from the upcoming area (SVN/%s) into the upcoming targets. Either move the package dir into trunk (SVN/%s) or a separate branch, or pass the --upcoming flag.""" % (SVN_UPCOMING_PATH, SVN_TRUNK_PATH))
def koji(package_dir, koji_obj, buildopts): """koji task with a git build.""" package_dir = os.path.abspath(package_dir) verify_package_dir(package_dir) package_name = os.path.basename(package_dir) if not re.match(r"\w+", package_name): # sanity check raise Error("Package directory '%s' gives invalid package name '%s'" % (package_dir, package_name)) if not buildopts.get('scratch'): koji_obj.add_pkg(package_name) remote = get_fetch_url(package_dir, get_known_remote(package_dir)[0]) top_dir = os.path.split(os.path.abspath(package_dir))[0] command = [ "git", "--work-tree", top_dir, "--git-dir", os.path.join(top_dir, ".git"), "log", "-1", "--pretty=format:%H" ] out, err = utils.sbacktick(command, err2out=True) if err: raise GitError( "Exit code %d getting git hash for directory %s. Output:\n%s" % (err, package_dir, out)) rev = out.strip() return koji_obj.build_git(remote, rev, package_name)
def process_dot_source(cache_prefix, sfilename, destdir): """Read a .source file, fetch any files mentioned in it from the cache. """ utils.safe_makedirs(destdir) downloaded = [] try: sfile = open(sfilename, 'r') for lineno, line in enumerate(sfile): line = line.strip() if line.startswith('#'): continue if line == '': continue basename = os.path.basename(line) if line.startswith('/'): uri = "file://" + line log.warning( "An absolute path has been given in %s line %d. " "It is recommended to use only paths relative to %s" "in your source files.", sfilename, lineno + 1, cache_prefix) elif not re.match(r'/|\w+://', line): # relative path uri = os.path.join(cache_prefix, line) else: uri = line log.info('Retrieving ' + uri) try: handle = urllib2.urlopen(uri) except urllib2.URLError, err: raise Error("Unable to download %s\n%s" % (uri, str(err))) filename = os.path.join(destdir, basename) try: desthandle = open(filename, 'w') desthandle.write(handle.read()) except EnvironmentError, err: raise Error("Unable to save downloaded file to %s\n%s" % (filename, str(err))) downloaded.append(filename)
def koji(package_dir, koji_obj, buildopts): """koji task with an svn build.""" package_info = get_package_info(package_dir) package_name = os.path.basename(package_info['canon_url']) if not re.match("\w+", package_name): # sanity check raise Error("Package directory '%s' gives invalid package name '%s'" % (package_dir, package_name)) if not verify_package_info(package_info): raise UsageError("%s isn't a package directory " "(must have either osg/ or upstream/ dirs or both)" % (package_dir)) if not buildopts.get('scratch'): koji_obj.add_pkg(package_name) return koji_obj.build_svn(package_info['canon_url'], package_info['revision'])
def verify_correct_branch(package_dir, buildopts): """Check that the user is not trying to build from trunk into upcoming, or vice versa. """ branch = get_branch(package_dir) remote = get_known_remote(package_dir)[1] verify_correct_remote(package_dir) # We only have branching rules for OSG and HCC repos if remote not in constants.KNOWN_GIT_REMOTES: return if remote == constants.OSG_REMOTE: verify_git_svn_commit(package_dir) for dver in buildopts['enabled_dvers']: target = buildopts['targetopts_by_dver'][dver]['koji_target'] if target.startswith("hcc-"): if branch.find("master") < 0: raise Error("""\ Error: Incorrect branch for koji build Only allowed to build into the HCC repo from the master branch! You must switch branches.""") if remote != constants.HCC_REMOTE and remote != constants.HCC_AUTH_REMOTE: raise Error("""\ Error: You must build into the HCC repo when building from a HCC git checkout. You must switch git repos or build targets.""") elif target.endswith('osg-upcoming'): if remote != constants.OSG_REMOTE: raise Error("""\ Error: You may not build into the OSG repo when building from a non-OSG target. You must switch git repos or build targets. Try adding "--repo=hcc" to the command line.""") if branch.find("master") >= 0: raise Error("""\ Error: Incorrect branch for koji build Not allowed to build into the upcoming targets from master branch! You must switch branches or build targets.""") elif target.find("osg") >= 0: if remote != constants.OSG_REMOTE: raise Error("""\ Error: You may not build into the OSG repo when building from a non-OSG target. You must switch git repos or build targets. Try adding "--repo=hcc" to the command line.""") if branch.find("upcoming") >= 0: raise Error("""\ Error: Incorrect branch for koji build Only allowed to build packages from the upcoming branch into the upcoming targets. Either switch the branch to master, or pass the --upcoming flag.""")
def is_svn(package_dir): """Determine whether a given directory is part of an SVN repo.""" # If package_dir is a URL, not a directory, then we can't cd into it to # check. Assume True for now. if utils.is_url(package_dir): return True # TODO: Allow specifying a git URL to build from. pwd = os.getcwd() try: try: os.chdir(package_dir) except OSError, ose: if ose.errno == errno.ENOENT: raise Error("%s is not a valid package directory\n(%s)" % (package_dir, ose)) command = ["svn", "info"] try: err = utils.sbacktick(command, err2out=True)[1] except OSError, ose: if ose.errno != errno.ENOENT: raise err = 1