57 information</li> |
57 information</li> |
58 <li>getModules: get a list of built-in modules</li> |
58 <li>getModules: get a list of built-in modules</li> |
59 <li>getTime: get the current time</li> |
59 <li>getTime: get the current time</li> |
60 <li>showTime: show the current time of the connected device</li> |
60 <li>showTime: show the current time of the connected device</li> |
61 <li>syncTime: synchronize the time of the connected device</li> |
61 <li>syncTime: synchronize the time of the connected device</li> |
|
62 <li>mipInstall: install a MicroPython package with 'mip'</li> |
|
63 <li>upipInstall: install a MicroPython package with 'upip'</li> |
|
64 <li>getLibPaths: get a list of library paths contained in sys.path</li> |
62 </ul> |
65 </ul> |
63 |
66 |
64 Supported WiFi commands are: |
67 Supported WiFi commands are: |
65 <ul> |
68 <ul> |
66 <li>hasWifi: check, if the board has WiFi functionality</li> |
69 <li>hasWifi: check, if the board has WiFi functionality</li> |
134 self._deviceData = {} |
137 self._deviceData = {} |
135 |
138 |
136 if connected: |
139 if connected: |
137 with contextlib.suppress(OSError): |
140 with contextlib.suppress(OSError): |
138 self._deviceData = self.__getDeviceData() |
141 self._deviceData = self.__getDeviceData() |
|
142 self._deviceData["local_mip"] = ( |
|
143 not self._deviceData["mip"] and not self._deviceData["upip"] |
|
144 ) |
139 self._deviceData["wifi"], self._deviceData["wifi_type"] = self.hasWifi() |
145 self._deviceData["wifi"], self._deviceData["wifi_type"] = self.hasWifi() |
140 self._deviceData["bluetooth"] = self.hasBluetooth() |
146 self._deviceData["bluetooth"] = self.hasBluetooth() |
141 ( |
147 ( |
142 self._deviceData["ethernet"], |
148 self._deviceData["ethernet"], |
143 self._deviceData["ethernet_type"], |
149 self._deviceData["ethernet_type"], |
970 usedSize = totalSize - freeSize |
976 usedSize = totalSize - freeSize |
971 filesystemInfos.append((fs, totalSize, usedSize, freeSize)) |
977 filesystemInfos.append((fs, totalSize, usedSize, freeSize)) |
972 |
978 |
973 return tuple(filesystemInfos) |
979 return tuple(filesystemInfos) |
974 |
980 |
|
981 def ensurePath(self, target): |
|
982 """ |
|
983 Public method to ensure, that the given target path exists. |
|
984 |
|
985 @param target target directory |
|
986 @type str |
|
987 """ |
|
988 pathParts = target.split("/") |
|
989 |
|
990 # handle targets starting with "/" |
|
991 if not pathParts[0]: |
|
992 pathParts.pop(0) |
|
993 pathParts[0] = "/" + pathParts[0] |
|
994 |
|
995 directory = "" |
|
996 for index in range(len(pathParts)): |
|
997 directory += pathParts[index] |
|
998 if not self.exists(directory): |
|
999 self.mkdir(directory) |
|
1000 directory += "/" |
|
1001 |
975 ################################################################## |
1002 ################################################################## |
976 ## board information related methods below |
1003 ## board information related methods below |
977 ################################################################## |
1004 ################################################################## |
978 |
1005 |
979 def __getDeviceData(self): |
1006 def __getDeviceData(self): |
1015 |
1042 |
1016 try: |
1043 try: |
1017 res['mpy_version'] = '.'.join((str(i) for i in sys.implementation.version)) |
1044 res['mpy_version'] = '.'.join((str(i) for i in sys.implementation.version)) |
1018 except AttributeError: |
1045 except AttributeError: |
1019 res['mpy_version'] = 'unknown' |
1046 res['mpy_version'] = 'unknown' |
|
1047 |
|
1048 if hasattr(sys.implementation, '_mpy'): |
|
1049 res['mpy_file_version'] = sys.implementation._mpy & 0xff |
|
1050 elif hasattr(sys.implementation, 'mpy'): |
|
1051 res['mpy_file_version'] = sys.implementation.mpy & 0xff |
|
1052 else: |
|
1053 res['mpy_file_version'] = 0 |
1020 |
1054 |
1021 try: |
1055 try: |
1022 import pimoroni |
1056 import pimoroni |
1023 res['mpy_variant'] = 'Pimoroni Pico' |
1057 res['mpy_variant'] = 'Pimoroni Pico' |
1024 try: |
1058 try: |
1320 """.format( |
1354 """.format( |
1321 repr(packages) |
1355 repr(packages) |
1322 ) |
1356 ) |
1323 return self._interface.execute(command, mode=self._submitMode, timeout=60000) |
1357 return self._interface.execute(command, mode=self._submitMode, timeout=60000) |
1324 |
1358 |
1325 def mipInstall(self, package, version, mpy): |
1359 def mipInstall(self, package, index=None, target=None, version=None, mpy=True): |
1326 """ |
1360 """ |
1327 Public method to install packages using 'mip'. |
1361 Public method to install packages using 'mip'. |
1328 |
1362 |
1329 @param package package name |
1363 @param package package name |
1330 @type str |
1364 @type str |
1331 @param version package version |
1365 @param index URL of the package index to be used (defaults to None) |
1332 @type str |
1366 @type str (optional) |
1333 @param mpy flag indicating to install as '.mpy' file |
1367 @param target target directory on the device (defaults to None) |
1334 @type bool |
1368 @type str (optional) |
|
1369 @param version package version (defaults to None) |
|
1370 @type str (optional) |
|
1371 @param mpy flag indicating to install as '.mpy' file (defaults to True) |
|
1372 @type bool (optional) |
1335 @return tuple containing the command output and errors |
1373 @return tuple containing the command output and errors |
1336 @return tuple of (str, str) |
1374 @return tuple of (str, str) |
1337 """ |
1375 """ |
1338 parameterStr = repr(package) |
1376 parameterStr = repr(package) |
|
1377 if index: |
|
1378 parameterStr += ", index={0}".format(repr(index)) |
|
1379 if target: |
|
1380 parameterStr += ", target={0}".format(repr(target)) |
1339 if version: |
1381 if version: |
1340 parameterStr += ", version={0}".format(repr(version)) |
1382 parameterStr += ", version={0}".format(repr(version)) |
1341 if not mpy: |
1383 if not mpy: |
1342 parameterStr += ", mpy=False" |
1384 parameterStr += ", mpy=False" |
1343 |
1385 |
1350 del mip_install |
1392 del mip_install |
1351 """.format( |
1393 """.format( |
1352 parameterStr |
1394 parameterStr |
1353 ) |
1395 ) |
1354 return self._interface.execute(command, mode=self._submitMode, timeout=60000) |
1396 return self._interface.execute(command, mode=self._submitMode, timeout=60000) |
|
1397 |
|
1398 def getLibPaths(self): |
|
1399 """ |
|
1400 Public method to get the list of library paths contained in 'sys.path'. |
|
1401 |
|
1402 @return list of library paths |
|
1403 @rtype list of str |
|
1404 @exception OSError raised to indicate an issue with the device |
|
1405 """ |
|
1406 command = """ |
|
1407 def lib_paths(): |
|
1408 import sys |
|
1409 print([p for p in sys.path if p.endswith('/lib')]) |
|
1410 |
|
1411 lib_paths() |
|
1412 del lib_paths |
|
1413 """ |
|
1414 out, err = self._interface.execute(command, mode=self._submitMode) |
|
1415 if err: |
|
1416 raise OSError(self._shortError(err)) |
|
1417 |
|
1418 return ast.literal_eval(out.decode("utf-8")) |
1355 |
1419 |
1356 ################################################################## |
1420 ################################################################## |
1357 ## Methods below implement WiFi related methods |
1421 ## Methods below implement WiFi related methods |
1358 ################################################################## |
1422 ################################################################## |
1359 |
1423 |