def _compile_and_run_utility(utility, args): """Compile a utility somewhere in a temporary directory so it can be used this time, and then run it.""" logger.warning("Compiling {} in place".format(utility)) filename = utility + ".java" # First, try to compile in place. return_code, stdout, stderr = popen([config.javac()] + [filename], cwd=libexec) if return_code != 0: logger.warning( "Failed to compile {} in place, trying in a tempdir".format( utility)) with tempfile.TemporaryDirectory() as dir: shutil.copy(os.path.join(libexec, filename), dir) return_code, stdout, stderr = popen([config.javac()] + [filename], cwd=dir) if return_code != 0: logger.error( "Failed to compile {}! Please compile manually.".format( utility)) raise JavaUtilityException( "{} needs to be compiled".format(utility)) # Call the utility from the temporary directory return _run_utility(utility, args, basedir=dir) # Compilation succeeded in-place, call the utility normally return _run_utility(utility, args)
def git_all_tags(repo): return_code, stdout, stderr = popen( [config.git(), "tag", "--sort", "version:refname"], cwd=repo) if return_code != 0: raise VersionControlException( "Failed to get tags of Git repository {}\n{}".format(repo, stderr)) return stdout.split()
def git_last_commit(repo): return_code, stdout, stderr = popen( [config.git(), "log", "-1", "--oneline"], cwd=repo) if return_code != 0: raise VersionControlException( "Failed to get last commit of Git repository {}".format(repo)) return stdout.split()[0]
def _checkout_commit(checkout_dir, commit): """Checkout a Git commit at some location.""" return_code, _, _ = popen([config.git(), "checkout", commit], cwd=checkout_dir) if return_code != 0: raise VersionControlException( "Checking out commit {} at {} failed!".format( commit, checkout_dir))
def call_git(repo, *args): """Call Git in some repository with some arguments. If the exit code is not 0, an exception is raised. """ cmd = ["git"] + list(args) return_code, _, _ = popen(cmd, cwd=repo) if return_code != 0: raise CalledProcessError(return_code, cmd)
def _run_inspector(file, repo): """Runs the utility program inspector.clj for a file, with the working directory set to 'repo'.""" arglist = [config.clojure(), inspector_clj, file] logger.debug("Running inspector as follows: " + ' '.join(arglist)) return_code, stdout, stderr = popen(arglist, cwd=repo) if return_code != 0: raise _ClojureUtilityException(stderr) return stdout
def _run_utility(utility, args, basedir=libexec): """Run a Java utility program with arguments.""" javafile = os.path.join(basedir, utility + ".java") classfile = os.path.join(basedir, utility + ".class") if os.path.isfile(javafile) and not os.path.isfile(classfile): logger.warning("{} has not been compiled".format(utility)) return _compile_and_run_utility(utility, args) return_code, stdout, stderr = popen([config.java()] + [utility] + args, cwd=basedir) if return_code != 0: raise JavaUtilityException(stderr) return stdout
def setUp(repo): cmd = [ "mvn", "dependency:build-classpath", "-Dmdep.outputFile=classpath.txt" ] return_code, _, _ = popen(cmd, cwd=repo) if return_code != 0: print("Failed to get classpath from Maven!", file=sys.stderr) exit(1) with open(os.path.join(repo, "classpath.txt")) as classpathf: classpath = classpathf.read() # If we set the classpath to exactly what Maven told us, then # Autobump's own utilities won't work. That's why we need to add the # current directory to the end as well. os.environ["CLASSPATH"] = classpath + ":.:"
def _clone_repo(repo, checkout_dir): """Clone a git repository into a directory.""" return_code, _, _ = popen([config.git(), "clone", repo, checkout_dir]) if return_code != 0: raise VersionControlException("Cloning {} into {} failed!".format( repo, checkout_dir))
def hg_last_commit(repo): return_code, stdout, stderr = popen([config.hg(), "log", "-r", "tip", "--template", "{rev}"], cwd=repo) if return_code != 0: raise VersionControlException("Failed to get last commit of Hg repository {}" .format(repo)) return stdout.split()[0]
def hg_all_tags(repo): return_code, stdout, stderr = popen([config.hg(), "log", "-r", 'tag()', "--template", '{tags}\n'], cwd=repo) if return_code != 0: raise VersionControlException("Failed to get tags of Hg repository {}" .format(repo)) return stdout.split()
def hg_last_tag(repo): return_code, stdout, stderr = popen([config.hg(), "log", "-r", '"."', "--template", "{latesttag}"], cwd=repo) if return_code != 0: raise VersionControlException("Failed to get last tag of Hg repository {}" .format(repo)) return stdout
def _run_git(checkout_dir, args): """Run Git inside a directory with a list of arguments.""" return_code, _, _ = popen(["git"] + args, cwd=checkout_dir) if return_code != 0: raise VersionControlException("\'git {}\' failed!".format(args))