-
Notifications
You must be signed in to change notification settings - Fork 1
/
disciple.py
76 lines (60 loc) · 2.33 KB
/
disciple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''
Early stages of development of a GitHub project tracker. It's like watching a
live birth. But messier.
'''
import sys
from github import github
from bop import *
import memcache
import iso8601
import config
from helpers import AttrDict
__version__ = "0.1"
# Tell Bop about the static/ directory.
# Under the development runner, this folder will now be served as normal.
# Under any runner, this object supports attribute access, so that (when called
# while handling a request):
# static['jquery.js']
# gives a full URI to static/jquery.js.
# Template code can do that, too, since objects in your module are
# automatically put in template scope by Bop. (Sorry for all the undocumented
# magic!)
static = static_directory('/static', 'static')
@setup
def setup_cache():
cache = memcache.Client(['127.0.0.1:11211'])
# invoke bop -e clear_cache disciple.py to clear the cache at startup
if env('clear_cache'):
cache.delete('disciple_repos')
# dicts returned from setup functions are added to the app's Bop
# environment
return {'cache': cache}
@setup
def setup_template():
return {'template.engine': 'jinja2', 'template.path': ['templates']}
@get('/')
def index(request):
cache = env('cache')
repos = cache.get('disciple_repos')
if not repos:
try:
gh = github.GitHub(config.username, config.token)
except AttributeError, e:
gh = github.GitHub()
repos = []
for repo in config.repos:
info = gh.repos.show(repo.user, repo.repo)
commits = gh.commits.forBranch(repo.user, repo.repo, repo.branch)
if not isinstance(commits, list):
commits = []
for commit in commits:
committed_date = iso8601.parse_date(commit.committed_date)
commit.committed_date = committed_date.strftime('%a %b %d %H:%M:%S %z %Y')
authored_date = iso8601.parse_date(commit.authored_date)
commit.authored_date = authored_date.strftime('%a %b %d %H:%M:%S %z %Y')
repos.append(AttrDict({'info':info, 'commits':commits}))
# cache it for 10 minutes
cache.set("disciple_repos", repos, time=600)
return render('overview.html', repos=repos) # 200 OK; text/html is default
if __name__ == '__main__':
run()