Skip to content

Instantly share code, notes, and snippets.

@arnaudgelas
Created April 25, 2014 14:09
Show Gist options
  • Save arnaudgelas/11290881 to your computer and use it in GitHub Desktop.
Save arnaudgelas/11290881 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
import subprocess,os
from time import localtime,strftime
# directory containing the repositories
repo_dir = "/Users/arnaud/GITROOT/ITKExamples/.git"
# feed url
feed_url = "http://example.com/git/index.xml"
# location of rss on the web server
remote_file = "user@example.com:public_html/git/index.xml"
# atom feed id
feed_id = "example.com/git"
def atom_item(title="",content="",id="",date="",author="",email=""):
return """<entry>
<title>%s</title>
<id>%s</id>
<published>%s</published>
<updated>%s</updated>
<author>
<name>%s</name>
<email>%s</email>
</author>
<content type="html"><![CDATA[%s]]></content>
</entry>
""" % (title,id,date,date,author,email,content)
def atom_skeleton(title="",id="",date="",selflink="",inner=""):
return """<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>%s</title>
<link rel="self" href="%s" type="application/atom+xml" />
<id>%s</id>
<updated>%s</updated>
%s
</feed>
""" % (title,selflink,id,date,inner)
def commit_atom(data,feed_id):
timestamp,date,hash,name,email,subject,repo=data
title="[%s] %s" % (repo,subject)
id="%s:%s:%s" % (feed_id,repo,hash)
content="""<p>Commit %s to %s:<br><br>
%s<br><br>
Author: %s (%s)<br>
Date: %s</p>
""" % (hash[:7], repo, subject,name,email,date)
return atom_item(title=title,content=content,id=id,date=date,author=name,email=email)
# Get repositories
#dirs=os.listdir(repo_dir)
# Run each respective git log
commits=[]
#for dir in dirs:
try:
commits.extend(subprocess.check_output(["git",
# "--git-dir=%s%s" % (repo_dir,dir),
"log",
"--max-count=6",
r"--pretty=format:%at%x00%ai%x00%H%x00%an%x00%ae%x00%s%x00" #+ dir
]).rstrip().split("\n"))
except:
pass
# split the data
commit_list=[a.split("\x00") for a in commits]
print commit_list
for i in range(len(commit_list)):
commit_list[i][0]=int(commit_list[i][0])
commit_list.sort(reverse=True)
inner="\n".join([commit_atom(data,feed_id) for data in commit_list[:30]])
atom=atom_skeleton(title="Git repository logs",id=feed_id,
date=strftime("%Y-%m-%dT%H:%M:%S%z", localtime()),inner=inner,
selflink=feed_url)
f=open('.git-atom','w')
f.write(atom)
f.close()
#subprocess.call(['scp','.git-atom',remote_file])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment