-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py.erb
118 lines (100 loc) · 4.08 KB
/
app.py.erb
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import os
from flask import Flask, request
from werkzeug.contrib.cache import RedisCache, FileSystemCache
from flask_caching import Cache
from pkg_resources import resource_filename
from MyCapytain.resources.prototypes.cts.inventory import CtsTextInventoryCollection as TextInventoryCollection, CtsTextInventoryMetadata as PrototypeTextInventory
from MyCapytain.resolvers.utils import CollectionDispatcher
from capitains_nautilus.cts.resolver import NautilusCTSResolver
from flask_nemo import Nemo
from flask_nemo.chunker import level_grouper
from capitains_nautilus.flask_ext import FlaskNautilus
from cts_leipzig_ui import CTSLeipzigUI, scheme_grouper
d = "<%= @data_root %>"
#
tic = TextInventoryCollection()
latin = PrototypeTextInventory("urn:perseus:latinLit", parent=tic)
latin.set_label("Classical Latin", "eng")
latin.set_label("Latin Classique", "fre")
farsi = PrototypeTextInventory("urn:perseus:farsiLit", parent=tic)
farsi.set_label("Farsi", "eng")
farsi.set_label("Persan", "fre")
gc = PrototypeTextInventory("urn:perseus:greekLit", parent=tic)
gc.set_label("Ancient Greek", "eng")
gc.set_label("Grec Ancien", "fre")
psci = PrototypeTextInventory("urn:perseus:pdlpsci", parent=tic)
psci.set_label("Political Science", "eng")
psci.set_label("Sciences Politiques", "fre")
pdlrefwk = PrototypeTextInventory("urn:perseus:pdlrefwk", parent=tic)
pdlrefwk.set_label("Reference Work", "eng")
pdlrefwk.set_label("Oeuvres de référence", "fre")
hebrew = PrototypeTextInventory("urn:perseus:ancJewLit", parent=tic)
hebrew.set_label("Classical Hebrew and Jewish Aramaic", "eng")
http_cache = Cache(config={'CACHE_TYPE': "redis", "CACHE_REDIS_HOST": "<%= scope.lookupvar('capitains::redis_host') %>", "CACHE_DEFAULT_TIMEOUT": 0})
nautilus_cache = RedisCache("<%= scope.lookupvar('capitains::redis_host') %>", port=6379, default_timeout=0)
#http_cache = Cache(config={'CACHE_TYPE': "filesystem", "CACHE_DIR": "<%= scope.lookupvar('capitains::cache_dir') %>", "CACHE_DEFAULT_TIMEOUT": 28800})
#nautilus_cache = FileSystemCache("<%= scope.lookupvar('capitains::cache_dir') %>", threshold=10000, default_timeout=28800)
dispatcher = CollectionDispatcher(tic)
@dispatcher.inventory("urn:perseus:latinLit")
def dispatchLatinLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:latinLit:"):
return True
return False
@dispatcher.inventory("urn:perseus:farsiLit")
def dispatchfFarsiLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:farsiLit:"):
return True
return False
@dispatcher.inventory("urn:perseus:greekLit")
def dispatchGreekLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:greekLit:"):
return True
return False
@dispatcher.inventory("urn:perseus:pdlpsci")
def dispatchPSCILit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:pdlpsci:"):
return True
return False
@dispatcher.inventory("urn:perseus:pdlrefwk")
def dispatchREFWKLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:pdlrefwk:"):
return True
return False
@dispatcher.inventory("urn:perseus:ancJewLit")
def dispatchAncJewLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:ancJewLit:"):
return True
return False
resolver = NautilusCTSResolver(
[os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))],
dispatcher=dispatcher,
cache=nautilus_cache
)
app = Flask("Nautilus")
nautilus = FlaskNautilus(
app=app,
prefix="/api",
name="nautilus",
resolver=resolver,
flask_caching=http_cache
)
# We set up Nemo
nemo = Nemo(
app=app,
name="nemo",
base_url="",
cache=http_cache,
resolver=resolver,
chunker={
"default": scheme_grouper
},
plugins=[CTSLeipzigUI("<%= scope.lookupvar('capitains::analytics_id') %>")],
transform={
"default": resource_filename("cts_leipzig_ui","data/assets/static/xslt/epidocShort.xsl")
},
)
http_cache.init_app(app)
#app.debug = True
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')