Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added post-commit.py script

  • Loading branch information...
commit c705fe2991d11bcfba7a91be46c69ddb5c2e1ec2 1 parent 17c79f7
@ranman authored
Showing with 49 additions and 0 deletions.
  1. +49 −0 post-commit.py
View
49 post-commit.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# this is an awesome githook by randall at 4am.
+# now to get back to real work
+import os
+import subprocess
+import time
+from datetime import datetime
+from pymongo import MongoClient
+from bson import binary
+host = 'localhost'
+port = 27017
+database = 'gitscraper'
+auth = ('gitscraper', 'gitscraper')
+gitshots_path = '~/.gitshots/'
+# must have space at end
+img_command = 'imagesnap -q '
+# filename is unix epoch time
+filename = str(time.mktime(datetime.now().timetuple()))[:10] + '.jpg'
+imgpath = os.path.abspath(os.path.expanduser(gitshots_path + filename))
+img_command = img_command + imgpath
+# ??? BUG: better way to get this?
+author = 'ranman'
+
+db = MongoClient(host=host, port=port)[database]
+db.authenticate(*auth)
+
+
+subprocess.check_output(img_command.split(' '), shell=False)
+data = dict()
+with open(imgpath, 'rb') as f:
+ # binary, yo
+ data['img'] = binary.Binary(f.read())
+
+data['author'] = author
+# timestamp
+data['ts'] = datetime.fromtimestamp(int(filename[:10]))
+# grab commit message and chop off the last newline
+data['msg'] = subprocess.check_output(
+ ["git", "log", "-n", "1", "HEAD", "--format=format:%s%n%b"],
+ shell=False).rstrip()
+# project name or document
+data['project'] = os.path.basename(os.getcwd())
+# diff stats
+stats = subprocess.check_output(['git', 'diff', 'HEAD~1', '--numstat'])
+stats = stats.split('\n')
+dstats = [dict(zip(['+', '-', 'f'], line.split('\t'))) for line in stats][:-1]
+data['dstats'] = dstats
+db.gitshots.insert(data)
+print "Data pushed"
Please sign in to comment.
Something went wrong with that request. Please try again.