def get_authors_by_date(header=False): """lists the authors of a git repository sorted by date. Example: 0001 (2015-02-25): Gregor von Laszewski ([email protected]) 0002 (2015-04-14): Fugang Wang ([email protected]) :rtype: str """ # modified from https://github.com/jgehrcke/git-authors result = "" # if header: # result = result + "Authors\n" # result = result + "=======\n\n" r = Shell.git("log", "--encoding=utf-8", "--full-history", "--reverse", "--format=format:%at;%an;%ae").split("\n") seen = set() for line in r: timestamp, name, email = line.strip().split(";") if name not in seen: seen.add(name) day = time.strftime("%Y-%m-%d", time.gmtime(float(timestamp))) result = result + "* {:04d} ({:}): {:} ({:})\n".format(len(seen), day, name, email) return result
def emails(self, output=None): """ returns the emails of the authors either as a text or as a dict. The format is specified as an argument. :param output: if "dict" is specified a dict will be returned :rtype: dict or array of e-mails dependent on output """ format_string = "'%aN' <%cE>" if output == 'dict': format_string = "%aN\t%cE" result = sorted( set( Shell.git("log", "--all", "--format=" + format_string).split("\n"))) if output is None: return result elif output == "dict": emails = {} for l in result: (name, email) = l.split("\t") emails[name] = email return emails
def stat(self, email): """ returns a statistic of a git author with the given e_mail. :param email: name of the author :rtype: a dict with the statistics """ result = Shell.git("log", "--all", "--stat", '--author={0}'.format(email)).split("\n") sums = [0, 0, 0] for line in result: if " files changed" in line: line = line.strip() line = line.replace(" insertions(+)", "") line = line.replace(" insertion(+)", "") line = line.replace(" deletion(-)", "") line = line.replace(" deletions(-)", "") line = line.replace(" files changed", "") line = line.split(",") data = [int(i) for i in line] for index in range(0, len(data)): sums[index] += data[index] return {"email": email, "fileschanged": sums[0], "inserted": sums[1], "deleted": sums[2], "lineschanged": sums[1] + sums[2]}
def get_authors_by_date(header=False): """lists the authors of a git repository sorted by date. Example: 0001 (2015-02-25): Gregor von Laszewski ([email protected]) 0002 (2015-04-14): Fugang Wang ([email protected]) :rtype: str """ # modified from https://github.com/jgehrcke/git-authors result = "" # if header: # result = result + "Authors\n" # result = result + "=======\n\n" r = Shell.git("log", "--encoding=utf-8", "--full-history", "--reverse", "--format=format:%at;%an;%ae").split("\n") seen = set() for line in r: timestamp, name, email = line.strip().split(";") if name not in seen: seen.add(name) day = time.strftime("%Y-%m-%d", time.gmtime(float(timestamp))) result = result + "* {:04d} ({:}): {:} ({:})\n".format( len(seen), day, name, email) return result
def stat(self, email): """ returns a statistic of a git author with the given e_mail. :param email: name of the author :rtype: a dict with the statistics """ result = Shell.git("log", "--all", "--stat", '--author={0}'.format(email)).split("\n") sums = [0, 0, 0] for line in result: if " files changed" in line: line = line.strip() line = line.replace(" insertions(+)", "") line = line.replace(" insertion(+)", "") line = line.replace(" deletion(-)", "") line = line.replace(" deletions(-)", "") line = line.replace(" files changed", "") line = line.split(",") data = [int(i) for i in line] for index in range(0, len(data)): sums[index] += data[index] return { "email": email, "fileschanged": sums[0], "inserted": sums[1], "deleted": sums[2], "lineschanged": sums[1] + sums[2] }
def tag(self): v = self.find() banner("v") print v #v = ".".join(self.version) os.system("python shell_plugins.py install") if self.git_commit_needed(): banner("git commit") command = "git commit -m 'version {:}' {:}".format(v,self.filename) print "CCC", command os.system(command) os.system("git push") else: print "git commit not needed" Shell.git("tag", "-a", v, "-m", "version {:}".format(v)) Shell.git("push", "origin", "--tags")
def tag(self): v = self.find() banner("v") print v #v = ".".join(self.version) os.system("python shell_plugins.py install") if self.git_commit_needed(): banner("git commit") command = "git commit -m 'version {:}' {:}".format( v, self.filename) print "CCC", command os.system(command) os.system("git push") else: print "git commit not needed" Shell.git("tag", "-a", v, "-m", "version {:}".format(v)) Shell.git("push", "origin", "--tags")
def authors(self, output=None): """ returns the authors of the authors either as a text or as a dict. The format is specified as an argument. :param output: if "dict" is specified a dict will be returned """ result = Shell.git("shortlog", "-s", "-n") if output is None: return result elif output == "dict": authors = {} for line in result.split("\n"): l = " ".join(line.split()).strip() (number, name) = l.split(" ", 1) authors[name] = int(number) return authors
def emails(self, output=None): """ returns the emails of the authors either as a text or as a dict. The format is specified as an argument. :param output: if "dict" is specified a dict will be returned :rtype: dict or array of e-mails dependent on output """ format_string = "'%aN' <%cE>" if output == 'dict': format_string = "%aN\t%cE" result = sorted(set(Shell.git("log", "--all", "--format=" + format_string).split("\n"))) if output is None: return result elif output == "dict": emails = {} for l in result: (name, email) = l.split("\t") emails[name] = email return emails
def version(self): """ returns the verison of the code from github :rtype: the git tags """ return str(Shell.git("describe", "--tags"))[:-1]
sums["deleted"] += stats[email]["deleted"] sums["lineschanged"] += stats[email]["lineschanged"] for email in emails: stats[email] = {'percentage': [ stats[email]["fileschanged"] / float(sums["fileschanged"]), stats[email]["inserted"] / float(sums["inserted"]), stats[email]["deleted"] / float(sums["deleted"]), stats[email]["lineschanged"] / float(sums["lineschanged"]) ]} return stats if __name__ == "__main__": print (Shell.git("shortlog", "-n", "-s")) gitinfo = GitInfo() # print gitinfo.version() banner("a") print(gitinfo.authors()) banner("b") pprint(gitinfo.authors("dict")) banner("c") pprint(gitinfo.emails())
def git_commit_needed(self): content = Shell.git("status") return ("Changes to be committed:" in content) or \ ('Your branch is ahead' in content)
for email in emails: stats[email] = { 'percentage': [ stats[email]["fileschanged"] / float(sums["fileschanged"]), stats[email]["inserted"] / float(sums["inserted"]), stats[email]["deleted"] / float(sums["deleted"]), stats[email]["lineschanged"] / float(sums["lineschanged"]) ] } return stats if __name__ == "__main__": print(Shell.git("shortlog", "-n", "-s")) gitinfo = GitInfo() # print gitinfo.version() banner("a") print(gitinfo.authors()) banner("b") pprint(gitinfo.authors("dict")) banner("c") pprint(gitinfo.emails()) banner("d")
def get_version_from_git(): return Shell.git('tag').split("\n")[-1]