66 createDirectoryDone = pyqtSignal() |
66 createDirectoryDone = pyqtSignal() |
67 fsinfoDone = pyqtSignal(tuple) |
67 fsinfoDone = pyqtSignal(tuple) |
68 |
68 |
69 error = pyqtSignal(str, str) |
69 error = pyqtSignal(str, str) |
70 |
70 |
71 def __init__(self, commandsInterface, parent=None): |
71 def __init__(self, device, parent=None): |
72 """ |
72 """ |
73 Constructor |
73 Constructor |
74 |
74 |
75 @param commandsInterface reference to the commands interface object |
75 @param device MicroPython device object |
76 @type MicroPythonCommandsInterface |
76 @type BaseDevice |
77 @param parent reference to the parent object |
77 @param parent reference to the parent object |
78 @type QObject |
78 @type QObject |
79 """ |
79 """ |
80 super().__init__(parent) |
80 super().__init__(parent) |
81 |
81 |
82 self.__commandsInterface = commandsInterface |
82 self.__device = device |
83 |
83 |
84 @pyqtSlot(str) |
84 @pyqtSlot(str) |
85 def lls(self, dirname, showHidden=False): |
85 def lls(self, dirname, showHidden=False): |
86 """ |
86 """ |
87 Public slot to get a long listing of the given directory. |
87 Public slot to get a long listing of the given directory. |
110 def pwd(self): |
110 def pwd(self): |
111 """ |
111 """ |
112 Public slot to get the current directory of the device. |
112 Public slot to get the current directory of the device. |
113 """ |
113 """ |
114 try: |
114 try: |
115 pwd = self.__commandsInterface.pwd() |
115 pwd = self.__device.pwd() |
116 self.currentDir.emit(pwd) |
116 self.currentDir.emit(pwd) |
117 except Exception as exc: |
117 except Exception as exc: |
118 self.error.emit("pwd", str(exc)) |
118 self.error.emit("pwd", str(exc)) |
119 |
119 |
120 @pyqtSlot(str) |
120 @pyqtSlot(str) |
124 |
124 |
125 @param dirname name of the desired current directory |
125 @param dirname name of the desired current directory |
126 @type str |
126 @type str |
127 """ |
127 """ |
128 try: |
128 try: |
129 self.__commandsInterface.cd(dirname) |
129 self.__device.cd(dirname) |
130 self.currentDirChanged.emit(dirname) |
130 self.currentDirChanged.emit(dirname) |
131 except Exception as exc: |
131 except Exception as exc: |
132 self.error.emit("cd", str(exc)) |
132 self.error.emit("cd", str(exc)) |
133 |
133 |
134 @pyqtSlot(str) |
134 @pyqtSlot(str) |
144 """ |
144 """ |
145 if hostFileName and os.path.isdir(hostFileName): |
145 if hostFileName and os.path.isdir(hostFileName): |
146 # only a local directory was given |
146 # only a local directory was given |
147 hostFileName = os.path.join(hostFileName, os.path.basename(deviceFileName)) |
147 hostFileName = os.path.join(hostFileName, os.path.basename(deviceFileName)) |
148 try: |
148 try: |
149 self.__commandsInterface.get(deviceFileName, hostFileName) |
149 self.__device.get(deviceFileName, hostFileName) |
150 self.getFileDone.emit(deviceFileName, hostFileName) |
150 self.getFileDone.emit(deviceFileName, hostFileName) |
151 except Exception as exc: |
151 except Exception as exc: |
152 self.error.emit("get", str(exc)) |
152 self.error.emit("get", str(exc)) |
153 |
153 |
154 def getData(self, deviceFileName): |
154 def getData(self, deviceFileName): |
177 @type str |
177 @type str |
178 @param deviceFileName name of the file on the connected device |
178 @param deviceFileName name of the file on the connected device |
179 @type str |
179 @type str |
180 """ |
180 """ |
181 try: |
181 try: |
182 self.__commandsInterface.put(hostFileName, deviceFileName) |
182 self.__device.put(hostFileName, deviceFileName) |
183 self.putFileDone.emit(hostFileName, deviceFileName) |
183 self.putFileDone.emit(hostFileName, deviceFileName) |
184 except Exception as exc: |
184 except Exception as exc: |
185 self.error.emit("put", str(exc)) |
185 self.error.emit("put", str(exc)) |
186 |
186 |
187 def putData(self, deviceFileName, data): |
187 def putData(self, deviceFileName, data): |
188 """ |
188 """ |
189 Public method to write data to the connected device. |
189 Public method to write data to the connected device. |
190 |
190 |
191 @param deviceFileName name of the file to write to |
191 @param deviceFileName name of the file to write to |
192 @type str |
192 @type str |
193 @param content data to write |
193 @param data data to write |
194 @type bytes |
194 @type bytes |
195 """ |
195 """ |
196 try: |
196 try: |
197 self.__commandsInterface.putData(deviceFileName, data) |
197 self.__device.putData(deviceFileName, data) |
198 self.putDataDone.emit(deviceFileName) |
198 self.putDataDone.emit(deviceFileName) |
199 except Exception as exc: |
199 except Exception as exc: |
200 self.error.emit("putData", str(exc)) |
200 self.error.emit("putData", str(exc)) |
201 |
201 |
202 @pyqtSlot(str) |
202 @pyqtSlot(str) |
206 |
206 |
207 @param deviceFileName name of the file on the connected device |
207 @param deviceFileName name of the file on the connected device |
208 @type str |
208 @type str |
209 """ |
209 """ |
210 try: |
210 try: |
211 self.__commandsInterface.rm(deviceFileName) |
211 self.__device.rm(deviceFileName) |
212 self.deleteFileDone.emit(deviceFileName) |
212 self.deleteFileDone.emit(deviceFileName) |
213 except Exception as exc: |
213 except Exception as exc: |
214 self.error.emit("delete", str(exc)) |
214 self.error.emit("delete", str(exc)) |
215 |
215 |
216 def __rsync( |
216 def __rsync( |
273 destinationFiles = listdirStat(deviceDirectory) |
273 destinationFiles = listdirStat(deviceDirectory) |
274 for name, nstat in destinationFiles: |
274 for name, nstat in destinationFiles: |
275 destinationDict[name] = nstat |
275 destinationDict[name] = nstat |
276 else: |
276 else: |
277 try: |
277 try: |
278 destinationFiles = self.__commandsInterface.lls( |
278 destinationFiles = self.__device.lls(deviceDirectory, fullstat=True) |
279 deviceDirectory, fullstat=True |
|
280 ) |
|
281 except Exception as exc: |
279 except Exception as exc: |
282 return [str(exc)] |
280 return [str(exc)] |
283 if destinationFiles is None: |
281 if destinationFiles is None: |
284 # the destination directory does not exist |
282 # the destination directory does not exist |
285 try: |
283 try: |
286 self.__commandsInterface.mkdir(deviceDirectory) |
284 self.__device.mkdir(deviceDirectory) |
287 except Exception as exc: |
285 except Exception as exc: |
288 return [str(exc)] |
286 return [str(exc)] |
289 else: |
287 else: |
290 for name, nstat in destinationFiles: |
288 for name, nstat in destinationFiles: |
291 destinationDict[name] = nstat |
289 destinationDict[name] = nstat |
385 self.rsyncProgressMessage.emit( |
383 self.rsyncProgressMessage.emit( |
386 self.tr("{1}Adding <b>{0}</b>...").format(destFilename, indentStr) |
384 self.tr("{1}Adding <b>{0}</b>...").format(destFilename, indentStr) |
387 ) |
385 ) |
388 if os.path.isfile(sourceFilename): |
386 if os.path.isfile(sourceFilename): |
389 try: |
387 try: |
390 self.__commandsInterface.put(sourceFilename, destFilename) |
388 self.__device.put(sourceFilename, destFilename) |
391 except Exception as exc: |
389 except Exception as exc: |
392 # just note issues but ignore them otherwise |
390 # just note issues but ignore them otherwise |
393 errors.append(str(exc)) |
391 errors.append(str(exc)) |
394 elif os.path.isdir(sourceFilename): |
392 elif os.path.isdir(sourceFilename): |
395 # recurse |
393 # recurse |
414 self.tr("{1}Removing <b>{0}</b>...").format( |
412 self.tr("{1}Removing <b>{0}</b>...").format( |
415 destFilename, indentStr |
413 destFilename, indentStr |
416 ) |
414 ) |
417 ) |
415 ) |
418 try: |
416 try: |
419 self.__commandsInterface.rmrf( |
417 self.__device.rmrf(destFilename, recursive=True, force=True) |
420 destFilename, recursive=True, force=True |
|
421 ) |
|
422 except Exception as exc: |
418 except Exception as exc: |
423 # just note issues but ignore them otherwise |
419 # just note issues but ignore them otherwise |
424 errors.append(str(exc)) |
420 errors.append(str(exc)) |
425 |
421 |
426 for sourceBasename in toUpdate: |
422 for sourceBasename in toUpdate: |
468 self.tr("{1}Updating <b>{0}</b>...").format( |
464 self.tr("{1}Updating <b>{0}</b>...").format( |
469 destFilename, indentStr |
465 destFilename, indentStr |
470 ) |
466 ) |
471 ) |
467 ) |
472 try: |
468 try: |
473 self.__commandsInterface.put( |
469 self.__device.put(sourceFilename, destFilename) |
474 sourceFilename, destFilename |
|
475 ) |
|
476 except Exception as exc: |
470 except Exception as exc: |
477 errors.append(str(exc)) |
471 errors.append(str(exc)) |
478 |
472 |
479 self.rsyncProgressMessage.emit(doneMessage) |
473 self.rsyncProgressMessage.emit(doneMessage) |
480 |
474 |
512 |
506 |
513 @param dirname name of the directory to create |
507 @param dirname name of the directory to create |
514 @type str |
508 @type str |
515 """ |
509 """ |
516 try: |
510 try: |
517 self.__commandsInterface.mkdir(dirname) |
511 self.__device.mkdir(dirname) |
518 self.createDirectoryDone.emit() |
512 self.createDirectoryDone.emit() |
519 except Exception as exc: |
513 except Exception as exc: |
520 self.error.emit("mkdir", str(exc)) |
514 self.error.emit("mkdir", str(exc)) |
521 |
515 |
522 @pyqtSlot(str) |
516 @pyqtSlot(str) |
530 @param recursive flag indicating a recursive removal |
524 @param recursive flag indicating a recursive removal |
531 @type bool |
525 @type bool |
532 """ |
526 """ |
533 try: |
527 try: |
534 if recursive: |
528 if recursive: |
535 self.__commandsInterface.rmrf(dirname, recursive=True, force=True) |
529 self.__device.rmrf(dirname, recursive=True, force=True) |
536 else: |
530 else: |
537 self.__commandsInterface.rmdir(dirname) |
531 self.__device.rmdir(dirname) |
538 self.removeDirectoryDone.emit() |
532 self.removeDirectoryDone.emit() |
539 except Exception as exc: |
533 except Exception as exc: |
540 self.error.emit("rmdir", str(exc)) |
534 self.error.emit("rmdir", str(exc)) |
541 |
535 |
542 def fileSystemInfo(self): |
536 def fileSystemInfo(self): |
543 """ |
537 """ |
544 Public method to obtain information about the currently mounted file |
538 Public method to obtain information about the currently mounted file |
545 systems. |
539 systems. |
546 """ |
540 """ |
547 try: |
541 try: |
548 fsinfo = self.__commandsInterface.fileSystemInfo() |
542 fsinfo = self.__device.fileSystemInfo() |
549 self.fsinfoDone.emit(fsinfo) |
543 self.fsinfoDone.emit(fsinfo) |
550 except Exception as exc: |
544 except Exception as exc: |
551 self.error.emit("fileSystemInfo", str(exc)) |
545 self.error.emit("fileSystemInfo", str(exc)) |