src/eric7/MicroPython/MicroPythonFileManager.py

branch
eric7
changeset 9853
080e060a0383
parent 9852
b7aef103355a
child 10019
e56089d00750
equal deleted inserted replaced
9852:b7aef103355a 9853:080e060a0383
213 try: 213 try:
214 self.__device.putData(deviceFileName, data) 214 self.__device.putData(deviceFileName, data)
215 self.putDataDone.emit(deviceFileName) 215 self.putDataDone.emit(deviceFileName)
216 except Exception as exc: 216 except Exception as exc:
217 self.error.emit("putData", str(exc)) 217 self.error.emit("putData", str(exc))
218
219 def writeFile(self, filename, text):
220 """
221 Public method to write some text to a file on the connected device.
222
223 @param filename name of the file on the connected device
224 @type str
225 @param text text to be written
226 @type str
227 @return flag indicating success
228 @rtype bool
229 """
230 if self.__device.supportsLocalFileAccess():
231 try:
232 with open(filename, "w") as f:
233 f.write(text)
234 return True
235 except OSError as exc:
236 self.error.emit("writeFile", str(exc))
237 return False
238 else:
239 try:
240 self.__device.putData(filename, text.encode("utf-8"))
241 self.putDataDone.emit(filename)
242 return True
243 except Exception as exc:
244 self.error.emit("writeFile", str(exc))
245 return False
218 246
219 @pyqtSlot(str) 247 @pyqtSlot(str)
220 def delete(self, deviceFileName): 248 def delete(self, deviceFileName):
221 """ 249 """
222 Public slot to delete a file on the device. 250 Public slot to delete a file on the device.
529 self.createDirectoryDone.emit() 557 self.createDirectoryDone.emit()
530 except Exception as exc: 558 except Exception as exc:
531 self.error.emit("mkdir", str(exc)) 559 self.error.emit("mkdir", str(exc))
532 560
533 @pyqtSlot(str) 561 @pyqtSlot(str)
562 def makedirs(self, dirname):
563 """
564 Public slot to create a new directory and all intermediates.
565
566 @param dirname name of the directory to create
567 @type str
568 """
569 parts = [d for d in dirname.split("/") if bool(d)]
570 dname = ""
571 try:
572 for part in parts:
573 dname += "/" + part
574 if not self.__device.exists(dname):
575 self.__device.mkdir(dname)
576 self.createDirectoryDone.emit()
577 except Exception as exc:
578 self.error.emit("makedirs", str(exc))
579
580 @pyqtSlot(str)
534 @pyqtSlot(str, bool) 581 @pyqtSlot(str, bool)
535 def rmdir(self, dirname, recursive=False): 582 def rmdir(self, dirname, recursive=False):
536 """ 583 """
537 Public slot to (recursively) remove a directory. 584 Public slot to (recursively) remove a directory.
538 585

eric ide

mercurial