-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
246 lines (187 loc) · 7.95 KB
/
install.py
File metadata and controls
246 lines (187 loc) · 7.95 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# installer for the inigo template.
#
# 24th of Mar 2026
import configobj
import os
import stat
import weeutil.weeutil
import weewx
from weecfg.extension import ExtensionInstaller
from weeutil.config import conditional_merge
VERSION="2.0.19"
InigoDataConfig = {
"skin": "Inigo-Data",
"enable": "True",
}
InigoDictsConfig = {
"skin": "Inigo-Dicts",
"enable": "True",
"report_timing": "@yearly, @createIfMissing",
}
InigoLastConfig = {
"skin": "Inigo-Last",
"enable": "True",
"report_timing": "@daily, @createIfMissing",
}
InigoReportConfigs = {
"Inigo-Data": InigoDataConfig,
"Inigo-Dicts": InigoDictsConfig,
"Inigo-Last": InigoLastConfig,
}
def loader():
return InigoInstaller()
def fatal_error(error_str):
print()
print(error_str)
print()
print()
raise weewx.UnsupportedFeature("Fatal Error")
def is_integer(s):
try:
int(s)
return True
except (ValueError, TypeError) as e:
return False
class InigoInstaller(ExtensionInstaller):
def __init__(self):
config_dict = {
}
self.metric = True
self.rainInInches = False
self.since_hour = -1
super(InigoInstaller, self).__init__(
version=VERSION,
name="Inigo",
description="A skin to feed data to weeWx app",
author="John Smith",
author_email="deltafoxtrot256+InigoPlugin@gmail.com",
config={
"StdReport": InigoReportConfigs
},
files=[
("bin/user",
["bin/user/inigo.py"]),
("skins/Inigo-Data",
["skins/Inigo-Data/inigo-data.json.tmpl",
"skins/Inigo-Data/skin.conf"]),
("skins/Inigo-Dicts",
["skins/Inigo-Dicts/inigo-dicts.json.tmpl",
"skins/Inigo-Dicts/skin.conf"]),
("skins/Inigo-Last",
["skins/Inigo-Last/inigo-last.json.tmpl",
"skins/Inigo-Last/skin.conf"]),
]
)
def process_args(self, args):
args_iter = iter(args)
for arg in args_iter:
if arg == "--since-hour":
arg = next(args_iter, "-1")
if arg != "-1":
if is_integer(arg):
self.since_hour = int(arg)
if not 0 <= self.since_hour <= 23:
fatal_error(f"'{self.since_hour}' isn't valid hour, you need to specify a number between 0 and 23 or leave unset to keep the current setting")
else:
fatal_error(f"{arg} isn't valid hour, you need to specify a number between 0 and 23 or leave unset to keep the current setting")
def configure(self, engine):
if engine.config_dict is None:
fatal_error("engine.config_dict is None, can't continue...")
try:
import numpy as np
np.array([1.0, 2.0, 3.0])
del np
except (ImportError, Exception):
fatal_error(f"The numpy python module wasn't detected, this is required to detect peak daily temperature in real time.\n\nPlease view this wiki page for installation details: https://github.com/evilbunny2008/InigoPlugin/blob/main/README.md")
stdreport_dict = engine.config_dict.get("StdReport", None)
if stdreport_dict is None:
fatal_error("StdReport is None, can't continue...")
data_dir = engine.config_dict.get("WEEWX_ROOT", None)
if data_dir is None or not os.path.isdir(data_dir):
fatal_error("Failed to determine where to store Inigo cache files, you may need to set WEEWX_ROOT in weewx.conf")
uid = os.getuid()
statinfo = os.stat(data_dir)
data_uid = statinfo.st_uid
data_gid = statinfo.st_gid
cache_dir = os.path.join(data_dir, "inigo")
if os.path.exists(cache_dir) and not os.path.isdir(cache_dir):
os.remove(cache_dir)
if not os.path.exists(cache_dir):
os.makedirs(cache_dir, exist_ok=True)
if not os.path.exists(cache_dir):
fatal_error("Failed to create the directory for the InigoService cache files, can't continue...")
desired_mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH | stat.S_ISGID
current_mode = os.stat(cache_dir).st_mode
if current_mode != desired_mode | stat.S_IFDIR:
os.chmod(cache_dir, desired_mode)
statinfo = os.stat(cache_dir)
cache_uid = statinfo.st_uid
cache_gid = statinfo.st_gid
if cache_uid != data_uid or cache_gid != data_gid:
os.chown(cache_dir, data_uid, data_gid)
for fn in os.listdir(cache_dir):
os.chown(os.path.join(cache_dir, fn), data_uid, data_gid)
current_mode = os.stat(cache_dir).st_mode
statinfo = os.stat(cache_dir)
cache_uid = statinfo.st_uid
cache_gid = statinfo.st_gid
if current_mode != desired_mode | stat.S_IFDIR or cache_uid != data_uid or cache_gid != data_gid:
fatal_error("Failed to set the correct permissions for the InigoService cache directory, can't continue...")
old_since_hour = -1
inigo_dict = stdreport_dict.get("Inigo", None)
if inigo_dict is not None:
old_since_hour = int(inigo_dict.get("since_hour", -1))
del stdreport_dict["Inigo"]
inigo_data_dict = stdreport_dict.get("Inigo-Data", None)
if inigo_data_dict is None:
stdreport_dict["Inigo-Data"] = InigoDataConfig
inigo_data_dict = stdreport_dict.get("Inigo-Data")
if "cache_dir" not in inigo_data_dict or inigo_data_dict.get("cache_dir") != cache_dir:
inigo_data_dict["cache_dir"] = cache_dir
if "since_hour" not in inigo_data_dict:
if 0 <= self.since_hour <= 23:
inigo_data_dict["since_hour"] = self.since_hour
else:
inigo_data_dict["since_hour"] = 0
else:
tmpsince = int(inigo_data_dict.get("since_hour", old_since_hour))
if 0 <= self.since_hour <= 23:
if self.since_hour != tmpsince:
inigo_data_dict["since_hour"] = self.since_hour
elif not 0 <= tmpsince <= 23:
inigo_data_dict["since_hour"] = 0
engine_dict = engine.config_dict.get("Engine", None)
if engine_dict is None:
engine.config_dict["Engine"] = {}
engine_dict = engine.config_dict.get("Engine", None)
services_dict = engine_dict.get("Services", None)
if services_dict is None:
engine_dict["Services"] = {}
services_dict = engine_dict.get("Services", None)
things_to_remove = ["user.since", "user.peak_detector.PeakDetectorService", "user.inigo.InigoService"]
for service in list(services_dict):
for thing in things_to_remove:
services = services_dict.get(service, None)
if services is None:
continue
if isinstance(services, str) and services == thing:
del services_dict[service]
elif thing in services:
services.remove(thing)
if len(services) == 1:
services_dict[service] = services[0]
services_dict = engine_dict.get("Services", None)
data_service = "user.inigo.InigoService"
data_services = services_dict.get("data_services", None)
if data_services is None:
services_dict["data_services"] = data_service
elif data_service not in data_services:
if isinstance(data_services, str):
data_services = [data_services, data_service]
else:
data_services.append(data_service)
if engine.dry_run:
engine.printer.out(engine.config_dict)
engine.printer.out("-" * 72)
return False
return True