feat(core): micropython 板卡文件管理 右键菜单添加 剪切复制粘贴 选项

This commit is contained in:
王立帮
2025-08-24 04:33:08 +08:00
parent 16a72f1773
commit 4f26f8e9f4
14 changed files with 299 additions and 35 deletions

View File

@@ -337,7 +337,7 @@ def put(local, remote):
else:
sys.stdout.write("Skip " + filename + "\n")
sys.stdout.flush()
board_files.putDir(file_name_list, data_list, False)
board_files.putdir(file_name_list, data_list, False)
'''
for filename in child_files:
@@ -404,6 +404,22 @@ def rename(oldname, newname):
board_files.rename(oldname, newname)
@cli.command()
@click.argument("local", required=True)
@click.argument("remote", required=True)
def cpdir(local, remote):
board_files = files.Files(_board)
board_files.cpdir(local, remote)
@cli.command()
@click.argument("local", required=True)
@click.argument("remote", required=True)
def cpfile(local, remote):
board_files = files.Files(_board)
board_files.cpfile(local, remote)
@cli.command()
@click.argument("local_file")
@click.option(

View File

@@ -388,7 +388,7 @@ class Files(object):
if exit_repl:
self._pyboard.exit_raw_repl()
def putDir(self, fileNameList, dataList, enter_repl=True, exit_repl=True):
def putdir(self, fileNameList, dataList, enter_repl=True, exit_repl=True):
"""Create or update the specified file with the provided data.
"""
# Open the file for writing on the board and write chunks of data.
@@ -458,6 +458,7 @@ class Files(object):
import os
except ImportError:
import uos as os
def rmdir(directory):
os.chdir(directory)
for f in os.listdir():
@@ -506,6 +507,70 @@ class Files(object):
raise ex
self._pyboard.exit_raw_repl()
def cpdir(self, oldpath, newpath):
command = """
try:
import os
except ImportError:
import uos as os
def cpfile(src, dst):
with open(src, 'rb') as src_file:
content = src_file.read()
with open(dst, 'wb') as dst_file:
dst_file.write(content)
def cpdir(src, dst):
try:
os.mkdir(dst)
except:
pass
for item in os.listdir(src):
src_path = src + '/' + item
dst_path = dst + '/' + item
stat = os.stat(src_path)
mode = stat[0]
if mode & 0o170000 == 0o040000:
cpdir(src_path, dst_path)
else:
cpfile(src_path, dst_path)
cpdir('{0}', '{1}')
""".format(
oldpath, newpath
)
self._pyboard.enter_raw_repl()
try:
out = self._pyboard.exec_(textwrap.dedent(command))
except PyboardError as ex:
message = ex.args[2].decode("utf-8")
raise ex
self._pyboard.exit_raw_repl()
def cpfile(self, oldpath, newpath):
command = """
try:
import os
except ImportError:
import uos as os
def cpfile(src, dst):
with open(src, 'rb') as src_file:
content = src_file.read()
with open(dst, 'wb') as dst_file:
dst_file.write(content)
cpfile('{0}', '{1}')
""".format(
oldpath, newpath
)
self._pyboard.enter_raw_repl()
try:
out = self._pyboard.exec_(textwrap.dedent(command))
except PyboardError as ex:
message = ex.args[2].decode("utf-8")
raise ex
self._pyboard.exit_raw_repl()
def run(self, filename, wait_output=True, stream_output=True):
"""Run the provided script and return its output. If wait_output is True
(default) then wait for the script to finish and then return its output,