@@ -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.\n Do you want to give permission?" ))
80+ _ ("You don't have permission to access the port.\n Do you want to give permission?\n \n End 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 )
0 commit comments