From d33f6828a4e6a95abcaf4884b0d14ea9b1fad018 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Sat, 2 Dec 2017 10:43:53 +0000 Subject: [PATCH] Add differences folder --- differences/.project | 17 +++ differences/.pydevproject | 8 ++ differences/show_release_differences.py | 151 ++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 differences/.project create mode 100644 differences/.pydevproject create mode 100644 differences/show_release_differences.py diff --git a/differences/.project b/differences/.project new file mode 100644 index 0000000..75af0fc --- /dev/null +++ b/differences/.project @@ -0,0 +1,17 @@ + + + Release_difference + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/differences/.pydevproject b/differences/.pydevproject new file mode 100644 index 0000000..c3434da --- /dev/null +++ b/differences/.pydevproject @@ -0,0 +1,8 @@ + + + +/${PROJECT_DIR_NAME} + +python 3.0 +Default + diff --git a/differences/show_release_differences.py b/differences/show_release_differences.py new file mode 100644 index 0000000..1d525b9 --- /dev/null +++ b/differences/show_release_differences.py @@ -0,0 +1,151 @@ +''' +Created on 2 Mar 2017 + +@author: Dan +''' +import subprocess +import os +import sys +import re + +GIT_EXECUTABLE = os.getenv("GIT_EXECUTABLE") +if GIT_EXECUTABLE == None: + print("Please define the GIT_EXECUTABLE environment variable to the git executable path") + sys.exit(1) + +WORKING_PATH = os.getenv("WORKING_PATH") +if WORKING_PATH == None: + print("Please define the WORKING_PATH environment variable to the git repository path to use") + sys.exit(1) + +CURRENT_RELEASE = os.getenv("CURRENT_RELEASE") +if CURRENT_RELEASE == None: + print("Please define the CURRENT_RELEASE version") + sys.exit(1) + +PREVIOUS_RELEASE = os.getenv("PREVIOUS_RELEASE") +if PREVIOUS_RELEASE == None: + print("Please define the PREVIOUS_RELEASE version") + sys.exit(1) + +DIFFERENCE_OPTIONS = os.getenv("DIFFERENCE_OPTIONS") +if DIFFERENCE_OPTIONS == None: + DIFFERENCE_OPTIONS = "" + +class GitException(Exception): + def __init__(self, message): + self.message = message + + def __repr__(self): + return self.message + +def printDivider(times = 1, length = 100): + for _ in range(times): + print("*" * length) + +TABSIZE = 4 +def printTabbed(string, tabs = 0): + print("{0}{1}".format(" " * (TABSIZE * tabs), string)) + +def getGitLogDifferences(workingPath, previousRelease, currentRelease, tripledot = False): + gitExecutable = GIT_EXECUTABLE + if tripledot: + releaseExpression = previousRelease + "..." + currentRelease + else: + releaseExpression = previousRelease + ".." + currentRelease + currentdir = os.getcwd() + os.chdir(workingPath) + gitlog = [] + printTabbed("Executing: {0} {1} {2} {3}".format(gitExecutable, "log", "--oneline", releaseExpression)) + proc = subprocess.Popen([gitExecutable, "log", "--oneline", releaseExpression], stdout=subprocess.PIPE) + while True: + line = proc.stdout.readline() + if line: + linestring = line.decode('utf-8').rstrip() + gitlog.append(linestring) + #printTabbed(linestring, 1) + else: + break + proc.wait() + if proc.returncode > 0: + raise GitException("Git executable returned an error") + os.chdir(currentdir) + return gitlog + +expectedpattern = re.compile("^.* +(?:[gG][iI][sS][ _-]*|[tT]rac \#*|\#\s*)(\d+):*(.*)$") +revertpattern = re.compile('^(\S*) Revert " *GIS-(\d+):* (.*)"$') +mergepattern = re.compile("^(.*)((?:Merge branch '.*'|Merge remote-tracking branch '.*'|Merge commit '.*'|Add '.*' from commit).*)$") + +def processLog(gitlog): + reverts = [] + merges = {} + other = [] + numbered = {} + for line in gitlog: + expectedmatch = expectedpattern.match(line) + revertmatch = revertpattern.match(line) + mergematch = mergepattern.match(line) + if expectedmatch == None and revertmatch == None and mergematch == None: + other.append(line) + if revertmatch: + gisnumber = "GIS-" + revertmatch.group(2) + description = revertmatch.group(3) + reverts.append("Revert: {0} {1}".format(gisnumber, description)) + if mergematch: + merge = mergematch.group(2) + if not merge in merges: + merges[merge] = 1 + else: + merges[merge] += 1 + if expectedmatch: + gisnumber = "GIS-" + expectedmatch.group(1) + description = expectedmatch.group(2) + if not gisnumber in numbered: + numbered[gisnumber] = [] + numbered[gisnumber].append(description) + return (reverts, merges, other, numbered) + +def showDifferences(differences): + (revertslog, mergeslog, otherlog, numberedlog) = differences + printDivider() + printTabbed("GIS-Numbers Log:") + for (gisnumber, descriptions) in sorted(numberedlog.items()): + printTabbed(gisnumber, 1) + descriptions = numberedlog[gisnumber]; + for description in descriptions: + printTabbed(description, 2) + printDivider() + printTabbed("Revert log:") + for reversion in sorted(revertslog): + printTabbed(reversion, 1) + printDivider() + printTabbed("Merges log:") + for merge in sorted(mergeslog): + printTabbed(merge, 1) + printDivider() + printTabbed("Other log:") + for other in sorted(otherlog): + printTabbed(other, 1) + +def main(): + workingPath = WORKING_PATH + previous = PREVIOUS_RELEASE + now = CURRENT_RELEASE + printDivider(times = 4) + printTabbed("Looking for changes in {2} that are not in {1} of the repository at path: {0}".format(workingPath, previous, now)) + gitlog = getGitLogDifferences(workingPath, previous, now) + showDifferences(processLog(gitlog)) + if 'opposite' in DIFFERENCE_OPTIONS.lower(): + printDivider(times = 4) + printTabbed("Looking for changes in {2} that are not in {1} of the repository at path: {0}".format(workingPath, now, previous)) + gitlog = getGitLogDifferences(workingPath, now, previous) + showDifferences(processLog(gitlog)) + if 'notcommon' in DIFFERENCE_OPTIONS.lower(): + printDivider(times = 4) + printTabbed("Looking for changes that are not common to {1} or {2} at path: {0}".format(workingPath, now, previous)) + gitlog = getGitLogDifferences(workingPath, now, previous, tripledot = True) + showDifferences(processLog(gitlog)) + sys.exit(0) + +if __name__ == '__main__': + main() \ No newline at end of file