Fixed a bug in the python script where I forgot to remove the clearing of 'who' (which breaks reporting multiple adds/removes in a single commit.)
On Tue, Aug 25, 2015 at 1:47 PM, Philip Webb <purs...@ca.inter.net> wrote: > 150825 malc wrote: >> On Tue, Aug 25, 2015 at 4:17 AM, Philip Webb <purs...@ca.inter.net> wrote: >>> Is there any possibility they could be sorted alphabetically ? >> Yup, good suggestion. Updated wrapper attached - output now looks like: > > -- snip -- > > Thanks. > > -- > ========================,,============================================ > SUPPORT ___________//___, Philip Webb > ELECTRIC /] [] [] [] [] []| Cities Centre, University of Toronto > TRANSIT `-O----------O---' purslowatchassdotutorontodotca > >
#!/usr/bin/env python2 # Authored by Alec Warner <anta...@gentoo.org> # Significent modifications by Robin H Johnson <robb...@gentoo.org> # Modified for Git support by Malcolm Lashley <mlash...@gmail.com> # Released under the GPL Version 2 # Copyright Gentoo Foundation 2006 # Changelog: Initial release 2006/10/27 # Git Support 2015/08/25 doc = """ # Purpose: This script analyzes the git log output in an attempt to locate package # additions and removals. It takes 3 arguments; two of which are optional. It needs # the path to the repository to read. If a start_date is not provided it will read # the entire log and match any addition/removal. If you provide a start date it will # only match things that are after that start_date. If you provide an end date you can # find matches over date ranges. If an end date is not provided it defaults to now() """ import sys, os, re, time, datetime, subprocess new_package = re.compile("^A\s+(.*)\/(.*)\/Manifest$") removed_package = re.compile("^D\s+(.*)\/(.*)\/Manifest$") author_re = re.compile("^Author: (.*)") date_re = re.compile("^Date:\s+(.*)") class record(object): def __init__(self, who, date, cp, op ): """ Who is a string date is whatever the crap git outputs for date string :) cp is a category/package op is "added", "removed", "moved" """ self.who = who self.date = date self.package = cp self.op = op def __str__( self ): #return "Package %s was %s by %s on %s" % (self.package, self.op, self.who, self.date) return "%s,%s,%s,%s" % (self.package, self.op, self.who, self.date) def cat (self): return self.package.split("/")[0] def pn (self): return self.package.split("/")[1] def date (self): return self.date def who (self): return self.who def op (self): return self.op def main(): if (len(sys.argv) < 2): usage() sys.exit(1) args = sys.argv[1:] repo_path = args[0] os.chdir(repo_path) if len(args) >= 2: start_date = ["--after", args[1] ] else: start_date = [] if len(args) >= 3: end_date = ["--before", args[2]] else: end_date = [] p = subprocess.Popen(["git","log","--name-status"] + start_date + end_date,stdout=subprocess.PIPE, stderr=subprocess.STDOUT) removals = [] adds = [] moves = [] for line in iter(p.stdout.readline,''): match = author_re.match(line) if match: who = match.groups()[0] match = date_re.match(line) if match: date = match.groups()[0] match = new_package.match( line ) if match: rec = record( who, date, match.groups()[0] + "/" + match.groups()[1], "added" ) adds.append( rec ) match = removed_package.match( line ) if match: rec = record( who, date, match.groups()[0] + "/" + match.groups()[1], "removed" ) removals.append( rec ) print("Removed Packages:") for pkg in removals: print(pkg) print("Added Packages:") for pkg in adds: print(pkg) print print("Done.") def usage(): print(sys.argv[0] + " <git repo path> [start date] [end date]") print("Start date defaults to '0'.") print("End date defaults to 'now'.") print("Both dates should be specified as anything git can parse...") print(doc) if __name__ == "__main__": main()