-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.py
executable file
·72 lines (64 loc) · 1.62 KB
/
tracker.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
#!/usr/bin/env python3
from model import *
VERSION += '.0'
__version__ = VERSION
def start(hike='custom'):
'''Start the database connection, creating the tables and configuring if necessary'''
from os.path import exists, expanduser
hike = expanduser(hike + '.hike')
db.Entity.metadata.bind = 'sqlite:///%s' % hike
if not exists(hike):
from convert import load
db.Entity.metadata.create_all()
hike = hike.replace('.hike', '.conf')
load(hike)
def save():
db.session.commit()
def all(type):
'''Shortcut to a list of specified hike objects'''
types = {'b':Base, 'r':Route, 't':Team}
t = type[0].lower()
return types[t].query.all()
def get(tname):
'''Shortcut to getting hike objects by name'''
type = tname[0].lower()
name = tname[1:]
types = {'b':Base, 'r':Route, 't':Team}
return types[type].get(name)
def get_all(type=None):
'''Load all objects into global namespace'''
types = {'b':Base, 'r':Route, 't':Team}
if type:
t = type[0].lower()
for i in all(t):
tname = t + i.name
line = '%s = get("%s")' % (tname, tname)
exec(line, globals())
else:
for t in types:
get_all(t)
def base_report(base, filename=None):
if filename:
f = open(filename)
else:
from sys import stdin
f = stdin
for line in f.readlines():
kwargs = {}
args = [base]
for arg in line.split():
if '=' in arg:
k,v = arg.split('=')
kwargs[k] = v
else:
args += [arg]
try:
Report(*args, **kwargs)
except Exception as e:
print(args, kwargs, e)
if __name__ == '__main__':
from os import environ as _environ
_environ["PYTHONINSPECT"] = "1"
from sys import argv
if len(argv) >= 2:
start(argv[1][:-5])