def update_repo(repo_name, repo_object, active_branch): """Accept a GitPython Repo object and updates the specified branch.""" if active_branch == "latest": active_tag = get_latest_tag(repo_object) print "Checkout {repo_name}'s {active_tag} tag".format(repo_name=repo_name, active_tag=active_tag) try: build_utilities.call_binary("git", ["checkout", active_tag, "-b", active_tag]) except ProcessExecutionError, err: if err.retcode == 128: pass
def build(repo, log_directory, build_command="make_dist"): """Run the build directive from a repo's build script.""" build_log = os.path.join(log_directory, repo + "-build.log") with open(build_log, "w") as build_log_file: build_output = build_utilities.call_binary("ant", [build_command]) build_log_file.write(build_output)
def publish_local(repo, log_directory, publish_command="publish_local"): """Run the publish local directive from a repo's build script.""" publish_local_log = log_directory + "/" + repo + "-publishlocal.log" with open(publish_local_log, "w") as publish_local_log_file: publish_local_output = build_utilities.call_binary( "ant", [publish_command]) publish_local_log_file.write(publish_local_output)
def check_java_compiler(): """Check if a suitable Java compiler is found. The ESGF webapps currently support being built with Java 8 (JRE class number 52). An exception will be raised if an incompatible Java compiler is found. """ javac = build_utilities.call_binary("javac", ["-version"], stderr_output=True) javac = javac.split(" ")[1] if not javac.startswith("1.8.0"): raise EnvironmentError("Your Java compiler must be a Java 8 compiler (JRE class number 52). Java compiler version {} was found using javac -version".format(javac))
def get_latest_tag(repo): """Accept a GitPython Repo object and returns the latest annotated tag. Provides all the tags, reverses them (so that you can get the latest tag) and then takes only the first from the list. """ # Fetch latest tags from GitHub build_utilities.call_binary("git", ["fetch", "--tags"]) # A tag can point to a blob and the loop prunes blob tags from the list of tags to be sorted tag_list = [] for bar in repo.tags: try: bar.commit.committed_datetime except ValueError: pass else: tag_list.append(bar) sorted_tags = sorted(tag_list, key=lambda t: t.commit.committed_datetime) latest_tag = str(sorted_tags[-1]) return latest_tag
def update_tags(repo, synctag): """Update tags on the repo.""" if synctag: # Fetch latest tags from GitHub build_utilities.call_binary( "git", ["fetch", "--prune", "--prune-tags", "origin"]) return else: build_utilities.call_binary("git", ["fetch", "--tags"]) remote_tags = set(list_remote_tags()) local_tags = set(list_local_tags(repo)) local_only_tags = local_tags.difference(remote_tags) if local_only_tags: print "The following tags only exist locally and are not in sync with remote: {}".format( ", ".join(local_only_tags)) delete_local_tags = raw_input( "Would you like to delete them? [Y/n]: ") or "yes" if delete_local_tags.lower() in ["y", "yes"]: for tag in local_only_tags: build_utilities.call_binary("git", ["tag", "-d", tag])
def clean(repo, log_directory, clean_command="clean_all"): """Run the clean directive from a repo's build script.""" clean_log = os.path.join(log_directory, repo + "-clean.log") with open(clean_log, "w") as clean_log_file: clean_output = build_utilities.call_binary("ant", [clean_command]) clean_log_file.write(clean_output)