-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·56 lines (44 loc) · 1.12 KB
/
run.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
#!/usr/bin/env python
import sys
import textwrap
from gitAggregate import app, loop, query_db
usage = textwrap.dedent("""\
Usage: ./run.py <command> [<args>]
Commands:
listen [port no] Listens by default on 8888
query [author] Returns commits performed by author""")
def listen(port):
"""
Receives list containg local port to listen on.
Listens on local port and runs indefinitely.
"""
if not port:
port = 8888
else:
port = port[0]
app.listen(port)
loop.start()
def run_command(command):
"""
Switch based on given command line argument.
Returns refernce to function that is to be run.
"""
return {
'query' : query,
'listen': listen,
}.get(command, None)
def query(author):
if not author:
print usage
return
query_db.get_by_author(author)
if __name__ == "__main__":
args = sys.argv[1:]
if not args:
print usage
else:
foo = run_command(args[0])
if foo is None:
print usage
else:
foo(args[1:])