32 on the file system of a connected MicroPython device, for getting and setting |
32 on the file system of a connected MicroPython device, for getting and setting |
33 the time on the board and getting board related data. Supported file system |
33 the time on the board and getting board related data. Supported file system |
34 commands are: |
34 commands are: |
35 <ul> |
35 <ul> |
36 <li>cd: change directory</li> |
36 <li>cd: change directory</li> |
37 <li>fileSystemInfo: get information about the file system |
37 <li>exists: test the existence of a file or directory on the device</li> |
|
38 <li>fileSystemInfo: get information about the file system</li> |
38 <li>get: get a file from the connected device</li> |
39 <li>get: get a file from the connected device</li> |
39 <li>getData: read data of a file of the connected device</li> |
40 <li>getData: read data of a file of the connected device</li> |
40 <li>lls: directory listing with meta data</li> |
41 <li>lls: directory listing with meta data</li> |
41 <li>ls: directory listing</li> |
42 <li>ls: directory listing</li> |
42 <li>mkdir: create a new directory</li> |
43 <li>mkdir: create a new directory</li> |
43 <li>put: copy a file to the connected device</li> |
44 <li>put: copy a file to the connected device</li> |
44 <li>putData: write data to a file of the connected device</li> |
45 <li>putData: write data to a file of the connected device</li> |
45 <li>pwd: get the current directory</li> |
46 <li>pwd: get the current directory</li> |
46 <li>rm: remove a file from the connected device</li> |
47 <li>rm: remove a file from the connected device</li> |
47 <li>rmdir: remove an empty directory</li> |
48 <li>rmdir: remove an empty directory</li> |
48 <li>rmrf: remove a file/directory recursively (like 'rm -rf' in bash) |
49 <li>rmrf: remove a file/directory recursively (like 'rm -rf' in bash)</li> |
49 </ul> |
50 </ul> |
50 |
51 |
51 Supported non file system commands are: |
52 Supported non file system commands are: |
52 <ul> |
53 <ul> |
53 <li>getBoardData: get information about the connected board</li> |
54 <li>getBoardData: get information about the connected board</li> |
475 return self.tr("Detected an error without indications.") |
476 return self.tr("Detected an error without indications.") |
476 |
477 |
477 ################################################################## |
478 ################################################################## |
478 ## Methods below implement the file system commands |
479 ## Methods below implement the file system commands |
479 ################################################################## |
480 ################################################################## |
|
481 |
|
482 def exists(self, pathname): |
|
483 """ |
|
484 Public method to check the existence of a file or directory. |
|
485 |
|
486 @param pathname name of the path to check |
|
487 @type str |
|
488 @return flag indicating the existence |
|
489 @rtype bool |
|
490 @exception OSError raised to indicate an issue with the device |
|
491 """ |
|
492 command = """ |
|
493 import os as __os_ |
|
494 try: |
|
495 __os_.stat({0}) |
|
496 print(True) |
|
497 except OSError: |
|
498 print(False) |
|
499 del __os_ |
|
500 """.format( |
|
501 repr(pathname) |
|
502 ) |
|
503 out, err = self._interface.execute(command, mode=self._submitMode) |
|
504 if err: |
|
505 raise OSError(self._shortError(err)) |
|
506 return out.strip() == b"True" |
480 |
507 |
481 def ls(self, dirname=""): |
508 def ls(self, dirname=""): |
482 """ |
509 """ |
483 Public method to get a directory listing of the connected device. |
510 Public method to get a directory listing of the connected device. |
484 |
511 |