src/eric7/MicroPython/Devices/RP2040Devices.py

branch
mpy_network
changeset 10022
a95800b414b7
parent 9989
286c2a21f36f
child 10069
435cc5875135
equal deleted inserted replaced
10021:a71f50b3a503 10022:a95800b414b7
1170 return [], err 1170 return [], err
1171 1171
1172 clientsList = ast.literal_eval(out.decode("utf-8")) 1172 clientsList = ast.literal_eval(out.decode("utf-8"))
1173 return clientsList, "" 1173 return clientsList, ""
1174 1174
1175 def enableWebrepl(self, password):
1176 """
1177 Public method to write the given WebREPL password to the connected device and
1178 modify the start script to start the WebREPL server.
1179
1180 @param password password needed to authenticate
1181 @type str
1182 @return tuple containing a flag indicating success and an error message
1183 @rtype tuple of (bool, str)
1184 """
1185 command = """
1186 def modify_boot():
1187 import os
1188
1189 try:
1190 with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f:
1191 found = False
1192 for l in old_f.read().splitlines():
1193 if 'webrepl' in l:
1194 found = True
1195 if l.startswith('#'):
1196 l = l[1:]
1197 new_f.write(l + '\\n')
1198 if not found:
1199 new_f.write('\\nimport webrepl\\nwebrepl.start()\\n')
1200
1201 os.remove('/boot.py')
1202 os.rename('/boot.py.tmp', '/boot.py')
1203 except:
1204 pass
1205
1206 print(True)
1207
1208 modify_boot()
1209 del modify_boot
1210 """
1211
1212 if self._deviceData["wifi_type"] == "picow":
1213 config = "PASS = {0}\n".format(repr(password))
1214 else:
1215 return False, self.tr("WebREPL is not supported on this device.")
1216
1217 try:
1218 # write config file
1219 self.putData("/webrepl_cfg.py", config.encode("utf-8"))
1220 except OSError as err:
1221 return False, str(err)
1222
1223 # modify boot.py
1224 out, err = self.executeCommands(command, mode=self._submitMode)
1225 if err:
1226 return False, err
1227
1228 return out.decode("utf-8").strip() == "True", ""
1229
1230 def disableWebrepl(self):
1231 """
1232 Public method to write the given WebREPL password to the connected device and
1233 modify the start script to start the WebREPL server.
1234
1235 @return tuple containing a flag indicating success and an error message
1236 @rtype tuple of (bool, str)
1237 """
1238 command = """
1239 def modify_boot():
1240 import os
1241
1242 try:
1243 with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f:
1244 for l in old_f.read().splitlines():
1245 if 'webrepl' in l:
1246 if not l.startswith('#'):
1247 l = '#' + l
1248 new_f.write(l + '\\n')
1249
1250 os.remove('/boot.py')
1251 os.rename('/boot.py.tmp', '/boot.py')
1252 except:
1253 pass
1254
1255 print(True)
1256
1257 modify_boot()
1258 del modify_boot
1259 """
1260
1261 # modify boot.py
1262 out, err = self.executeCommands(command, mode=self._submitMode)
1263 if err:
1264 return False, err
1265
1266 return out.decode("utf-8").strip() == "True", ""
1267
1175 ################################################################## 1268 ##################################################################
1176 ## Methods below implement Ethernet related methods 1269 ## Methods below implement Ethernet related methods
1177 ################################################################## 1270 ##################################################################
1178 1271
1179 def hasEthernet(self): 1272 def hasEthernet(self):

eric ide

mercurial