Skip to content

Commit 06ce11a

Browse files
committed
a lot of bug fixing and optimization. detials in changelog
1 parent 7b37520 commit 06ce11a

File tree

8 files changed

+89
-33
lines changed

8 files changed

+89
-33
lines changed

src/MainWindow.py

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def init_variables(self):
100100
else:
101101
self.stack_main.set_visible_child_name("main")
102102
asyncio.run(self.board_info())
103+
cf.upadet_board_fn = self.board_info
103104
Thread(target=self.startWebsocket).start()
104105

105106
def startWebsocket(self):
@@ -140,10 +141,9 @@ async def board_info(self):
140141
GLib.idle_add(self.lb_board_info.set_text, b_info)
141142

142143
def on_btn_about_clicked(self, b):
143-
self.dialog_about.set_visible(True)
144-
145-
def on_cmb_board_changed(self, c):
146-
GLib.idle_add(asyncio.run(self.ins.board_name.keys))
144+
#https://github.com/pardus/pardus-image-writer/blob/master/src/MainWindow.py#L221
145+
self.dialog_about.run()
146+
self.dialog_about.hide()
147147

148148
def on_btn_install_clicked(self, b):
149149
self.stack_main.set_visible_child_name("wait")
@@ -162,7 +162,7 @@ def on_btn_msg_cancel_clicked(self, b):
162162
self.message_dialog_port.set_visible(False)
163163

164164
def on_btn_msg_ok_clicked(self, b):
165-
asyncio.run(self.ins.add_port_permission(self.message_dialog_port))
165+
asyncio.run(self.pro.add_port_permission())
166166

167167
def on_btn_reset_clicked(self, b):
168168
self.dialog_info.set_visible(True)

src/common/AsyncProc.py

100644100755
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ async def download_data(self, url, path, name):
2828
class CommandRunner:
2929
def __init__(self):
3030
self.l = Log()
31+
self.old_log_c = ""
32+
self.old_log_o = ""
3133

3234
async def run_command(self, command, websocket=None, print_on_ui=None):
33-
self.l.log("Running command: " + command, "i")
35+
3436
process = subprocess.Popen(
3537
command,
3638
shell=True,
@@ -48,17 +50,25 @@ async def run_command(self, command, websocket=None, print_on_ui=None):
4850
break
4951
# Satır sonundaki newline karakterini kaldır
5052
line = line.rstrip()
51-
self.l.log(line, "i")
5253
if print_on_ui:
5354
print_on_ui(line)
5455
output += line + '\n'
5556
if websocket:
5657
await websocket.send(json.dumps({"command": "consoleLog", "log": self.remove_ansi_color_codes(line)+"\n"}))
5758

59+
if output != self.old_log_o or command != self.old_log_c:
60+
#if True:
61+
self.l.log("Command output:\n" + output, "i")
62+
self.l.log("Running command:\n" + command, "i")
63+
self.old_log_c = command
64+
self.old_log_o = output
65+
5866
# Hata çıktısını oku
5967
error = process.stderr.read()
6068
if error:
61-
self.l.log("Subprocces error: " + error.decode(), "e")
69+
self.l.log("Subprocces error: " + error, "e")
70+
#hata her zaman olabilir. isteller dışında da gönderilmesi gerekibilir
71+
await cf.websocket.send(json.dumps({"command": "consoleLog", "log": self.remove_ansi_color_codes(error)+"\n"}))
6272
if cf.is_main_thread_running:
6373
process.terminate()
6474
return output

src/static/commands.py

100644100755
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ class Commands:
1515

1616
deneyap_board = 'lsusb | grep "Turkish Technnology Team Foundation"'
1717

18-
port_user_permission = "sudo adduser "+p.HOME.split("/")[2]+" dialout"
18+
port_user_permission = "pkexec sudo adduser "+p.HOME.split("/")[2]+" dialout"
19+
20+
restart ="/sbin/reboot"
1921

2022

2123
@classmethod
2224
def add_port_permission(self, port):
23-
return "sudo chmod a+rw " + port
25+
return "pkexec sudo chmod a+rw " + port
2426

2527
@classmethod
2628
def compile_code(self, board):
@@ -40,4 +42,15 @@ def search_lib(self, lib):
4042

4143
@classmethod
4244
def download_lib(self, lib, version):
43-
return f"{p.arduino_cli} lib install \"{lib}\"@{version}"
45+
return f"{p.arduino_cli} lib install \"{lib}\"@{version}"
46+
@classmethod
47+
def is_user_in_group(self):
48+
groupname = "dialout"
49+
username = p.HOME.split("/")[2]
50+
with open('/etc/group', 'r') as file:
51+
for line in file:
52+
parts = line.split(':')
53+
print(parts)
54+
if parts[0] == groupname and username in parts[3]:
55+
return True
56+
return False

src/static/configs.py

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class Configs:
33
board = ""
44
is_main_thread_running = True
55
is_websocket_running = True
6+
websocket = None
7+
upadet_board_fn = None
68

79
deneyap_esp="deneyap:esp32:"
810

@@ -13,4 +15,4 @@ class Configs:
1315
deneyapMiniv2 = "dym_mpv20"
1416
deneyapKart1Av2 = "dydk1a_mpv20"
1517

16-
AGENT_VERSION = "1.0.3"
18+
AGENT_VERSION = "1.0.1"

src/utils/Installer.py

100644100755
File mode changed.

src/utils/Process.py

100644100755
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, messageDialog):
1414
self.messageDialog = messageDialog
1515
self.l = Log()
1616

17-
async def compile_code(self, board, code, websocket):
17+
async def compile_code(self, board, code):
1818
cf.board = board
1919
p.file_check(p.deneyap_pro)
2020
os.chdir(p.deneyap_pro)
@@ -23,19 +23,18 @@ async def compile_code(self, board, code, websocket):
2323
os.chdir(p.deneyap_p_f)
2424
bodyToSend = {"command": "cleanConsoleLog",
2525
"log": _("Compiling Code")+"...\n"}
26-
await websocket.send(json.dumps(bodyToSend))
27-
await self.cr.run_command(co.compile_code(cf.deneyap_esp + board), websocket=websocket)
28-
await websocket.send(json.dumps({"command": "consoleLog", "log": _("Compilation done")+"\n"}))
26+
await cf.websocket.send(json.dumps(bodyToSend))
27+
await self.cr.run_command(co.compile_code(cf.deneyap_esp + board), websocket=cf.websocket)
28+
await cf.websocket.send(json.dumps({"command": "consoleLog", "log": _("Compilation done")+"\n"}))
2929

3030

31-
async def compile_upload(self, board, port, code, websocket):
31+
async def compile_upload(self, board, port, code):
3232
cf.port = port
3333
cf.board = board
34-
await self.check_port_permission()
35-
await self.compile_code(board, code, websocket)
36-
37-
await self.cr.run_command(co.upload_code(port, cf.deneyap_esp + board), websocket=websocket)
38-
await websocket.send(json.dumps({"command": "consoleLog", "log": _("Uploading completed")+"\n"}))
34+
if await self.check_port_permission():
35+
await self.compile_code(board, code)
36+
await self.cr.run_command(co.upload_code(port, cf.deneyap_esp + board), websocket=cf.websocket)
37+
#await websocket.send(json.dumps({"command": "consoleLog", "log": _("Uploading completed")+"\n"}))
3938

4039

4140
async def board_infos(self):
@@ -74,11 +73,11 @@ async def download_lib(self, lib, version):
7473
return json.dumps(bodyToSend)
7574

7675
async def check_port_permission(self):
77-
res = await self.cr.run_command(co.check_port_permission(cf.port))
78-
if 'rw' not in res.splitlines()[0].split()[0]:
76+
if not os.access(cf.port, os.W_OK and os.R_OK) or not co.is_user_in_group():
77+
await cf.websocket.send(json.dumps({"command": "consoleLog", "log": _("Compiling rejected. Try again")+"\n"}))
7978
self.messageDialog.set_visible(True)
8079
self.messageDialog.set_markup(
81-
_("You don't have permission to access the port.\nDo you want to give permission?"))
80+
_("You don't have permission to access the port.\nDo you want to give permission?\n\nEnd of the procces your computer restart! Please save your imortant files"))
8281
return False
8382
return True
8483

@@ -92,10 +91,15 @@ async def ui_board_infos(self):
9291
return res
9392

9493
async def add_port_permission(self):
95-
await self.cr.run_command(co.port_user_permission)
96-
await self.cr.run_command(co.add_port_permission(cf.port))
9794
self.messageDialog.set_visible(False)
98-
self.messageDialog.set_markup("")
95+
print("chmod", os.access(cf.port, os.W_OK and os.R_OK))
96+
print("grup", co.is_user_in_group())
97+
if not os.access(cf.port, os.W_OK and os.R_OK):
98+
await self.cr.run_command(co.add_port_permission(cf.port))
99+
if not co.is_user_in_group():
100+
await self.cr.run_command(co.port_user_permission)
101+
102+
await self.cr.run_command(co.restart)
99103

100104
def reset_system(self):
101105
os.system("rm -rf " + p.arduino15_path)

src/utils/socket_con/SerialMonitorWebsocket.py

100644100755
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,21 @@ async def closeSerialMonitor(self) -> None:
126126
self.serialOpen = False
127127

128128
async def serial_log_loop(self):
129-
while self.serialOpen and self.ser is not None:
129+
while self.serialOpen and self.ser != None:
130130
try:
131131
if self.ser.in_waiting > 0:
132132
await self.serialLog()
133133
else:
134-
await asyncio.sleep(0.05)
134+
await asyncio.sleep(0.5)
135135
except serial.SerialException as e:
136136
self.l.log(e, "e")
137137
await asyncio.sleep(1)
138+
#raise e
139+
except Exception as e:
140+
self.l.log(e, "e")
141+
await asyncio.sleep(1)
142+
await self.closeSerialMonitor()
143+
#raise e
138144

139145
async def serialLog(self) -> None:
140146
if self.serialOpen and self.ser != None:

src/utils/socket_con/WebSocket.py

100644100755
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ def __init__(self, pro):
1414
self.l = Log()
1515
self.websocket = None
1616
self.pro = pro
17+
self.board_infos = None
18+
1719
async def start_server(self, url, port):
1820
await websockets.serve(self.mainLoop, url, port)
1921

2022
async def mainLoop(self, websocket, path):
2123
# TODO: kuyruk eklenebilir
2224
self.websocket = websocket
25+
cf.websocket = websocket
26+
print("websocket started")
27+
chck_board = asyncio.create_task(self.check_board())
2328
try:
2429
while cf.is_websocket_running and cf.is_main_thread_running:
2530
body = {"command": None}
@@ -29,6 +34,7 @@ async def mainLoop(self, websocket, path):
2934
body = json.loads(msg)
3035
await self.commandParser(body)
3136
await self.websocket.close()
37+
chck_board.cancel()
3238
self.l.log("Serial Monitor Websocket closed", "i")
3339
except Exception as e:
3440
print("armut")
@@ -45,12 +51,13 @@ async def commandParser(self, body: dict) -> None:
4551
else:
4652
await self.sendResponse()
4753
if command == "upload":
48-
await self.pro.compile_upload(body['board'], body['port'], body["code"], self.websocket)
54+
await self.pro.compile_upload(body['board'], body['port'], body["code"])
4955
elif command == "compile":
5056
#await self.pro.compile_upload(body['board'], body['port'], body["code"])
51-
await self.pro.compile_code(body['board'], body['code'], self.websocket)
57+
await self.pro.compile_code(body['board'], body['code'])
5258
elif command == "getBoards":
5359
res = await self.pro.board_infos()
60+
self.board_infos = res
5461
elif command == "getVersion":
5562
res = await self.pro.get_version()
5663
elif command == "changeVersion":
@@ -70,4 +77,18 @@ async def commandParser(self, body: dict) -> None:
7077
async def sendResponse(self) -> None:
7178
bodyToSend = {"command": "response"}
7279
bodyToSend = json.dumps(bodyToSend)
73-
await self.websocket.send(bodyToSend)
80+
await self.websocket.send(bodyToSend)
81+
82+
async def check_board(self):
83+
while cf.is_websocket_running and cf.is_main_thread_running:
84+
res = await self.pro.board_infos()
85+
if res != None and res != self.board_infos:
86+
print("res", res)
87+
self.board_infos = res
88+
await self.websocket.send(res)
89+
await cf.upadet_board_fn()
90+
else:
91+
await asyncio.sleep(1)
92+
continue
93+
await asyncio.sleep(1)
94+
continue

0 commit comments

Comments
 (0)