Hi Robin,

Updated code and sample output :)

Cheers,
malc. (long-time lapsed dev.)

On Mon, Aug 24, 2015 at 6:44 PM, Robin H. Johnson <robb...@gentoo.org> wrote:
> On Mon, Aug 24, 2015 at 09:48:16AM +0200, Patrice Clement wrote:
>> Monday 24 Aug 2015 00:05:20, Robin H. Johnson wrote :
>> > The attached list notes all of the packages that were added or removed
>> > from the tree, for the week ending 2015-08-23 23:59 UTC.
>> >
>> > Removals:
>> >
>> > Additions:
>> >
>> > --
>> > Robin Hugh Johnson
>> > Gentoo Linux Developer
>> > E-Mail     : robb...@gentoo.org
>> > GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85
>>
>> > Removed Packages:
>> > Added Packages:
>> > Done.
>> You should turn this off now. :)
>>
>> Btw, do you still need help with the same script but for Git?
> I said last week already, that would somebody please write a Git version
> of it. The prior one was very CVS-specific.
>
> The mailer part is already separate from the data-build part, so here's
> that data-build part if you wanted to integrate with the existing mail.
>
> I've attached all the scripts from the CVS version, so you can see how
> to slot in the Git code (replace the process.sh and .py script).
>
> --
> Robin Hugh Johnson
> Gentoo Linux: Developer, Infrastructure Lead
> E-Mail     : robb...@gentoo.org
> GnuPG FP   : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
Removals:
dev-java/burlap                 Mon Aug 24 17:21:42 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>
dev-java/caucho-services        Mon Aug 24 17:21:42 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>
dev-java/jldap                  Mon Aug 24 17:19:44 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>
dev-java/openspml               Mon Aug 24 17:19:44 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>
dev-java/openspml2              Mon Aug 24 17:19:44 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>
dev-java/soap                   Mon Aug 24 17:19:44 2015 +0200  Patrice Clement 
<monsie...@gentoo.org>

Additions:
dev-go/go-md2man                Mon Aug 24 17:59:21 2015 -0500  William Hubbs 
<willi...@gentoo.org>
dev-go/blackfriday              Mon Aug 24 17:48:35 2015 -0500  William Hubbs 
<willi...@gentoo.org>
dev-go/sanitized-anchor-name    Mon Aug 24 17:43:23 2015 -0500  William Hubbs 
<willi...@gentoo.org>
x11-misc/kronometer             Tue Aug 25 04:13:15 2015 +1000  Michael 
Palimaka <kensing...@gentoo.org>
dev-python/packaging            Mon Aug 24 09:15:07 2015 +0200  Justin Lecher 
<j...@gentoo.org>
dev-python/progress             Mon Aug 24 09:06:06 2015 +0200  Justin Lecher 
<j...@gentoo.org>
dev-python/CacheControl         Mon Aug 24 08:46:41 2015 +0200  Justin Lecher 
<j...@gentoo.org>
dev-python/distlib              Mon Aug 24 08:41:12 2015 +0200  Justin Lecher 
<j...@gentoo.org>
#!/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 )
			who = ""
			date = ""

		match = removed_package.match( line )
		if match:
			rec = record( who, date, match.groups()[0] + "/" + match.groups()[1], "removed" )
			removals.append( rec )
# Can't assume these can be re-initialized as git would allow multiple removes in 1 commit
#			who = ""
#			date = ""

	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()

Attachment: find-git-adds-and-removals-process.sh
Description: Bourne shell script

Reply via email to