-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstartup.py
More file actions
119 lines (101 loc) · 3.28 KB
/
startup.py
File metadata and controls
119 lines (101 loc) · 3.28 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
#!/usr/bin/env python3
# This file is part of OpenPlotter.
# Copyright (C) 2022 by Sailoog <https://github.com/openplotter/openplotter-pypilot>
#
# Openplotter is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
# Openplotter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
import os, sys, subprocess
from openplotterSettings import language
from openplotterSettings import platform
from openplotterSignalkInstaller import connections
class Start():
def __init__(self, conf, currentLanguage):
self.conf = conf
self.initialMessage = ''
def start(self):
green = ''
black = ''
red = ''
return {'green': green,'black': black,'red': red}
class Check():
def __init__(self, conf, currentLanguage):
self.conf = conf
self.platform = platform.Platform()
currentdir = os.path.dirname(os.path.abspath(__file__))
language.Language(currentdir,'openplotter-pypilot',currentLanguage)
self.initialMessage = _('Checking pypilot...')
def check(self):
green = ''
black = ''
red = ''
def active(name):
return not os.system('systemctl is-active ' + name)
def addgreen(n):
nonlocal green
if green:
n = ' | ' + n
green += n
def addred(n):
nonlocal red
if red:
n = '\n ' + n
red += n
def addblack(n):
nonlocal black
if black:
n = ' | ' + n
black += n
#access
skConnections = connections.Connections('PYPILOT')
result = skConnections.checkConnection()
if result[0] == 'pending' or result[0] == 'error' or result[0] == 'repeat' or result[0] == 'permissions':
addred(result[1])
if result[0] == 'approved' or result[0] == 'validated':
token = self.conf.get('PYPILOT', 'token')
try:
file = open(self.conf.home+'/.pypilot/signalk-token', 'r')
token2 = file.read()
token2 = token2.rstrip()
file.close()
if token != token2:
file = open(self.conf.home+'/.pypilot/signalk-token', 'w')
file.write(token)
file.close()
except:
file = open(self.conf.home+'/.pypilot/signalk-token', 'w')
file.write(token)
file.close()
addblack(_('Access to Signal K server validated'))
#services status
running = ' ' + _('running')
notrunning = ' ' + _('not running')
if active('pypilot'):
if active('pypilot_boatimu'):
addred(_('both pypilot and pypilot_boatimu services are running'))
else:
addgreen('pypilot' + running)
elif active('pypilot_boatimu'):
addgreen('pypilot_boatimu' + running)
if active('openplotter-pypilot-read'):
addgreen('openplotter-pypilot-read' + running)
else:
addred('openplotter-pypilot-read' + notrunning)
else:
addblack('pypilot' + notrunning)
def showservice(name):
if active(name):
addgreen(name + running)
else:
addblack(name + notrunning)
showservice('pypilot_web')
showservice('pypilot_hat')
return {'green': green,'black': black,'red': red}