-
Notifications
You must be signed in to change notification settings - Fork 1
/
astroarch_tweak_tool.py
171 lines (150 loc) · 6.43 KB
/
astroarch_tweak_tool.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
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
import sys
import os
import subprocess
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
from PySide6.QtCore import QFile, QTimer
from ui_astroarch_tweak_tool import Ui_Form
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.timer = QTimer(self)
self.timer.timeout.connect(self.status)
self.timer.start(1000)
# call function on clicked button and radio button
self.ui.btn_update.clicked.connect(self.btn_update_action)
self.ui.rb_gps_off.clicked.connect(self.rb_gps_off_action)
self.ui.rb_gps_on.clicked.connect(self.rb_gps_on_action)
self.ui.rb_gps_on_ublox.clicked.connect(self.rb_gps_on_ublox_action)
self.ui.rb_blue_off.clicked.connect(self.rb_blue_off_action)
self.ui.rb_blue_on.clicked.connect(self.rb_blue_on_action)
self.ui.rb_ftp_off.clicked.connect(self.rb_ftp_off_action)
self.ui.rb_ftp_on.clicked.connect(self.rb_ftp_on_action)
def btn_update_action(self):
self.ui.lb_update_error.setText("")
print("update")
cmd = "konsole -e '/bin/zsh -i -c \"update-astroarch\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
self.ui.lb_update_error.setText("update error")
self.ui.lb_update_error.setStyleSheet("color:red")
print("error")
else:
print("ok")
def rb_gps_off_action(self):
self.ui.lb_gps_error.setText("")
print("gps off")
cmd = "konsole -e '/bin/zsh -i -c \"gps_off\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
print("error")
else:
print("ok")
def rb_gps_on_action(self):
self.ui.lb_gps_error.setText("")
print("gps on")
cmd = "konsole -e '/bin/zsh -i -c \"gps_on\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
self.ui.lb_gps_error.setText("gps error")
self.ui.lb_gps_error.setStyleSheet("color:red")
print("error")
else:
print("ok")
def rb_gps_on_ublox_action(self):
self.ui.lb_gps_error.setText("")
print("gps on ublox")
cmd = "konsole -e '/bin/zsh -i -c \"gps_ublox_on\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
self.ui.lb_gps_error.setText("gps ublox error")
self.ui.lb_gps_error.setStyleSheet("color:red")
print("error")
else:
print("ok")
def rb_blue_off_action(self):
self.ui.lb_blue_error.setText("")
print("Bluetooh off")
cmd = "konsole -e '/bin/zsh -i -c \"bluetooth_off\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
print("error")
else:
print("ok")
def rb_blue_on_action(self):
self.ui.lb_blue_error.setText("")
print("Bluetooh on")
cmd = "konsole -e '/bin/zsh -i -c \"bluetooth_on\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
self.ui.lb_blue_error.setText("bluetooth error")
self.ui.lb_blue_error.setStyleSheet("color:red")
print("error")
else:
print("ok")
def rb_ftp_off_action(self):
self.ui.lb_ftp_error.setText("")
print("FTP off")
cmd = "konsole -e '/bin/zsh -i -c \"ftp_off\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
print("error")
else:
print("ok")
def rb_ftp_on_action(self):
self.ui.lb_ftp_error.setText("")
print("FTP on")
cmd = "konsole -e '/bin/zsh -i -c \"ftp_on\"'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = proc.communicate()
if proc.returncode or errors:
self.ui.lb_ftp_error.setText("ftp error")
self.ui.lb_ftp_error.setStyleSheet("color:red")
print("error")
else:
print("ok")
def status(self):
# services status
gps_status = os.system('systemctl is-active gpsd')
bluetooh_status = os.system('systemctl is-active bluetooth')
ftp_status = os.system('systemctl is-active vsftpd')
# set radio button gps
with open('/etc/default/gpsd') as gpsd_file:
file = gpsd_file.readlines()
for line in file:
if line.find('ttyACM0') != -1 and gps_status == 0:
self.ui.rb_gps_on_ublox.setChecked(True)
self.ui.lb_gps.setStyleSheet("color: green;")
elif line.find('gps0') != -1 and gps_status == 0:
self.ui.rb_gps_on.setChecked(True)
self.ui.lb_gps.setStyleSheet("color: green;")
if gps_status == 768:
self.ui.rb_gps_off.setChecked(True)
self.ui.lb_gps.setStyleSheet("color: red;")
# set radio button bluetooh
if bluetooh_status == 0:
self.ui.rb_blue_on.setChecked(True)
self.ui.lb_bluetooh.setStyleSheet("color: green;")
else:
self.ui.rb_blue_off.setChecked(True)
self.ui.lb_bluetooh.setStyleSheet("color: red;")
# set radio button ftp
if ftp_status == 0:
self.ui.rb_ftp_on.setChecked(True)
self.ui.lb_ftp.setStyleSheet("color: green;")
else:
self.ui.rb_ftp_off.setChecked(True)
self.ui.lb_ftp.setStyleSheet("color: red;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())