/
apps.py
109 lines (97 loc) · 3.47 KB
/
apps.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
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
import logging
import os
import jnius_config
from django.apps import AppConfig
from django.conf import settings
from simccs_maptool import datasets, simccs_helper
logger = logging.getLogger(__name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
class Settings:
WEBPACK_LOADER = {
"SIMCCS_MAPTOOL": {
"BUNDLE_DIR_NAME": "simccs_maptool/dist/", # must end with slash
"STATS_FILE": os.path.join(
BASE_DIR,
"static",
"simccs_maptool",
"dist",
"webpack-stats.json",
),
}
}
class MapToolConfig(AppConfig):
name = "simccs_maptool"
label = "simccs_maptool"
verbose_name = "Map Tool"
url_prefix = "maptool"
url_app_name = label
app_order = 20
url_home = url_app_name + ":home"
fa_icon_class = "fa-map"
app_description = """
SimCCS Map Tool.
"""
settings = Settings()
nav = [
{
"label": "Map Tool",
"icon": "fa fa-map",
"url": "simccs_maptool:home",
"active_prefixes": ["$"],
},
{
"label": "Build",
"icon": "fa fa-tools",
"url": "simccs_maptool:projects",
"active_prefixes": ["build"],
},
{
"label": "Documentation Links",
"icon": "fa fa-question",
"url": "simccs_maptool:help",
"active_prefixes": ["help"],
},
]
def ready(self):
logger.info("MapToolConfig.ready() called")
init_pyjnius()
try:
# get path of Lower48US dataset and set it as a cached cost surface
# on simccs_helper note: dataset may not exist, need to check
lower48_dir = datasets.get_dataset_dir(datasets.LOWER48US_DATASET_ID)
simccs_helper.register_cost_surface_data_cache(lower48_dir)
except Exception as e:
logger.warning("Unable to register Lower48US cost surface cache: " + str(e))
def merge_settings(self, settings_module):
WEBPACK_LOADER = getattr(settings_module, "WEBPACK_LOADER", {})
WEBPACK_LOADER.update(Settings.WEBPACK_LOADER)
settings_module.WEBPACK_LOADER = WEBPACK_LOADER
def init_pyjnius():
if not jnius_config.vm_running:
if "JAVA_HOME" not in os.environ:
logger.info(
"'JAVA_HOME' environment variable missing, "
"trying to get from settings.py"
)
os.environ["JAVA_HOME"] = settings.JAVA_HOME
logger.info("JAVA_HOME set to '{}'".format(os.environ["JAVA_HOME"]))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
jnius_config.add_options("-Djava.awt.headless=true")
DEFAULT_JAVA_OPTIONS = ("-Xmx4g",)
java_options = getattr(settings, "MAPTOOL_SETTINGS", {}).get(
"JAVA_OPTIONS", DEFAULT_JAVA_OPTIONS
)
if isinstance(java_options, list) or isinstance(java_options, tuple):
jnius_config.add_options(*java_options)
else:
jnius_config.add_options(java_options)
jnius_config.set_classpath(
os.path.join(BASE_DIR, "simccs", "lib", "SimCCS.jar"),
os.path.join(BASE_DIR, "simccs", "lib", "maptool.jar"),
)
logger.info(
"Initialized jnius with classpath={}, options={}".format(
jnius_config.get_classpath(), jnius_config.get_options()
)
)
import jnius # noqa