annotate repo_github_status.py @ 21:cb71722bb75c

use pipenv
author drewp@bigasterisk.com
date Tue, 29 Mar 2022 21:13:48 -0700
parents b59912649fc4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
6f38aa08408d starting over: make a web page that draws a streamed graph from collector, with plans for services to scrape the data that collector will subscribe to
drewp@bigasterisk.com
parents:
diff changeset
1 """
6f38aa08408d starting over: make a web page that draws a streamed graph from collector, with plans for services to scrape the data that collector will subscribe to
drewp@bigasterisk.com
parents:
diff changeset
2 repos from config.yaml that are at github -> rdf data
19
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
3 """
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
4 import datetime
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
5 from pathlib import Path
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
6 from typing import Set, Tuple
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
7
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
8 import cyclone.web
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
9 import docopt
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
10 import treq
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
11 from background_loop import loop_forever_async
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
12 from dateutil.parser import parse
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
13 from dateutil.tz import tzlocal
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
14 from patchablegraph import (CycloneGraphEventsHandler, CycloneGraphHandler, PatchableGraph)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
15 from prometheus_client import Counter, Gauge
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
16 from prometheus_client.exposition import generate_latest
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
17 from prometheus_client.registry import REGISTRY
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
18 from rdfdb.currentstategraphapi import CurrentStateGraphApi
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
19 from rdfdb.patch import Patch
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
20 from rdflib import RDF, Literal, Namespace, URIRef
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
21 from rdflib.term import Identifier
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
22 from ruamel.yaml import YAML
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
23 from standardservice.logsetup import log, verboseLogging
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
24 from twisted.internet import reactor
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
25 from twisted.internet.defer import inlineCallbacks
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
26
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
27 Quad = Tuple[Identifier, Identifier, Identifier, Identifier]
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
28 Triple = Tuple[Identifier, Identifier, Identifier]
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
29
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
30 githubOwner = 'drewp'
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
31
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
32 EX = Namespace('http://example.com/') # todo
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
33 GITHUB_SYNC = Gauge('github_sync', 'syncs to github')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
34 GITHUB_CALLS = Counter('github_calls', 'http calls to github')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
35
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
36
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
37 # merge this into setToGraph
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
38 def replaceContext(pg: PatchableGraph, ctx: URIRef, newTriples: Set[Triple]):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
39 prevCtxStmts = set((s, p, o, g.identifier) for s, p, o, g in pg._graph.quads((None, None, None, ctx)))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
40
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
41 currentStmts: Set[Quad] = set()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
42 for tri in newTriples:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
43 currentStmts.add(tri + (ctx,))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
44
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
45 p = Patch(delQuads=prevCtxStmts.difference(currentStmts), addQuads=currentStmts.difference(prevCtxStmts))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
46
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
47 pg.patch(p)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
48
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
49
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
50 class Metrics(cyclone.web.RequestHandler):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
51
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
52 def get(self):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
53 self.add_header('content-type', 'text/plain')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
54 self.write(generate_latest(REGISTRY))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
55
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
56
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
57 class Index(cyclone.web.RequestHandler):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
58
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
59 def get(self, *args):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
60 self.add_header('content-type', 'text/html')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
61 self.write('''<!DOCTYPE html>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
62 <html>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
63 <head>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
64 <title>repo_github_status</title>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
65 </head>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
66 <body>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
67 <a href="graph/localRepos">graph</a>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
68 </body>
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
69 </html>''')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
70
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
71
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
72 @inlineCallbacks
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
73 def updateOne(graph: PatchableGraph, repo: URIRef, ghrepo: URIRef, shortRepoName: str):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
74 log.info(f'getting update from github for {repo}')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
75
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
76 writeGhRepo(graph, repo, ghrepo)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
77
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
78 commitsUrl = f'https://api.github.com/repos/{githubOwner}/{shortRepoName}/commits?per_page=1'
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
79 GITHUB_CALLS.inc()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
80 resp = yield treq.get(commitsUrl,
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
81 timeout=5,
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
82 headers={
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
83 'User-agent': 'reposync by github.com/drewp',
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
84 'Accept': 'application/vnd.github.v3+json'
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
85 })
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
86 ret = yield treq.json_content(resp)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
87
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
88 if len(ret) < 1:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
89 raise ValueError(f"no commits on {commitsUrl}")
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
90 log.info(f'{repo=} {ret[0]=}')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
91
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
92 author = writeAuthor(graph, ret[0]['author'])
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
93 writeCommit(graph, ghrepo, ret[0], author)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
94
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
95
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
96 def writeGhRepo(graph, repo, ghrepo):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
97 replaceContext(graph, URIRef(ghrepo + '/config'), {
21
cb71722bb75c use pipenv
drewp@bigasterisk.com
parents: 20
diff changeset
98 (repo, RDF.type, EX['Repo']),
19
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
99 (repo, EX['githubRepo'], ghrepo),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
100 (ghrepo, RDF.type, EX['GithubRepo']),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
101 })
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
102
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
103
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
104 def writeCommit(graph, ghrepo, row, author):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
105 new: Set[Triple] = set()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
106
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
107 commit = row['commit']
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
108 latest = URIRef(commit['url'])
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
109 new.add((ghrepo, EX['latestCommit'], latest))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
110
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
111 new.add((latest, RDF.type, EX['GithubCommit']))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
112
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
113 t = parse(commit['author']['date']).astimezone(tzlocal()).isoformat()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
114 new.add((latest, EX['created'], Literal(t)))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
115
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
116 new.add((latest, EX['creator'], author))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
117 new.add((author, EX['foafMail'], Literal(commit['committer']['email'])))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
118 new.add((latest, EX['commitMessage'], Literal(commit['message'])))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
119 new.add((latest, EX['sha'], Literal(row['sha'])))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
120 for p in row['parents']:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
121 new.add((latest, EX['parent'], Literal(p['url'])))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
122
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
123 replaceContext(graph, ghrepo, new)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
124
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
125
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
126 def writeAuthor(graph: PatchableGraph, author: dict) -> URIRef:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
127 uri = URIRef(author['url'])
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
128 replaceContext(
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
129 graph, uri, {
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
130 (uri, RDF.type, EX['GithubAuthor']),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
131 (uri, EX['login'], Literal(author['login'])),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
132 (uri, EX['avatar'], URIRef(author['avatar_url'])),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
133 })
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
134 return uri
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
135
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
136
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
137 @inlineCallbacks
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
138 def update(graph, repos):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
139 for shortRepoName in repos:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
140 uri = URIRef(f'http://bigasterisk.com/repo/{shortRepoName}')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
141 ghrepo = URIRef(uri + '/github')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
142
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
143 now = datetime.datetime.now(tzlocal())
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
144 if lastReadBefore(graph, ghrepo, now, datetime.timedelta(hours=24)):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
145 yield updateOne(graph, uri, ghrepo, shortRepoName)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
146 graph.patchObject(EX['githubUpdates'], ghrepo, EX['lastRead'], newObject=Literal(now))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
147
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
148
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
149 def lastReadBefore(graph, ghrepo, now, ago):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
150 with graph.currentState() as g:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
151 lastRead = g.value(ghrepo, EX['lastRead'])
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
152 return lastRead is None or lastRead.toPython() < now - ago
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
153
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
154
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
155 def githubRepoForPath(p: Path) -> str:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
156 return p.name
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
157
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
158
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
159 def main():
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
160 args = docopt.docopt('''
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
161 Usage:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
162 repo_github_status.py [options]
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
163
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
164 Options:
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
165 -v, --verbose more logging
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
166 ''')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
167 verboseLogging(args['--verbose'])
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
168
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
169 yaml = YAML(typ='safe')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
170 config = yaml.load(open('config.yaml'))
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
171 repos = [githubRepoForPath(Path(row['dir'])) for row in config['hg_repos'] if row['github']]
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
172
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
173 log.info(f'{repos=}')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
174
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
175 class PG2(PatchableGraph, CurrentStateGraphApi):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
176 pass
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
177
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
178 graph = PG2()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
179
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
180 loop_forever_async(lambda first: update(graph, repos), 10, GITHUB_SYNC)
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
181
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
182 class Application(cyclone.web.Application):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
183
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
184 def __init__(self):
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
185 handlers = [
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
186 (r"/()", Index),
20
b59912649fc4 rewrite local hg scanner
drewp@bigasterisk.com
parents: 19
diff changeset
187 (r'/graph/githubRepos', CycloneGraphHandler, {
19
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
188 'masterGraph': graph
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
189 }),
20
b59912649fc4 rewrite local hg scanner
drewp@bigasterisk.com
parents: 19
diff changeset
190 (r'/graph/githubRepos/events', CycloneGraphEventsHandler, {
19
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
191 'masterGraph': graph,
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
192 }),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
193 (r'/metrics', Metrics),
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
194 ]
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
195 cyclone.web.Application.__init__(
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
196 self,
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
197 handlers,
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
198 debug=args['--verbose'],
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
199 )
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
200
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
201 reactor.listenTCP(8000, Application(), interface='::')
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
202 reactor.run()
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
203
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
204
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
205 if __name__ == '__main__':
5751ef191454 read from github into local graph
drewp@bigasterisk.com
parents: 18
diff changeset
206 main()