eric6/MicroPython/MicroPythonFileSystem.py

Sat, 27 Jul 2019 17:52:00 +0200

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

Fixed some code style issues.

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)
7089
9f9816b19aa4 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7088
diff changeset
501 @exception IOError raised to indicate an issue with the device
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
502 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
503 commands = [
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
504 "import os",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
505 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
506 "def fsinfo():",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
507 " infolist = []",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
508 " fsnames = os.listdir('/')",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
509 " for fs in fsnames:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
510 " fs = '/' + fs",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
511 " infolist.append((fs, os.statvfs(fs)))",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
512 " return infolist",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
513 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
514 "print(fsinfo())",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
515 ]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
516 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
517 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
518 raise IOError(self.__shortError(err))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
519 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
520 if infolist is None:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
521 return None
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
522 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
523 filesystemInfos = []
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
524 for fs, info in infolist:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
525 totalSize = info[2] * info[1]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
526 freeSize = info[4] * info[1]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
527 usedSize = totalSize - freeSize
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
528 filesystemInfos.append((fs, totalSize, usedSize, freeSize))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
529
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
530 return tuple(filesystemInfos)
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 ##################################################################
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
533 ## non-filesystem related methods below
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
534 ##################################################################
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
535
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
536 def version(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
537 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
538 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
539 connected device.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
540
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
541 @return dictionary containing the version information
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
542 @rtype dict
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
543 @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
544 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
545 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
546 "import os",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
547 "print(os.uname())",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
548 ]
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
549 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
550 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
551 raise IOError(self.__shortError(err))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
552
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
553 rawOutput = out.decode("utf-8").strip()
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
554 rawOutput = rawOutput[1:-1]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
555 items = rawOutput.split(",")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
556 result = {}
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
557 for item in items:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
558 key, value = item.strip().split("=")
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
559 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
560 return result
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
561
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
562 def getImplementation(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
563 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
564 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
565 device.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
566
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
567 @return dictionary containing the implementation information
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
568 @rtype dict
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
569 @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
570 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
571 commands = [
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
572 "import sys",
7089
9f9816b19aa4 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7088
diff changeset
573 "res = {}", # __IGNORE_WARNING_M613__
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
574 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
575 "try:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
576 " res['name'] = sys.implementation.name",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
577 "except AttributeError:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
578 " res['name'] = 'unknown'",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
579 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
580 "\n".join([
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
581 "try:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
582 " 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
583 " sys.implementation.version))",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
584 "except AttributeError:",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
585 " res['version'] = 'unknown'",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
586 ]),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
587 "print(res)",
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
588 ]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
589 out, err = self.__execute(commands)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
590 if err:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
591 raise IOError(self.__shortError(err))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
592 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
593
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
594 def syncTime(self):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
595 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
596 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
597 computer's time.
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
598
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
599 @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
600 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
601 now = time.localtime(time.time())
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
602 commands = [
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
603 "\n".join([
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
604 "def set_time(rtc_time):",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
605 " rtc = None",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
606 " 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
607 " import pyb",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
608 " rtc = pyb.RTC()",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
609 " 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
610 " rtc.datetime(clock_time)",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
611 " except:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
612 " try:",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
613 " import machine",
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
614 " rtc = machine.RTC()",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
615 " try:", # ESP8266 may use rtc.datetime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
616 " clock_time = rtc_time[:6] +"
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
617 " (rtc_time[6] + 1, 0)",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
618 " rtc.datetime(clock_time)",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
619 " except:", # ESP32 uses rtc.init()
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
620 " rtc.init(rtc_time[:6])",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
621 " except:",
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
622 " try:",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
623 " import rtc, time",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
624 " clock=rtc.RTC()",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
625 " 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
626 " (-1, -1))",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
627 " except:",
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
628 " pass",
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
629 ]),
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
630 "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
631 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
632 now.tm_wday))
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
633 ]
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
634 out, err = self.__execute(commands)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
635 if err:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
636 raise IOError(self.__shortError(err))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
637
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
638 def showTime(self):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
639 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
640 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
641
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
642 @return time of the device
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
643 @rtype str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
644 @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
645 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
646 commands = [
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
647 "import time",
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
648 "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
649 # __IGNORE_WARNING_M601__
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
650 ]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
651 out, err = self.__execute(commands)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
652 if err:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
653 raise IOError(self.__shortError(err))
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
654 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
655
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
656
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
657 class MicroPythonFileManager(QObject):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
658 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
659 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
660 some additional sugar.
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
661
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
662 @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
663 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
664 @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
665 device
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
666 @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
667 current directory
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
668 @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
669 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
670 @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
671 copied to the connected device
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
672 @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
673 on the connected device
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
674 @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
675 has been completed
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
676 @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
677 rsync is doing
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
678 @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
679 @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
680 @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
681 obtained
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
682
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
683 @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
684 device
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
685 @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
686 from the connected device
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
687 @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
688 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
689 @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
690 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
691
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
692 @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
693 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
694 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
695 longListFiles = pyqtSignal(tuple)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
696 currentDir = pyqtSignal(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
697 currentDirChanged = pyqtSignal(str)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
698 getFileDone = pyqtSignal(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
699 putFileDone = pyqtSignal(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
700 deleteFileDone = pyqtSignal(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
701 rsyncDone = pyqtSignal(str, str)
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
702 rsyncProgressMessage = pyqtSignal(str)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
703 removeDirectoryDone = pyqtSignal()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
704 createDirectoryDone = pyqtSignal()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
705 fsinfoDone = pyqtSignal(tuple)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
706
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
707 synchTimeDone = pyqtSignal()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
708 showTimeDone = pyqtSignal(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
709 showVersionDone = pyqtSignal(dict)
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
710 showImplementationDone = pyqtSignal(str, str)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
711
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
712 error = pyqtSignal(str, str)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
713
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
714 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
715 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
716 Constructor
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
717
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
718 @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
719 @type str
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
720 @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
721 @type QObject
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
722 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
723 super(MicroPythonFileManager, self).__init__(parent)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
724
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
725 self.__serialPort = port
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
726 self.__serial = MicroPythonSerialPort(
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
727 timeout=Preferences.getMicroPython("SerialTimeout"),
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
728 parent=self)
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
729 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
730
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
731 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
732 def connectToDevice(self):
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
733 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
734 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
735 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
736 self.__serial.openSerialLink(self.__serialPort)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
737 self.__fs.setSerial(self.__serial)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
738
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
739 @pyqtSlot()
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
740 def disconnectFromDevice(self):
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
741 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
742 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
743 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
744 self.__serial.closeSerialLink()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
745
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
746 @pyqtSlot()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
747 def handlePreferencesChanged(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
748 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
749 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
750 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
751 self.__serial.setTimeout(Preferences.getMicroPython("SerialTimeout"))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
752
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
753 @pyqtSlot(str)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
754 def lls(self, dirname):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
755 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
756 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
757
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
758 @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
759 @type str
7070
3368ce0e7879 Started to implement the device file system interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7067
diff changeset
760 """
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
761 try:
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
762 filesList = self.__fs.lls(dirname)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
763 result = [(decoratedName(name, mode),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
764 mode2string(mode),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
765 str(size),
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
766 mtime2string(time)) for
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
767 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
768 self.longListFiles.emit(tuple(result))
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
769 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
770 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
771
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
772 @pyqtSlot()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
773 def pwd(self):
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
774 """
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
775 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
776 """
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
777 try:
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
778 pwd = self.__fs.pwd()
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
779 self.currentDir.emit(pwd)
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
780 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
781 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
782
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
783 @pyqtSlot(str)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
784 def cd(self, dirname):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
785 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
786 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
787
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
788 @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
789 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
790 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
791 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
792 self.__fs.cd(dirname)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
793 self.currentDirChanged.emit(dirname)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
794 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
795 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
796
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
797 @pyqtSlot(str)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
798 @pyqtSlot(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
799 def get(self, deviceFileName, hostFileName=""):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
800 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
801 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
802
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
803 @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
804 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
805 @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
806 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
807 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
808 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
809 # only a local directory was given
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
810 hostFileName = os.path.join(hostFileName,
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
811 os.path.basename(deviceFileName))
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
812 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
813 self.__fs.get(deviceFileName, hostFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
814 self.getFileDone.emit(deviceFileName, hostFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
815 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
816 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
817
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
818 @pyqtSlot(str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
819 @pyqtSlot(str, str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
820 def put(self, hostFileName, deviceFileName=""):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
821 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
822 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
823
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
824 @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
825 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
826 @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
827 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
828 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
829 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
830 self.__fs.put(hostFileName, deviceFileName)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
831 self.putFileDone.emit(hostFileName, deviceFileName)
7080
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
832 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
833 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
834
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
835 @pyqtSlot(str)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
836 def delete(self, deviceFileName):
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
837 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
838 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
839
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
840 @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
841 @type str
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
842 """
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
843 try:
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
844 self.__fs.rm(deviceFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
845 self.deleteFileDone.emit(deviceFileName)
9a3adf033f90 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7077
diff changeset
846 except Exception as exc:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
847 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
848
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
849 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
850 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
851 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
852
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
853 @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
854 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
855 @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
856 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
857 @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
858 the device directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
859 @type bool
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
860 @return list of errors
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
861 @rtype list of str
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
862 """
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
863 errors = []
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
864
7083
217862c28319 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
865 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
866 return [self.tr(
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
867 "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
868 .format(hostDirectory)
7084
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
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
871 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
872 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
873 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
874
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
875 sourceDict = {}
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
876 sourceFiles = listdirStat(hostDirectory)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
877 for name, nstat in sourceFiles:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
878 sourceDict[name] = nstat
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
879
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
880 destinationDict = {}
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
881 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
882 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
883 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
884 return [str(exc)]
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
885 if destinationFiles is None:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
886 # the destination directory does not exist
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
887 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
888 self.__fs.mkdir(deviceDirectory)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
889 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
890 return [str(exc)]
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
891 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
892 for name, nstat in destinationFiles:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
893 destinationDict[name] = nstat
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
894
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
895 destinationSet = set(destinationDict.keys())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
896 sourceSet = set(sourceDict.keys())
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
897 toAdd = sourceSet - destinationSet # add to dev
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
898 toDelete = destinationSet - sourceSet # delete from dev
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
899 toUpdate = destinationSet.intersection(sourceSet) # update files
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
900
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
901 for sourceBasename in toAdd:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
902 # 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
903 sourceFilename = os.path.join(hostDirectory, sourceBasename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
904 destFilename = deviceDirectory + "/" + sourceBasename
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
905 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
906 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
907 if os.path.isfile(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
908 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
909 self.__fs.put(sourceFilename, destFilename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
910 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
911 # 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
912 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
913 if os.path.isdir(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
914 # recurse
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
915 errs = self.__rsync(sourceFilename, destFilename,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
916 mirror=mirror)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
917 # 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
918 errors.extend(errs)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
919
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
920 if mirror:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
921 for destBasename in toDelete:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
922 # 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
923 destFilename = deviceDirectory + "/" + destBasename
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
924 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
925 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
926 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
927 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
928 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
929 # 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
930 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
931
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
932 for sourceBasename in toUpdate:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
933 # 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
934 sourceStat = sourceDict[sourceBasename]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
935 destStat = destinationDict[sourceBasename]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
936 sourceFilename = os.path.join(hostDirectory, sourceBasename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
937 destFilename = deviceDirectory + "/" + sourceBasename
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
938 destMode = destStat[0]
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
939 if os.path.isdir(sourceFilename):
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
940 if stat.S_ISDIR(destMode):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
941 # both are directories => recurs
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
942 errs = self.__rsync(sourceFilename, destFilename,
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
943 mirror=mirror)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
944 # 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
945 errors.extend(errs)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
946 else:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
947 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
948 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
949 " 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
950 " it.")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
951 .format(sourceFilename, destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
952 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
953 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
954 if stat.S_ISDIR(destMode):
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
955 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
956 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
957 " <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
958 .format(sourceFilename, destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
959 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
960 else:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
961 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
962 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
963 self.tr("Updating <b>{0}</b>...")
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
964 .format(destFilename)
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
965 )
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
966 try:
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
967 self.__fs.put(sourceFilename, destFilename)
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
968 except Exception as exc:
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
969 errors.append(str(exc))
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
970
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
971 self.rsyncProgressMessage.emit(
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
972 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
973 )
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
974
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
975 return errors
7077
3b7475b7a1ef MicroPython: started to implement the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7070
diff changeset
976
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
977 @pyqtSlot(str, str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
978 @pyqtSlot(str, str, bool)
7081
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
979 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
980 """
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
981 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
982
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
983 @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
984 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
985 @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
986 @type str
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
987 @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
988 the device directory
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
989 @type bool
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
990 """
7084
3eddfc540614 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7083
diff changeset
991 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
992 if errors:
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
993 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
994
ed510767c096 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7080
diff changeset
995 self.rsyncDone.emit(hostDirectory, deviceDirectory)
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
996
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
997 @pyqtSlot(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
998 def mkdir(self, dirname):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
999 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1000 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
1001
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1002 @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
1003 @type str
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1004 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1005 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1006 self.__fs.mkdir(dirname)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1007 self.createDirectoryDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1008 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1009 self.error.emit("mkdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1010
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1011 @pyqtSlot(str)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1012 @pyqtSlot(str, bool)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1013 def rmdir(self, dirname, recursive=False):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1014 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1015 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
1016
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1017 @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
1018 @type str
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1019 @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
1020 @type bool
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1021 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1022 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1023 if recursive:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1024 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
1025 else:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1026 self.__fs.rmdir(dirname)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1027 self.removeDirectoryDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1028 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1029 self.error.emit("rmdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1030
7088
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1031 def fileSystemInfo(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1032 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1033 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
1034 systems.
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1035 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1036 try:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1037 fsinfo = self.__fs.fileSystemInfo()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1038 self.fsinfoDone.emit(fsinfo)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1039 except Exception as exc:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1040 self.error.emit("fileSystemInfo", str(exc))
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1041
7082
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1042 ##################################################################
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1043 ## some non-filesystem related methods below
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
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1046 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1047 def synchronizeTime(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1048 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1049 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
1050 computer's time.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1051 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1052 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1053 self.__fs.syncTime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1054 self.synchTimeDone.emit()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1055 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1056 self.error.emit("rmdir", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1057
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1058 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1059 def showTime(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1060 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1061 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
1062 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1063 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1064 dt = self.__fs.showTime()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1065 self.showTimeDone.emit(dt)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1066 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1067 self.error.emit("showTime", str(exc))
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1068
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1069 @pyqtSlot()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1070 def showVersion(self):
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1071 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1072 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
1073 connected device.
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1074 """
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1075 try:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1076 versionInfo = self.__fs.version()
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1077 self.showVersionDone.emit(versionInfo)
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1078 except Exception as exc:
ec199ef0cfc6 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7081
diff changeset
1079 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
1080
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1081 @pyqtSlot()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1082 def showImplementation(self):
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1083 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1084 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
1085 """
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1086 try:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1087 impInfo = self.__fs.getImplementation()
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1088 if impInfo["name"] == "micropython":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1089 name = "MicroPython"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1090 elif impInfo["name"] == "circuitpython":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1091 name = "CircuitPython"
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1092 elif impInfo["name"] == "unknown":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1093 name = self.tr("unknown")
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1094 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1095 name = impInfo["name"]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1096 if impInfo["version"] == "unknown":
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1097 version = self.tr("unknown")
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1098 else:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1099 version = impInfo["version"]
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1100 self.showImplementationDone.emit(name, version)
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1101 except Exception as exc:
e29b0ee86b29 MicroPython: continued implementing the file manager widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7084
diff changeset
1102 self.error.emit("showVersion", str(exc))

eric ide

mercurial