1114 return [], err |
1114 return [], err |
1115 |
1115 |
1116 clientsList = ast.literal_eval(out.decode("utf-8")) |
1116 clientsList = ast.literal_eval(out.decode("utf-8")) |
1117 return clientsList, "" |
1117 return clientsList, "" |
1118 |
1118 |
|
1119 def enableWebrepl(self, password): |
|
1120 """ |
|
1121 Public method to write the given WebREPL password to the connected device and |
|
1122 modify the start script to start the WebREPL server. |
|
1123 |
|
1124 @param password password needed to authenticate |
|
1125 @type str |
|
1126 @return tuple containing a flag indicating success and an error message |
|
1127 @rtype tuple of (bool, str) |
|
1128 """ |
|
1129 command = """ |
|
1130 def modify_boot(): |
|
1131 import os |
|
1132 |
|
1133 try: |
|
1134 with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f: |
|
1135 found = False |
|
1136 for l in old_f.read().splitlines(): |
|
1137 if 'webrepl' in l: |
|
1138 found = True |
|
1139 if l.startswith('#'): |
|
1140 l = l[1:] |
|
1141 new_f.write(l + '\\n') |
|
1142 if not found: |
|
1143 new_f.write('\\nimport webrepl\\nwebrepl.start()\\n') |
|
1144 |
|
1145 os.remove('/boot.py') |
|
1146 os.rename('/boot.py.tmp', '/boot.py') |
|
1147 except: |
|
1148 pass |
|
1149 |
|
1150 print(True) |
|
1151 |
|
1152 modify_boot() |
|
1153 del modify_boot |
|
1154 """ |
|
1155 |
|
1156 try: |
|
1157 # write config file |
|
1158 config = "PASS = {0}\n".format(repr(password)) |
|
1159 self.putData("/webrepl_cfg.py", config.encode("utf-8")) |
|
1160 except OSError as err: |
|
1161 return False, str(err) |
|
1162 |
|
1163 # modify boot.py |
|
1164 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1165 if err: |
|
1166 return False, err |
|
1167 |
|
1168 return out.decode("utf-8").strip() == "True", "" |
|
1169 |
|
1170 def disableWebrepl(self): |
|
1171 """ |
|
1172 Public method to write the given WebREPL password to the connected device and |
|
1173 modify the start script to start the WebREPL server. |
|
1174 |
|
1175 @return tuple containing a flag indicating success and an error message |
|
1176 @rtype tuple of (bool, str) |
|
1177 """ |
|
1178 command = """ |
|
1179 def modify_boot(): |
|
1180 import os |
|
1181 |
|
1182 try: |
|
1183 with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f: |
|
1184 for l in old_f.read().splitlines(): |
|
1185 if 'webrepl' in l: |
|
1186 if not l.startswith('#'): |
|
1187 l = '#' + l |
|
1188 new_f.write(l + '\\n') |
|
1189 |
|
1190 os.remove('/boot.py') |
|
1191 os.rename('/boot.py.tmp', '/boot.py') |
|
1192 except: |
|
1193 pass |
|
1194 |
|
1195 print(True) |
|
1196 |
|
1197 modify_boot() |
|
1198 del modify_boot |
|
1199 """ |
|
1200 |
|
1201 # modify boot.py |
|
1202 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1203 if err: |
|
1204 return False, err |
|
1205 |
|
1206 return out.decode("utf-8").strip() == "True", "" |
|
1207 |
1119 ################################################################## |
1208 ################################################################## |
1120 ## Methods below implement Bluetooth related methods |
1209 ## Methods below implement Bluetooth related methods |
1121 ################################################################## |
1210 ################################################################## |
1122 |
1211 |
1123 def hasBluetooth(self): |
1212 def hasBluetooth(self): |