eric6/MicroPython/MicroPythonFileSystem.py

Sat, 27 Jul 2019 17:02:01 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Jul 2019 17:02:01 +0200
branch
micropython
changeset 7088
e29b0ee86b29
parent 7084
3eddfc540614
child 7089
9f9816b19aa4
permissions
-rw-r--r--

MicroPython: continued implementing 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
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
14 import os
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
15 import stat
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
16
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
17 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
18
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
19 from .MicroPythonSerialPort import MicroPythonSerialPort
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
20 from .MicroPythonFileSystemUtilities import (
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
21 mtime2string, mode2string, decoratedName, listdirStat
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
22 )
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
24 import Preferences
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
25
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class MicroPythonFileSystem(QObject):
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Class implementing some file system commands for MicroPython.
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
31 Commands are provided to perform operations on the file system of a
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
32 connected MicroPython device. Supported commands are:
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 <ul>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 <li>ls: directory listing</li>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 <li>lls: directory listing with meta data</li>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 <li>cd: change directory</li>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 <li>pwd: get the current directory</li>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 <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
39 <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
40 <li>rm: remove a file from the connected device</li>
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
41 <li>rmrf: remove a file/directory recursively (like 'rm -rf' in bash)
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
42 <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
43 <li>rmdir: remove an empty directory</li>
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
44 </ul>
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
45
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
46 There are additional commands related to time and version.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
47 <ul>
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
48 <li>version: get version info about MicroPython</li>
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
49 <li>syncTime: synchronize the time of the connected device</li>
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
50 <li>showTime: show the current time of the connected device</li>
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 </ul>
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def __init__(self, parent=None):
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Constructor
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param parent reference to the parent object
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @type QObject
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 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
61
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
62 self.__serial = None
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
64 def setSerial(self, serial):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
65 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
66 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
67
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
68 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
69
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
70 @param serial open serial port
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
71 @type MicroPythonSerialPort
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 = serial
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
74
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
75 def __rawOn(self):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
76 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
77 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
78
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
79 Note: switching to raw mode is done with synchronous writes.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
80
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
81 @return flag indicating success
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
82 @@rtype bool
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
83 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
84 if not self.__serial:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
85 return False
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
86
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
87 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
88 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
89
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
90 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
91 self.__serial.waitForBytesWritten()
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
92 for _i in range(3):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
93 # 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
94 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
95 self.__serial.waitForBytesWritten()
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
96 QThread.msleep(10)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
97 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
98 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
99 self.__serial.readUntil(rawReplMessage)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
100 if self.__serial.hasTimedOut():
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
101 return False
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
102 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
103 self.__serial.readUntil(softRebootMessage)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
104 if self.__serial.hasTimedOut():
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
105 return False
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
106
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
107 # 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
108 # special way
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
109 data = self.__serial.readUntil(rawReplMessage)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
110 if self.__serial.hasTimedOut():
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
111 return False
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
112 if not data.endswith(rawReplMessage):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
113 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
114 self.__serial.readUntil(rawReplMessage)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
115 if self.__serial.hasTimedOut():
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
116 return False
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
117 self.__serial.readAll() # read all data and discard it
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
118 return True
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
119
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
120 def __rawOff(self):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
121 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
122 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
123 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
124 if self.__serial:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
125 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
126
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
127 def __execute(self, commands):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
128 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
129 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
130 result.
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
131
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
132 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
133
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
134 @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
135 @type str
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
136 @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
137 @rtype tuple of (bytes, bytes)
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 if not self.__serial:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
140 return b"", b""
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
141
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
142 result = bytearray()
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
143 err = b""
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
144
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
145 ok = self.__rawOn()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
146 if not ok:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
147 return (
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
148 b"",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
149 b"Could not switch to raw mode. Is the device switched on?"
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
150 )
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
151
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
152 QThread.msleep(10)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
153 for command in commands:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
154 if command:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
155 commandBytes = command.encode("utf-8")
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
156 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
157 # read until prompt
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
158 response = self.__serial.readUntil(b"\x04>")
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
159 if self.__serial.hasTimedOut():
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
160 return b"", b"Timeout while processing commands."
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
161 if b"\x04" in response[2:-2]:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
162 # split stdout, stderr
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
163 out, err = response[2:-2].split(b"\x04")
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
164 result += out
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
165 else:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
166 err = b"invalid response received: " + response
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
167 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
168 return b"", err
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
169 QThread.msleep(10)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
170 self.__rawOff()
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 return bytes(result), err
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
173
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
174 def __shortError(self, error):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
175 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
176 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
177
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
178 @param error verbose error message
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
179 @type bytes
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
180 @return shortened error message
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
181 @rtype str
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
182 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
183 if error:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
184 decodedError = error.decode("utf-8")
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
185 try:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
186 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
187 except Exception:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
188 return decodedError
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
189 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
190
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
191 ##################################################################
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
192 ## 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
193 ##################################################################
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
194
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
195 def ls(self, dirname=""):
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 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
198
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
199 @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
200 @type str
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 @return tuple containg the directory listing
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 @rtype tuple of str
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
203 @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
204 """
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
205 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
206 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
207 "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
208 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
209 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
210 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
211 raise IOError(self.__shortError(err))
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
212 return ast.literal_eval(out.decode("utf-8"))
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
214 def lls(self, dirname="", fullstat=False):
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 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
217 including meta data.
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
219 @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
220 @type str
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
221 @param fullstat flag indicating to return the full stat() tuple
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
222 @type bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
223 @return list containing the directory listing with tuple entries of
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
224 the name and and a tuple of mode, size and time (if fullstat is
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
225 false) or the complete stat() tuple. 'None' is returned in case the
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
226 directory doesn't exist.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
227 @rtype tuple of (str, tuple)
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
228 @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
229 """
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
230 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
231 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
232 "\n".join([
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
233 "def stat(filename):",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
234 " try:",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
235 " rstat = os.lstat(filename)",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
236 " except:",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
237 " rstat = os.stat(filename)",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
238 " return tuple(rstat)",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
239 ]),
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
240 "\n".join([
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
241 "def listdir_stat(dirname):",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
242 " try:",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
243 " files = os.listdir(dirname)",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
244 " except OSError:",
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
245 " return None",
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
246 " if dirname in ('', '/'):",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
247 " 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
248 " 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
249 ]),
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
250 "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
251 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
252 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
253 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
254 raise IOError(self.__shortError(err))
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
255 fileslist = ast.literal_eval(out.decode("utf-8"))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
256 if fileslist is None:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
257 return None
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
258 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
259 if fullstat:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
260 return fileslist
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
261 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
262 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
263
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
264 def cd(self, dirname):
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 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
267
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
268 @param dirname directory to change to
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 @type str
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
270 @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
271 """
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
272 assert dirname
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 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
275 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
276 "os.chdir('{0}')".format(dirname),
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 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
279 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
280 raise IOError(self.__shortError(err))
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 def pwd(self):
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 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
285
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 @return current directory
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 @rtype str
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
288 @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
289 """
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
290 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
291 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
292 "print(os.getcwd())",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
293 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
294 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
295 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
296 raise IOError(self.__shortError(err))
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
297 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
298
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
299 def rm(self, filename):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
300 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
301 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
302
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
303 @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
304 @type str
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
305 @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
306 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
307 assert filename
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
308
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
309 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
310 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
311 "os.remove('{0}')".format(filename),
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
312 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
313 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
314 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
315 raise IOError(self.__shortError(err))
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
316
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
317 def rmrf(self, name, recursive=False, force=False):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
318 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
319 Public method to remove a file or directory recursively.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
320
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
321 @param name of the file or directory to remove
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
322 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
323 @param recursive flag indicating a recursive deletion
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
324 @type bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
325 @param force flag indicating to ignore errors
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
326 @type bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
327 @return flag indicating success
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
328 @rtype bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
329 @exception IOError raised to indicate an issue with the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
330 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
331 assert name
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
332
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
333 commands = [
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
334 "import os",
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
335 "\n".join([
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
336 "def remove_file(name, recursive=False, force=False):",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
337 " try:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
338 " mode = os.stat(name)[0]",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
339 " if mode & 0x4000 != 0:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
340 " if recursive:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
341 " for file in os.listdir(name):",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
342 " success = remove_file(name + '/' + file,"
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
343 " recursive, force)",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
344 " if not success and not force:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
345 " return False",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
346 " os.rmdir(name)",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
347 " else:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
348 " if not force:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
349 " return False",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
350 " else:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
351 " os.remove(name)",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
352 " except:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
353 " if not force:",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
354 " return False",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
355 " return True",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
356 ]),
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
357 "print(remove_file('{0}', {1}, {2}))".format(name, recursive,
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
358 force),
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
359 ]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
360 out, err = self.__execute(commands)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
361 if err:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
362 raise IOError(self.__shortError(err))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
363 return ast.literal_eval(out.decode("utf-8"))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
364
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
365 def mkdir(self, dirname):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
366 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
367 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
368
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
369 @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
370 @type str
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
371 @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
372 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
373 assert dirname
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
374
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
375 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
376 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
377 "os.mkdir('{0}')".format(dirname),
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
378 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
379 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
380 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
381 raise IOError(self.__shortError(err))
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
382
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
383 def rmdir(self, dirname):
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
384 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
385 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
386
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
387 @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
388 @type str
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
389 @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
390 """
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
391 assert dirname
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
392
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
393 commands = [
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
394 "import os",
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
395 "os.rmdir('{0}')".format(dirname),
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
396 ]
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
397 out, err = self.__execute(commands)
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
398 if err:
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
399 raise IOError(self.__shortError(err))
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
401 def put(self, hostFileName, deviceFileName=None):
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 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
404
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 @param hostFileName name of the file to be copied
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 @type str
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 @param deviceFileName name of the file to copy to
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 @type str
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 @return flag indicating success
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 @rtype bool
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
411 @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
412 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
413 if not os.path.isfile(hostFileName):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
414 raise IOError("No such file: {0}".format(hostFileName))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
415
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
416 with open(hostFileName, "rb") as hostFile:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
417 content = hostFile.read()
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
418 # convert eol '\r'
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
419 content = content.replace(b"\r\n", b"\r")
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
420 content = content.replace(b"\n", b"\r")
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
421
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
422 if not deviceFileName:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
423 deviceFileName = os.path.basename(hostFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
424
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
425 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
426 "fd = open('{0}', 'wb')".format(deviceFileName),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
427 "f = fd.write",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
428 ]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
429 while content:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
430 chunk = content[:64]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
431 commands.append("f(" + repr(chunk) + ")")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
432 content = content[64:]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
433 commands.append("fd.close()")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
434
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
435 out, err = self.__execute(commands)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
436 if err:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
437 raise IOError(self.__shortError(err))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
438 return True
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
440 def get(self, deviceFileName, hostFileName=None):
7067
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 """
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 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
443
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 @param deviceFileName name of the file to copy
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 @type str
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 @param hostFileName name of the file to copy to
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 @type str
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 @return flag indicating success
3fc4082fc6ba Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 @rtype bool
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
450 @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
451 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
452 if not hostFileName:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
453 hostFileName = deviceFileName
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
454
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
455 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
456 "\n".join([
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
457 "try:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
458 " from microbit import uart as u",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
459 "except ImportError:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
460 " try:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
461 " from machine import UART",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
462 " u = UART(0, {0})".format(115200),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
463 " except Exception:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
464 " try:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
465 " from sys import stdout as u",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
466 " except Exception:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
467 " raise Exception('Could not find UART module in"
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
468 " device.')",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
469 ]),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
470 "f = open('{0}', 'rb')".format(deviceFileName),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
471 "r = f.read",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
472 "result = True",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
473 "\n".join([
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
474 "while result:",
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
475 " result = r(32)",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
476 " if result:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
477 " u.write(result)",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
478 ]),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
479 "f.close()",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
480 ]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
481 out, err = self.__execute(commands)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
482 if err:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
483 raise IOError(self.__shortError(err))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
484
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
485 # write the received bytes to the local file
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
486 # convert eol to "\n"
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
487 out = out.replace(b"\r\n", b"\n")
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
488 out = out.replace(b"\r", b"\n")
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
489 with open(hostFileName, "wb") as hostFile:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
490 hostFile.write(out)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
491 return True
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
492
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
493 def fileSystemInfo(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
494 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
495 Public method to obtain information about the currently mounted file
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
496 systems.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
497
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
498 @return tuple of tuples containing the file system name, the total
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
499 size, the used size and the free size
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
500 @rtype tuple of tuples of (str, int, int, int)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
501 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
502 commands = [
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
503 "import os",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
504 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
505 "def fsinfo():",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
506 " infolist = []",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
507 " fsnames = os.listdir('/')",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
508 " for fs in fsnames:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
509 " fs = '/' + fs",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
510 " infolist.append((fs, os.statvfs(fs)))",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
511 " return infolist",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
512 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
513 "print(fsinfo())",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
514 ]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
515 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
516 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
517 raise IOError(self.__shortError(err))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
518 infolist = ast.literal_eval(out.decode("utf-8"))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
519 if infolist is None:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
520 return None
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
521 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
522 filesystemInfos = []
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
523 for fs, info in infolist:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
524 totalSize = info[2] * info[1]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
525 freeSize = info[4] * info[1]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
526 usedSize = totalSize - freeSize
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
527 filesystemInfos.append((fs, totalSize, usedSize, freeSize))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
528
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
529 return tuple(filesystemInfos)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
530
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
531 ##################################################################
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
532 ## non-filesystem related methods below
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
533 ##################################################################
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
534
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
535 def version(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
536 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
537 Public method to get the MicroPython version information of the
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
538 connected device.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
539
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
540 @return dictionary containing the version information
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
541 @rtype dict
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
542 @exception IOError raised to indicate an issue with the device
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
543 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
544 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
545 "import os",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
546 "print(os.uname())",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
547 ]
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
548 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
549 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
550 raise IOError(self.__shortError(err))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
551
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
552 rawOutput = out.decode("utf-8").strip()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
553 rawOutput = rawOutput[1:-1]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
554 items = rawOutput.split(",")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
555 result = {}
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
556 for item in items:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
557 key, value = item.strip().split("=")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
558 result[key.strip()] = value.strip()[1:-1]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
559 return result
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
560
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
561 def getImplementation(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
562 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
563 Public method to get some implementation information of the connected
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
564 device.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
565
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
566 @return dictionary containing the implementation information
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
567 @rtype dict
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
568 @exception IOError raised to indicate an issue with the device
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
569 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
570 commands = [
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
571 "import sys",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
572 "res = {}",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
573 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
574 "try:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
575 " res['name'] = sys.implementation.name",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
576 "except AttributeError:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
577 " res['name'] = 'unknown'",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
578 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
579 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
580 "try:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
581 " res['version'] = '.'.join((str(i) for i in"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
582 " sys.implementation.version))",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
583 "except AttributeError:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
584 " res['version'] = 'unknown'",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
585 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
586 "print(res)",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
587 ]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
588 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
589 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
590 raise IOError(self.__shortError(err))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
591 return ast.literal_eval(out.decode("utf-8"))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
592
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
593 def syncTime(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
594 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
595 Public method to set the time of the connected device to the local
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
596 computer's time.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
597
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
598 @exception IOError raised to indicate an issue with the device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
599 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
600 now = time.localtime(time.time())
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
601 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
602 "\n".join([
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
603 "def set_time(rtc_time):",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
604 " rtc = None",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
605 " try:", # Pyboard (it doesn't have machine.RTC())
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
606 " import pyb",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
607 " rtc = pyb.RTC()",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
608 " clock_time = rtc_time[:6] + (rtc_time[6] + 1, 0)",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
609 " rtc.datetime(clock_time)",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
610 " except:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
611 " try:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
612 " import machine",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
613 " rtc = machine.RTC()",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
614 " try:", # ESP8266 may use rtc.datetime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
615 " clock_time = rtc_time[:6] +"
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
616 " (rtc_time[6] + 1, 0)",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
617 " rtc.datetime(clock_time)",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
618 " except:", # ESP32 uses rtc.init()
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
619 " rtc.init(rtc_time[:6])",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
620 " except:",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
621 " try:",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
622 " import rtc, time",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
623 " clock=rtc.RTC()",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
624 " clock.datetime = time.struct_time(rtc_time +"
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
625 " (-1, -1))",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
626 " except:",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
627 " pass",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
628 ]),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
629 "set_time({0})".format((now.tm_year, now.tm_mon, now.tm_mday,
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
630 now.tm_hour, now.tm_min, now.tm_sec,
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
631 now.tm_wday))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
632 ]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
633 out, err = self.__execute(commands)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
634 if err:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
635 raise IOError(self.__shortError(err))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
636
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
637 def showTime(self):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
638 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
639 Public method to get the current time of the device.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
640
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
641 @return time of the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
642 @rtype str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
643 @exception IOError raised to indicate an issue with the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
644 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
645 commands = [
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
646 "import time",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
647 "print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
648 # __IGNORE_WARNING_M601__
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
649 ]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
650 out, err = self.__execute(commands)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
651 if err:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
652 raise IOError(self.__shortError(err))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
653 return out.decode("utf-8").strip()
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
654
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
655
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
656 class MicroPythonFileManager(QObject):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
657 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
658 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
659 some additional sugar.
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
660
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
661 @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
662 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
663 @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
664 device
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
665 @signal currentDirChanged(dirname) emitted to report back a change of the
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
666 current directory
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
667 @signal getFileDone(deviceFile, localFile) emitted after the file was
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
668 fetched from the connected device and written to the local file system
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
669 @signal putFileDone(localFile, deviceFile) emitted after the file was
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
670 copied to the connected device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
671 @signal deleteFileDone(deviceFile) emitted after the file has been deleted
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
672 on the connected device
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
673 @signal rsyncDone(localName, deviceName) emitted after the rsync operation
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
674 has been completed
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
675 @signal rsyncProgressMessage(msg) emitted to send a message about what
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
676 rsync is doing
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
677 @signal removeDirectoryDone() emitted after a directory has been deleted
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
678 @signal createDirectoryDone() emitted after a directory was created
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
679 @signal fsinfoDone(fsinfo) emitted after the file system information was
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
680 obtained
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
681
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
682 @signal synchTimeDone() emitted after the time was synchronizde to the
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
683 device
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
684 @signal showTimeDone(dateTime) emitted after the date and time was fetched
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
685 from the connected device
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
686 @signal showVersionDone(versionInfo) emitted after the version information
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
687 was fetched from the connected device
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
688 @signal showImplementationDone(name,version) emitted after the
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
689 implementation information has been obtained
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
690
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
691 @signal error(exc) emitted with a failure message to indicate a failure
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
692 during the most recent operation
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
693 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
694 longListFiles = pyqtSignal(tuple)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
695 currentDir = pyqtSignal(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
696 currentDirChanged = pyqtSignal(str)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
697 getFileDone = pyqtSignal(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
698 putFileDone = pyqtSignal(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
699 deleteFileDone = pyqtSignal(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
700 rsyncDone = pyqtSignal(str, str)
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
701 rsyncProgressMessage = pyqtSignal(str)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
702 removeDirectoryDone = pyqtSignal()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
703 createDirectoryDone = pyqtSignal()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
704 fsinfoDone = pyqtSignal(tuple)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
705
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
706 synchTimeDone = pyqtSignal()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
707 showTimeDone = pyqtSignal(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
708 showVersionDone = pyqtSignal(dict)
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
709 showImplementationDone = pyqtSignal(str, str)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
710
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
711 error = pyqtSignal(str, str)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
712
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
713 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
714 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
715 Constructor
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
716
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
717 @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
718 @type str
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
719 @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
720 @type QObject
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
721 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
722 super(MicroPythonFileManager, self).__init__(parent)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
723
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
724 self.__serialPort = port
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
725 self.__serial = MicroPythonSerialPort(
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
726 timeout=Preferences.getMicroPython("SerialTimeout"),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
727 parent=self)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
728 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
729
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
730 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
731 def connectToDevice(self):
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
732 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
733 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
734 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
735 self.__serial.openSerialLink(self.__serialPort)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
736 self.__fs.setSerial(self.__serial)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
737
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
738 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
739 def disconnectFromDevice(self):
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
740 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
741 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
742 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
743 self.__serial.closeSerialLink()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
744
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
745 @pyqtSlot()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
746 def handlePreferencesChanged(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
747 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
748 Public slot to handle a change of the preferences.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
749 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
750 self.__serial.setTimeout(Preferences.getMicroPython("SerialTimeout"))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
751
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
752 @pyqtSlot(str)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
753 def lls(self, dirname):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
754 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
755 Public slot 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
756
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
757 @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
758 @type str
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
759 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
760 try:
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
761 filesList = self.__fs.lls(dirname)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
762 result = [(decoratedName(name, mode),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
763 mode2string(mode),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
764 str(size),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
765 mtime2string(time)) for
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
766 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
767 self.longListFiles.emit(tuple(result))
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
768 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
769 self.error.emit("lls", str(exc))
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
770
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
771 @pyqtSlot()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
772 def pwd(self):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
773 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
774 Public slot to get the current directory of the device.
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
775 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
776 try:
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
777 pwd = self.__fs.pwd()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
778 self.currentDir.emit(pwd)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
779 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
780 self.error.emit("pwd", str(exc))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
781
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
782 @pyqtSlot(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
783 def cd(self, dirname):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
784 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
785 Public slot to change the current directory of the device.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
786
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
787 @param dirname name of the desired current directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
788 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
789 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
790 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
791 self.__fs.cd(dirname)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
792 self.currentDirChanged.emit(dirname)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
793 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
794 self.error.emit("cd", str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
795
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
796 @pyqtSlot(str)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
797 @pyqtSlot(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
798 def get(self, deviceFileName, hostFileName=""):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
799 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
800 Public slot to get a file from the connected device.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
801
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
802 @param deviceFileName name of the file on the device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
803 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
804 @param hostFileName name of the local file
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
805 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
806 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
807 if hostFileName and os.path.isdir(hostFileName):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
808 # only a local directory was given
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
809 hostFileName = os.path.join(hostFileName,
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
810 os.path.basename(deviceFileName))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
811 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
812 self.__fs.get(deviceFileName, hostFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
813 self.getFileDone.emit(deviceFileName, hostFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
814 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
815 self.error.emit("get", str(exc))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
816
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
817 @pyqtSlot(str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
818 @pyqtSlot(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
819 def put(self, hostFileName, deviceFileName=""):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
820 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
821 Public slot to put a file onto the device.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
822
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
823 @param hostFileName name of the local file
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
824 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
825 @param deviceFileName name of the file on the connected device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
826 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
827 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
828 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
829 self.__fs.put(hostFileName, deviceFileName)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
830 self.putFileDone.emit(hostFileName, deviceFileName)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
831 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
832 self.error.emit("put", str(exc))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
833
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
834 @pyqtSlot(str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
835 def delete(self, deviceFileName):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
836 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
837 Public slot to delete a file on the device.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
838
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
839 @param deviceFileName name of the file on the connected device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
840 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
841 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
842 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
843 self.__fs.rm(deviceFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
844 self.deleteFileDone.emit(deviceFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
845 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
846 self.error.emit("delete", str(exc))
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
847
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
848 def __rsync(self, hostDirectory, deviceDirectory, mirror=True):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
849 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
850 Private method to synchronize a local directory to the device.
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
851
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
852 @param hostDirectory name of the local directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
853 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
854 @param deviceDirectory name of the directory on the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
855 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
856 @param mirror flag indicating to mirror the local directory to
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
857 the device directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
858 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
859 @return list of errors
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
860 @rtype list of str
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
861 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
862 errors = []
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
863
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
864 if not os.path.isdir(hostDirectory):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
865 return [self.tr(
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
866 "The given name '{0}' is not a directory or does not exist.")
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
867 .format(hostDirectory)
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
868 ]
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
869
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
870 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
871 self.tr("Synchronizing <b>{0}</b>.").format(deviceDirectory)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
872 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
873
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
874 sourceDict = {}
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
875 sourceFiles = listdirStat(hostDirectory)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
876 for name, nstat in sourceFiles:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
877 sourceDict[name] = nstat
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
878
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
879 destinationDict = {}
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
880 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
881 destinationFiles = self.__fs.lls(deviceDirectory, fullstat=True)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
882 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
883 return [str(exc)]
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
884 if destinationFiles is None:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
885 # the destination directory does not exist
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
886 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
887 self.__fs.mkdir(deviceDirectory)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
888 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
889 return [str(exc)]
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
890 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
891 for name, nstat in destinationFiles:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
892 destinationDict[name] = nstat
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
893
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
894 destinationSet = set(destinationDict.keys())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
895 sourceSet = set(sourceDict.keys())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
896 toAdd = sourceSet - destinationSet # add to dev
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
897 toDelete = destinationSet - sourceSet # delete from dev
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
898 toUpdate = destinationSet.intersection(sourceSet) # update files
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
899
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
900 for sourceBasename in toAdd:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
901 # name exists in source but not in device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
902 sourceFilename = os.path.join(hostDirectory, sourceBasename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
903 destFilename = deviceDirectory + "/" + sourceBasename
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
904 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
905 self.tr("Adding <b>{0}</b>...").format(destFilename))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
906 if os.path.isfile(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
907 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
908 self.__fs.put(sourceFilename, destFilename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
909 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
910 # just note issues but ignore them otherwise
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
911 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
912 if os.path.isdir(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
913 # recurse
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
914 errs = self.__rsync(sourceFilename, destFilename,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
915 mirror=mirror)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
916 # just note issues but ignore them otherwise
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
917 errors.extend(errs)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
918
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
919 if mirror:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
920 for destBasename in toDelete:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
921 # name exists in device but not local, delete
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
922 destFilename = deviceDirectory + "/" + destBasename
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
923 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
924 self.tr("Removing <b>{0}</b>...").format(destFilename))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
925 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
926 self.__fs.rmrf(destFilename, recursive=True, force=True)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
927 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
928 # just note issues but ignore them otherwise
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
929 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
930
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
931 for sourceBasename in toUpdate:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
932 # names exist in both; do an update
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
933 sourceStat = sourceDict[sourceBasename]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
934 destStat = destinationDict[sourceBasename]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
935 sourceFilename = os.path.join(hostDirectory, sourceBasename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
936 destFilename = deviceDirectory + "/" + sourceBasename
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
937 destMode = destStat[0]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
938 if os.path.isdir(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
939 if stat.S_ISDIR(destMode):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
940 # both are directories => recurs
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
941 errs = self.__rsync(sourceFilename, destFilename,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
942 mirror=mirror)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
943 # just note issues but ignore them otherwise
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
944 errors.extend(errs)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
945 else:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
946 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
947 self.tr("Source <b>{0}</b> is a directory and"
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
948 " destination <b>{1}</b> is a file. Ignoring"
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
949 " it.")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
950 .format(sourceFilename, destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
951 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
952 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
953 if stat.S_ISDIR(destMode):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
954 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
955 self.tr("Source <b>{0}</b> is a file and destination"
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
956 " <b>{1}</b> is a directory. Ignoring it.")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
957 .format(sourceFilename, destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
958 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
959 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
960 if sourceStat[8] > destStat[8]: # mtime
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
961 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
962 self.tr("Updating <b>{0}</b>...")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
963 .format(destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
964 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
965 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
966 self.__fs.put(sourceFilename, destFilename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
967 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
968 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
969
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
970 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
971 self.tr("Done synchronizing <b>{0}</b>.").format(deviceDirectory)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
972 )
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
973
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
974 return errors
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
975
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
976 @pyqtSlot(str, str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
977 @pyqtSlot(str, str, bool)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
978 def rsync(self, hostDirectory, deviceDirectory, mirror=True):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
979 """
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
980 Public slot to synchronize a local directory to the device.
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
981
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
982 @param hostDirectory name of the local directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
983 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
984 @param deviceDirectory name of the directory on the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
985 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
986 @param mirror flag indicating to mirror the local directory to
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
987 the device directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
988 @type bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
989 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
990 errors = self.__rsync(hostDirectory, deviceDirectory, mirror=mirror)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
991 if errors:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
992 self.error.emit("rsync", "\n".join(errors))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
993
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
994 self.rsyncDone.emit(hostDirectory, deviceDirectory)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
995
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
996 @pyqtSlot(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
997 def mkdir(self, dirname):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
998 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
999 Public slot to create a new directory.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1000
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1001 @param dirname name of the directory to create
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1002 @type str
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1003 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1004 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1005 self.__fs.mkdir(dirname)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1006 self.createDirectoryDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1007 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1008 self.error.emit("mkdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1009
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1010 @pyqtSlot(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1011 @pyqtSlot(str, bool)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1012 def rmdir(self, dirname, recursive=False):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1013 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1014 Public slot to (recursively) remove a directory.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1015
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1016 @param dirname name of the directory to be removed
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1017 @type str
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1018 @param recursive flag indicating a recursive removal
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1019 @type bool
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1020 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1021 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1022 if recursive:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1023 self.__fs.rmrf(dirname, recursive=True, force=True)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1024 else:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1025 self.__fs.rmdir(dirname)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1026 self.removeDirectoryDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1027 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1028 self.error.emit("rmdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1029
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1030 def fileSystemInfo(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1031 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1032 Public method to obtain information about the currently mounted file
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1033 systems.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1034 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1035 try:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1036 fsinfo = self.__fs.fileSystemInfo()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1037 self.fsinfoDone.emit(fsinfo)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1038 except Exception as exc:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1039 self.error.emit("fileSystemInfo", str(exc))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1040
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1041 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1042 ## some non-filesystem related methods below
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1043 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1044
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1045 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1046 def synchronizeTime(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1047 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1048 Public slot to set the time of the connected device to the local
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1049 computer's time.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1050 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1051 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1052 self.__fs.syncTime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1053 self.synchTimeDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1054 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1055 self.error.emit("rmdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1056
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1057 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1058 def showTime(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1059 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1060 Public slot to get the current date and time of the device.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1061 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1062 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1063 dt = self.__fs.showTime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1064 self.showTimeDone.emit(dt)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1065 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1066 self.error.emit("showTime", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1067
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1068 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1069 def showVersion(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1070 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1071 Public slot to get the version info for the MicroPython run by the
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1072 connected device.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1073 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1074 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1075 versionInfo = self.__fs.version()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1076 self.showVersionDone.emit(versionInfo)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1077 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1078 self.error.emit("showVersion", str(exc))
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1079
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1080 @pyqtSlot()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1081 def showImplementation(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1082 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1083 Public slot to obtain some implementation related information.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1084 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1085 try:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1086 impInfo = self.__fs.getImplementation()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1087 if impInfo["name"] == "micropython":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1088 name = "MicroPython"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1089 elif impInfo["name"] == "circuitpython":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1090 name = "CircuitPython"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1091 elif impInfo["name"] == "unknown":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1092 name = self.tr("unknown")
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1093 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1094 name = impInfo["name"]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1095 if impInfo["version"] == "unknown":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1096 version = self.tr("unknown")
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1097 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1098 version = impInfo["version"]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1099 self.showImplementationDone.emit(name, version)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1100 except Exception as exc:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1101 self.error.emit("showVersion", str(exc))

eric ide

mercurial