Sun, 21 Jul 2019 19:54:15 +0200
MicroPython: started to implement the file manager widget.
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing some file system commands for MicroPython. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | from __future__ import unicode_literals |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
12 | import ast |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
13 | import time |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
14 | import stat |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
15 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
16 | from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QThread |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
17 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
18 | from .MicroPythonSerialPort import MicroPythonSerialPort |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | class MicroPythonFileSystem(QObject): |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | Class implementing some file system commands for MicroPython. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Some FTP like commands are provided to perform operations on the file |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | system of a connected MicroPython device. Supported commands are: |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | <ul> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | <li>ls: directory listing</li> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | <li>lls: directory listing with meta data</li> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | <li>cd: change directory</li> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | <li>pwd: get the current directory</li> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | <li>put: copy a file to the connected device</li> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | <li>get: get a file from the connected device</li> |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
34 | <li>rm: remove a file from the connected device</li> |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
35 | <li>mkdir: create a new directory</li> |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
36 | <li>rmdir: remove an empty directory</li> |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | </ul> |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | def __init__(self, parent=None): |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | Constructor |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | @param parent reference to the parent object |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | @type QObject |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | super(MicroPythonFileSystem, self).__init__(parent) |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
47 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
48 | self.__serial = None |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
50 | def setSerial(self, serial): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
51 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
52 | Public method to set the serial port to be used. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
53 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
54 | Note: The serial port should be initialized and open already. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
55 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
56 | @param serial open serial port |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
57 | @type MicroPythonSerialPort |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
58 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
59 | self.__serial = serial |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
60 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
61 | def __rawOn(self): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
62 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
63 | Private method to switch the connected device to 'raw' mode. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
64 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
65 | Note: switching to raw mode is done with synchroneous writes. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
66 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
67 | if not self.__serial: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
68 | return |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
69 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
70 | rawReplMessage = b"raw REPL; CTRL-B to exit\r\n" |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
71 | softRebootMessage = b"soft reboot\r\n" |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
72 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
73 | self.__serial.write(b"\x02") # end raw mode if required |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
74 | self.__serial.waitForBytesWritten() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
75 | for _i in range(3): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
76 | # CTRL-C three times to break out of loops |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
77 | self.__serial.write(b"\r\x03") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
78 | self.__serial.waitForBytesWritten() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
79 | QThread.msleep(10) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
80 | self.__serial.readAll() # read all data and discard it |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
81 | self.__serial.write(b"\r\x01") # send CTRL-A to enter raw mode |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
82 | self.__serial.readUntil(rawReplMessage) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
83 | self.__serial.write(b"\x04") # send CTRL-D to soft reset |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
84 | self.__serial.readUntil(softRebootMessage) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
85 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
86 | # some MicroPython devices seem to need to be convinced in some |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
87 | # special way |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
88 | data = self.__serial.readUntil(rawReplMessage) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
89 | if not data.endswith(rawReplMessage): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
90 | self.__serial.write(b"\r\x01") # send CTRL-A again |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
91 | self.__serial.readUntil(rawReplMessage) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
92 | self.__serial.readAll() # read all data and discard it |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
93 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
94 | def __rawOff(self): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
95 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
96 | Private method to switch 'raw' mode off. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
97 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
98 | if self.__serial: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
99 | self.__serial.write(b"\x02") # send CTRL-B to cancel raw mode |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
100 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
101 | def __execute(self, commands): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
102 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
103 | Private method to send commands to the connected device and return the |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
104 | result. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
105 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
106 | If no serial connection is available, empty results will be returned. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
107 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
108 | @param commands list of commands to be executed |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
109 | @type str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
110 | @return tuple containing stdout and stderr output of the device |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
111 | @rtype tuple of (bytes, bytes) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
112 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
113 | if not self.__serial: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
114 | return b"", b"" |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
115 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
116 | result = bytearray() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
117 | err = b"" |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
118 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
119 | self.__rawOn() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
120 | QThread.msleep(10) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
121 | for command in commands: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
122 | if command: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
123 | commandBytes = command.encode("utf-8") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
124 | self.__serial.write(commandBytes + b"\x04") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
125 | # read until prompt |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
126 | response = self.__serial.readUntil(b"\x04>") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
127 | # split stdout, stderr |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
128 | out, err = response[2:-2].split(b"\x04") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
129 | result += out |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
130 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
131 | return b"", err |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
132 | QThread.msleep(10) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
133 | self.__rawOff() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
134 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
135 | return bytes(result), err |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
136 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
137 | def __shortError(self, error): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
138 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
139 | Private method to create a shortened error message. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
140 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
141 | @param error verbose error message |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
142 | @type bytes |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
143 | @return shortened error message |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
144 | @rtype str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
145 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
146 | if error: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
147 | decodedError = error.decode("utf-8") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
148 | try: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
149 | return decodedError.split["\r\n"][-2] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
150 | except Exception: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
151 | return decodedError |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
152 | return self.tr("Detected an error without indications.") |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
153 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
154 | ################################################################## |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
155 | ## Methods below implement the file system commands |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
156 | ################################################################## |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
157 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
158 | def ls(self, dirname=""): |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | Public method to get a directory listing of the connected device. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
162 | @param dirname name of the directory to be listed |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
163 | @type str |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | @return tuple containg the directory listing |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | @rtype tuple of str |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
166 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | """ |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
168 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
169 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
170 | "print(os.listdir('{0}'))".format(dirname), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
171 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
172 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
173 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
174 | raise IOError(self.__shortError(err)) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
175 | return ast.literal_eval(out.decode("utf-8")) |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
177 | def lls(self, dirname=""): |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | Public method to get a long directory listing of the connected device |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | including meta data. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
182 | @param dirname name of the directory to be listed |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
183 | @type str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
184 | @return list containing the the directory listing with tuple entries |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
185 | of the name and and a tuple of mode, size and time |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | @rtype tuple of str |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
187 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | """ |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
189 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
190 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
191 | "\n".join([ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
192 | "def stat(filename):", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
193 | " try:", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
194 | " rstat = os.lstat(filename)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
195 | " except:", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
196 | " rstat = os.stat(filename)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
197 | " return tuple(rstat)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
198 | ]), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
199 | "\n".join([ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
200 | "def listdir_stat(dirname):", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
201 | " try:", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
202 | " files = os.listdir(dirname)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
203 | " except OSError:", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
204 | " return []", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
205 | " if dirname in ('', '/'):", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
206 | " return list((f, stat(f)) for f in files)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
207 | " return list((f, stat(dirname + '/' + f)) for f in files)", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
208 | ]), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
209 | "print(listdir_stat('{0}'))".format(dirname), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
210 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
211 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
212 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
213 | raise IOError(self.__shortError(err)) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
214 | fileslist = ast.literal_eval(out.decode("utf-8")) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
215 | return [(f, (s[0], s[6], s[8])) for f, s in fileslist] |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
217 | def cd(self, dirname): |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | Public method to change the current directory on the connected device. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
221 | @param dirname directory to change to |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | @type str |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
223 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | """ |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
225 | assert dirname |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
226 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
227 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
228 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
229 | "os.chdir('{0}')".format(dirname), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
230 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
231 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
232 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
233 | raise IOError(self.__shortError(err)) |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | def pwd(self): |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | Public method to get the current directory of the connected device. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | @return current directory |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | @rtype str |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
241 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | """ |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
243 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
244 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
245 | "print(os.getcwd())", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
246 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
247 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
248 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
249 | raise IOError(self.__shortError(err)) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
250 | return out.decode("utf-8").strip() |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
251 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
252 | def rm(self, filename): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
253 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
254 | Public method to remove a file from the connected device. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
255 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
256 | @param filename name of the file to be removed |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
257 | @type str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
258 | @exception IOError raised to indicate an issue with the device |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
259 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
260 | assert filename |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
261 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
262 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
263 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
264 | "os.remove('{0}')".format(filename), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
265 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
266 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
267 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
268 | raise IOError(self.__shortError(err)) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
269 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
270 | def mkdir(self, dirname): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
271 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
272 | Public method to create a new directory. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
273 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
274 | @param dirname name of the directory to create |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
275 | @type str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
276 | @exception IOError raised to indicate an issue with the device |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
277 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
278 | assert dirname |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
279 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
280 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
281 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
282 | "os.mkdir('{0}')".format(dirname), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
283 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
284 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
285 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
286 | raise IOError(self.__shortError(err)) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
287 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
288 | def rmdir(self, dirname): |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
289 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
290 | Public method to remove a directory. |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
291 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
292 | @param dirname name of the directory to be removed |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
293 | @type str |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
294 | @exception IOError raised to indicate an issue with the device |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
295 | """ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
296 | assert dirname |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
297 | |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
298 | commands = [ |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
299 | "import os", |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
300 | "os.rmdir('{0}')".format(dirname), |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
301 | ] |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
302 | out, err = self.__execute(commands) |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
303 | if err: |
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
304 | raise IOError(self.__shortError(err)) |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | def put(self, hostFileName, deviceFileName): |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | Public method to copy a local file to the connected device. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | @param hostFileName name of the file to be copied |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | @type str |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | @param deviceFileName name of the file to copy to |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | @type str |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | @return flag indicating success |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | @rtype bool |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
316 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | # TODO: not implemented yet |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | def get(self, deviceFileName, hostFileName): |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | Public method to copy a file from the connected device. |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | @param deviceFileName name of the file to copy |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | @type str |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | @param hostFileName name of the file to copy to |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | @type str |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | @return flag indicating success |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | @rtype bool |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
330 | @exception IOError raised to indicate an issue with the device |
7067
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | """ |
3fc4082fc6ba
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | # TODO: not implemented yet |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
333 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
334 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
335 | class MicroPythonFileManager(QObject): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
336 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
337 | Class implementing an interface to the device file system commands with |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
338 | some additional sugar. |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
339 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
340 | @signal longListFiles(result) emitted with a tuple of tuples containing the |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
341 | name, mode, size and time for each directory entry |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
342 | @signal currentDir(dirname) emitted to report the current directory of the |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
343 | device |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
344 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
345 | @signal longListFilesFailed(exc) emitted with a failure message to indicate |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
346 | a failed long listing operation |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
347 | @signal currentDirFailed(exc) emitted with a failure message to indicate |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
348 | that the current directory is not available |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
349 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
350 | longListFiles = pyqtSignal(tuple) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
351 | currentDir = pyqtSignal(str) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
352 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
353 | longListFilesFailed = pyqtSignal(str) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
354 | currentDirFailed = pyqtSignal(str) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
355 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
356 | def __init__(self, port, parent=None): |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
357 | """ |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
358 | Constructor |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
359 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
360 | @param port port name of the device |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
361 | @type str |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
362 | @param parent reference to the parent object |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
363 | @type QObject |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
364 | """ |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
365 | super(MicroPythonFileManager, self).__init__(parent) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
366 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
367 | self.__serialPort = port |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
368 | self.__serial = MicroPythonSerialPort(parent=self) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
369 | self.__fs = MicroPythonFileSystem(parent=self) |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
370 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
371 | @pyqtSlot() |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
372 | def connect(self): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
373 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
374 | Public slot to start the manager. |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
375 | """ |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
376 | self.__serial.openSerialLink(self.__serialPort) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
377 | self.__fs.setSerial(self.__serial) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
378 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
379 | @pyqtSlot() |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
380 | def disconnect(self): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
381 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
382 | Public slot to stop the thread. |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
383 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
384 | self.__serial.closeSerialLink() |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
385 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
386 | @pyqtSlot(str) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
387 | def lls(self, dirname): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
388 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
389 | Public method to get a long listing of the given directory. |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
390 | |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
391 | @param dirname name of the directory to list |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
392 | @type str |
7070
3368ce0e7879
Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7067
diff
changeset
|
393 | """ |
7077
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
394 | try: |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
395 | filesList = self.__fs.lls(dirname) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
396 | result = [(decoratedName(name, mode), |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
397 | mode2string(mode), |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
398 | str(size), |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
399 | mtime2string(time)) for |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
400 | name, (mode, size, time) in filesList] |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
401 | self.longListFiles.emit(tuple(result)) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
402 | except Exception as exc: |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
403 | self.longListFilesFailed.emit(str(exc)) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
404 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
405 | @pyqtSlot() |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
406 | def pwd(self): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
407 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
408 | Public method to get the current directory of the device. |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
409 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
410 | try: |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
411 | pwd = self.__fs.pwd() |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
412 | self.currentDir.emit(pwd) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
413 | except Exception as exc: |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
414 | self.currentDirFailed.emit(str(exc)) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
415 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
416 | ################################################################## |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
417 | ## Utility methods below |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
418 | ################################################################## |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
419 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
420 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
421 | def mtime2string(mtime): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
422 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
423 | Function to convert a time value to a string representation. |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
424 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
425 | @param mtime time value |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
426 | @type int |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
427 | @return string representation of the given time |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
428 | @rtype str |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
429 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
430 | return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(mtime)) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
431 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
432 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
433 | def mode2string(mode): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
434 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
435 | Function to convert a mode value to a string representation. |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
436 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
437 | @param mode mode value |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
438 | @type int |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
439 | @return string representation of the given mode value |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
440 | @rtype str |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
441 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
442 | return stat.filemode(mode) |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
443 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
444 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
445 | def decoratedName(name, mode): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
446 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
447 | Function to decorate the given name according to the given mode. |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
448 | |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
449 | @param name file or directory name |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
450 | @type str |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
451 | @param mode mode value |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
452 | @type int |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
453 | @return decorated file or directory name |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
454 | @rtype str |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
455 | """ |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
456 | if stat.S_ISDIR(mode): |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
457 | # append a '/' for directories |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
458 | return name + "/" |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
459 | else: |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
460 | # no change |
3b7475b7a1ef
MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7070
diff
changeset
|
461 | return name |