Skip to content

Commit

Permalink
Add new feature a file copy from device to local PC
Browse files Browse the repository at this point in the history
  • Loading branch information
JeongJun-Lee committed Dec 5, 2024
1 parent ce605d4 commit 410316b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
18 changes: 18 additions & 0 deletions mu/contrib/microfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ def put(self, filename, target=None, serial=None):


def get(self, filename, target=None, serial=None):
commands = [
"import sys",
"f = open('{}', 'rb')".format(filename),
"r = f.read",
"result = True",
"while result:\n result = r(32)\n if result:\n sys.stdout.buffer.write(result)\n",
"f.close()",
]
out, err = execute(commands, serial, True, self.on_put_update_file)
if err:
raise IOError(clean_error(err))
fd = open(target, 'wb')
fd.write(out)
fd.close()
return True


def get_by_uart(self, filename, target=None, serial=None):
"""
Gets a referenced file on the device's file system and copies it to the
target (or current working directory if unspecified).
Expand Down
21 changes: 10 additions & 11 deletions mu/interface/panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ class MicroPythonDeviceFileList(MuFileList):
Represents a list of files on a MicroPython device.
"""

put = pyqtSignal(str)
put = pyqtSignal(str, str)
delete = pyqtSignal(str)
is_dir = pyqtSignal(str)
open_file = pyqtSignal(str)
Expand All @@ -732,13 +732,12 @@ def dropEvent(self, event):
and self.show_confirm_overwrite_dialog()
):
self.disable.emit()
local_filename = os.path.join(
source.cur_home_dir, source.currentItem().text()
)
local_filename = os.path.join(source.cur_home_dir, source.currentItem().text())
microbit_filename = os.path.join(self.cur_home_dir, source.currentItem().text())
msg = _("Copying '{}' to device.").format(local_filename)
logger.info(msg)
self.set_message.emit(msg)
self.put.emit(local_filename)
self.put.emit(local_filename, microbit_filename)

def on_put(self, microbit_file):
"""
Expand Down Expand Up @@ -767,7 +766,7 @@ def contextMenuEvent(self, event):
msg = _("Deleting '{}' from device.").format(microbit_filename)
logger.info(msg)
self.set_message.emit(msg)
self.delete.emit(microbit_filename)
self.delete.emit(self.cur_home_dir + microbit_filename)

def on_delete(self, microbit_file):
"""
Expand Down Expand Up @@ -815,8 +814,8 @@ def dropEvent(self, event):
and self.show_confirm_overwrite_dialog()
):
self.disable.emit()
microbit_filename = source.currentItem().text()
local_filename = os.path.join(self.home, microbit_filename)
microbit_filename = os.path.join(source.cur_home_dir, source.currentItem().text())
local_filename = os.path.join(self.cur_home_dir, source.currentItem().text())
msg = _(
"Getting '{}' from device. " "Copying to '{}'."
).format(microbit_filename, local_filename)
Expand All @@ -832,7 +831,7 @@ def on_get(self, microbit_file):
"Successfully copied '{}' " "from the device to your computer."
).format(microbit_file)
self.set_message.emit(msg)
self.list_files.emit(self.cur_home_dir)
self.list_sub_files.emit([], self.cur_home_dir)
self.pbar_update.emit(-1) # To remove the pbar UI
self.enable.emit()

Expand Down Expand Up @@ -953,8 +952,8 @@ def enable(self):
"""
self.microbit_fs.setDisabled(False)
self.local_fs.setDisabled(False)
self.microbit_fs.setAcceptDrops(True) # Temporaraily
self.local_fs.setAcceptDrops(False)
self.microbit_fs.setAcceptDrops(True)
self.local_fs.setAcceptDrops(True)

def show_message(self, message):
"""
Expand Down
Binary file modified mu/locale/uz_UZ/LC_MESSAGES/mu.mo
Binary file not shown.
17 changes: 8 additions & 9 deletions mu/locale/uz_UZ/LC_MESSAGES/mu.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: mu-editor\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-11-25 00:20+0500\n"
"PO-Revision-Date: 2024-08-10 15:04\n"
"PO-Revision-Date: 2024-12-05 11:33\n"
"Last-Translator: \n"
"Language: uz\n"
"Language-Team: Uzbek\n"
Expand Down Expand Up @@ -435,20 +435,16 @@ msgid "There was a problem getting the list of files on the device. Please check
msgstr "Qurilmadagi fayllar roʻyxatini olishda muammo yuz berdi. Iltimos, texnik ma'lumot uchun Mu jurnalini tekshiring. Shu bilan bir qatorda, qurilmangizni uzib/ulang va/yoki Mu-ni qayta ishga tushiring."

#: mu/interface/panes.py:966
msgid "There was a problem copying the file '{}' onto the device. Please check Mu's logs for more information."
msgid "There was a problem copying the file '{}' onto the device. Please check Please check if you try to copy a directory or not and also Mu's logs for more information."
msgstr "“{}” faylini qurilmaga nusxalashda muammo yuz berdi. Folderni nusxalash urinishi emas, aniq faylligini tekshiring. Va qo'shimcha ma'lumot olish uchun Muning jurnallarini tekshiring."

#: mu/interface/panes.py:978
msgid "There was a problem deleting '{}' from the device. Please check Mu's logs for more information."
msgstr "“{}” faylini qurilmaga o'chirishda muammo yuz berdi. Qo'shimcha ma'lumot olish uchun Muning jurnallarini tekshiring."

#: mu/interface/panes.py:990
msgid "There was a problem getting '{}' from the device. Please check Mu's logs for more information."
msgstr "“{}” faylini qurilmaga olishda muammo yuz berdi. Qo'shimcha ma'lumot olish uchun Muning jurnallarini tekshiring."

#: mu/interface/panes.py:1034
msgid "The file open in device file system, Currently not supported"
msgstr "Qurilmada fayl ochilmoqda, hozirda qo'llab-quvvatlash qilinmaydi"
msgid "There was a problem getting '{}' from the device. Please check Please check if you try to copy a directory or not and also Mu's logs for more information."
msgstr "“{}” faylini qurilmaga olishda muammo yuz berdi. Folderni nusxalash urinishi emas, aniq faylligini tekshiring. Va qo'shimcha ma'lumot olish uchun Muning jurnallarini tekshiring."

#: mu/interface/widgets.py:70 mu/interface/widgets.py:141
#: mu/interface/widgets.py:154
Expand Down Expand Up @@ -1530,7 +1526,10 @@ msgstr "O'yinni tarqatish uchun bitta exe fayliga aylantiradi."
msgid "Stop packaging your Pygame Zero game."
msgstr "Bitta fayliga aylantirayotganini to'xtaydi."

#: #: mu/main.py:225
#: mu/main.py:225
msgid "There is un-saved work, closing the tab will cause you to lose it."
msgstr "Saqlanmagan ish bor, tabdan chiqish uni yo'qotishingizga olib keladi."

#: mu/panes.py:1027
msgid "The file open in device file system, Currently not supported."
msgstr "Qurilmada fayl ochilmoqda, hozirda qo'llab-quvvatlash qilinmaydi."
3 changes: 3 additions & 0 deletions mu/modes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ def ls(self, path='./'):
self.on_list_fail.emit()

def is_dir(self, path):
"""
Check the path is directory or not in the device.
"""
try:
result = microfs.is_dir(path, self.serial)
if not result:
Expand Down
3 changes: 2 additions & 1 deletion mu/wheels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class WheelsBuildError(WheelsError):
# from setup.py. This is version has to mirror the one from setup.py
("ipykernel", ("ipykernel>=5.5.6,<6",)),
# For Neopia mode
("neopia", ("neopia>=0.3.6",)),
("neopia", ("neopia>=0.3.6", "numpy<=1.24.3", "matplotlib<3.8", "contourpy<1.1"), "--extra-index-url",
"https://roboticsware-90up95s1.pypimirror.stablebuild.com/2024-02-01",),
# For pgzero's extenstion
("pgzhelper", ("pgzhelper_rw>=1.0.9",)),
]
Expand Down

0 comments on commit 410316b

Please sign in to comment.