-
Notifications
You must be signed in to change notification settings - Fork 3
/
freeze.py
50 lines (40 loc) · 1.55 KB
/
freeze.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
from flask_frozen import Freezer
from app import app
import os
import kipoi
from tqdm import tqdm
from app.models.cache import cache
from app.models.views import get_view
# override the database memcache
cache.init_app(app, config={'CACHE_TYPE': 'simple'})
# always use relative URL's
if os.environ.get('FREEZER_RELATIVE_URLS'):
print("Using FREEZER_RELATIVE_URLS: {}".format(os.environ.get('FREEZER_RELATIVE_URLS')))
app.config['FREEZER_RELATIVE_URLS'] = eval(os.environ.get('FREEZER_RELATIVE_URLS'))
# add also a differnet base_URL
if os.environ.get('FREEZER_BASE_URL'):
print("Using FREEZER_BASE_URL: {}".format(os.environ.get('FREEZER_BASE_URL')))
app.config['FREEZER_BASE_URL'] = os.environ.get('FREEZER_BASE_URL')
# http://pythonhosted.org/Frozen-Flask/#api-reference
freezer = Freezer(app,
# with_no_argument_rules=False
# ignore all other url's
log_url_for=False)
@freezer.register_generator
def all_urls():
df = kipoi.get_source("kipoi").list_models()
model = df.model
urls = set()
for m in model:
while m:
urls.add(m)
m = os.path.dirname(m)
groups = {x for x in urls if get_view(x, df)[0] == "group_list"}
# exclude the final models
groups = groups - set(model)
return ["/", "/groups/"] + ["/groups/{0}/".format(x) for x in groups] + ["/models/{0}/".format(x) for x in urls]
if __name__ == '__main__':
urls = list(freezer.all_urls())
for x in tqdm(freezer.freeze_yield(), total=len(urls)):
pass
print("Done!")