Last active
August 29, 2015 14:20
-
-
Save TristanCacqueray/bc0babe8261c42501830 to your computer and use it in GitHub Desktop.
Elections check ptl candidacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import os | |
import sys | |
import urllib | |
import re | |
import datetime | |
DATE_MIN = '2014-04-09' | |
DATE_MAX = '2015-04-09' | |
BASE_URL = 'http://git.openstack.org/cgit' | |
PROJECTS_URL = '%s/openstack/governance/plain/reference/projects.yaml' % (BASE_URL) | |
date_min = datetime.datetime.strptime(DATE_MIN, '%Y-%m-%d').strftime('%s') | |
date_max = datetime.datetime.strptime(DATE_MAX, '%Y-%m-%d').strftime('%s') | |
def check_date(date): | |
epoch = datetime.datetime.strptime(date, '%Y-%m-%d').strftime('%s') | |
if epoch > date_min and epoch < date_max: | |
return True | |
return False | |
try: | |
project_name = sys.argv[1] | |
author = sys.argv[2].replace(' ', '+') | |
except: | |
print "usage: %s <project> '<author>'" | |
exit(1) | |
if not os.path.isfile('projects.yaml'): | |
open('projects.yaml', 'w').write( | |
urllib.urlopen(PROJECTS_URL).read() | |
) | |
projects = yaml.load(open('projects.yaml')) | |
try: | |
project = projects[project_name] | |
except: | |
print "Can't find project [%s] in %s" % (project_name, projects.keys()) | |
exit(1) | |
for deliverable in project['deliverables'].values(): | |
for repo_name in deliverable["repos"]: | |
url = '%s/%s/log/?qt=author&q=%s' % (BASE_URL, repo_name, author) | |
print "Querying: %s" % url | |
found = False | |
for l in urllib.urlopen(url).read().split('\n'): | |
if "commit/?id=" not in l: | |
continue | |
try: | |
url = 'http://git.openstack.org/%s' % re.search("href='([^']*)'", l).groups()[0] | |
date = re.search('<td>([^<]*)</td>', l).groups()[0] | |
if not check_date(date): | |
continue | |
except: | |
continue | |
print "[%s]: %s" % (date, url) | |
found = True | |
if found: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment