feat(core): micropython 板卡文件管理 右键菜单添加 剪切 、复制 和 粘贴 选项
This commit is contained in:
@@ -869,16 +869,18 @@ class FileTree extends Component {
|
|||||||
let startPath = oldNode.id;
|
let startPath = oldNode.id;
|
||||||
let endPath = path.join(folderPath, oldNode.text);
|
let endPath = path.join(folderPath, oldNode.text);
|
||||||
if (mode === 'move_node') {
|
if (mode === 'move_node') {
|
||||||
if (type === 'file') {
|
const relativePath = path.relative(startPath, endPath);
|
||||||
pastePromise = this.#fs_.moveFile(startPath, endPath);
|
if (relativePath.indexOf('..') === -1) {
|
||||||
|
pastePromise = Promise.resolve();
|
||||||
} else {
|
} else {
|
||||||
pastePromise = this.#fs_.createDirectory(endPath)
|
if (type === 'file') {
|
||||||
.then(() => {
|
pastePromise = this.#fs_.moveFile(startPath, endPath);
|
||||||
return this.#fs_.moveDirectory(startPath, endPath);
|
} else {
|
||||||
})
|
pastePromise = this.#fs_.createDirectory(endPath)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.#fs_.deleteDirectory(startPath);
|
return this.#fs_.moveDirectory(startPath, endPath);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (mode === 'copy_node') {
|
} else if (mode === 'copy_node') {
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
@@ -891,21 +893,62 @@ class FileTree extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pastePromise
|
pastePromise
|
||||||
.catch(Debug.error)
|
.then(async () => {
|
||||||
.finally(() => {
|
if (mode === 'move_node') {
|
||||||
this.clearFolderTemp(folderPath);
|
const temp = path.join(startPath, '..');
|
||||||
this.#jstree_.refresh_node(folderPath);
|
const relativePath = path.relative(temp, endPath);
|
||||||
this.openNode(folderPath);
|
if (relativePath.indexOf('..') === -1) {
|
||||||
this.hideProgress();
|
this.clearFolderTemp(temp);
|
||||||
|
await this.loadNode(temp);
|
||||||
|
await this.openNode(temp);
|
||||||
|
this.clearFolderTemp(folderPath);
|
||||||
|
await this.loadNode(folderPath);
|
||||||
|
await this.openNode(folderPath);
|
||||||
|
} else {
|
||||||
|
this.clearFolderTemp(folderPath);
|
||||||
|
await this.loadNode(folderPath);
|
||||||
|
await this.openNode(folderPath);
|
||||||
|
this.clearFolderTemp(temp);
|
||||||
|
await this.loadNode(temp);
|
||||||
|
await this.openNode(temp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.clearFolderTemp(folderPath);
|
||||||
|
this.#jstree_.refresh_node(folderPath);
|
||||||
|
this.openNode(folderPath);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(Debug.error)
|
||||||
|
.finally(() => {
|
||||||
|
this.hideProgress();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
loadNode(inPath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (inPath === '/') {
|
||||||
|
inPath = '#';
|
||||||
|
}
|
||||||
|
const node = this.#jstree_.get_node(inPath);
|
||||||
|
if (!node) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
this.#jstree_.load_node(node, () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openNode(folderPath) {
|
openNode(folderPath) {
|
||||||
const node = this.#jstree_.get_node(folderPath);
|
return new Promise((resolve, reject) => {
|
||||||
if (!node) {
|
const node = this.#jstree_.get_node(folderPath);
|
||||||
return;
|
if (!node) {
|
||||||
}
|
resolve();
|
||||||
this.#jstree_.open_node(node);
|
}
|
||||||
|
this.#jstree_.open_node(node, () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
|||||||
@@ -351,11 +351,6 @@ class StatusBarAmpy extends PageBase {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fileTreeMenu.remove('copy');
|
|
||||||
fileTreeMenu.remove('cut');
|
|
||||||
fileTreeMenu.remove('paste');
|
|
||||||
fileTreeMenu.remove('sep2');
|
|
||||||
|
|
||||||
const editorContextMenu = this.#editor_.getContextMenu();
|
const editorContextMenu = this.#editor_.getContextMenu();
|
||||||
const editorMenu = editorContextMenu.getItem('code');
|
const editorMenu = editorContextMenu.getItem('code');
|
||||||
|
|
||||||
|
|||||||
@@ -106,9 +106,21 @@ class AmpyFS extends FS {
|
|||||||
return this.rename(oldFilePath, newFilePath);
|
return this.rename(oldFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// async moveFile(oldFilePath, newFilePath) {}
|
async moveFile(oldFilePath, newFilePath) {
|
||||||
|
return this.rename(oldFilePath, newFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
// async copyFile(oldFilePath, newFilePath) {}
|
async copyFile(oldFilePath, newFilePath) {
|
||||||
|
let stdout = '', error = null;
|
||||||
|
try {
|
||||||
|
const output = await this.#ampy_.cpfile(this.#port_, this.#baud_, oldFilePath, newFilePath);
|
||||||
|
stdout = output.stdout;
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
return [error, stdout];
|
||||||
|
}
|
||||||
|
|
||||||
async deleteFile(filePath) {
|
async deleteFile(filePath) {
|
||||||
let stdout = '', error = null;
|
let stdout = '', error = null;
|
||||||
@@ -179,9 +191,21 @@ class AmpyFS extends FS {
|
|||||||
return this.rename(oldFolderPath, newFolderPath);
|
return this.rename(oldFolderPath, newFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// async moveDirectory(oldFolderPath, newFolderPath) {}
|
async moveDirectory(oldFolderPath, newFolderPath) {
|
||||||
|
return this.rename(oldFolderPath, newFolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
// async copyDirectory(oldFolderPath, newFolderPath) {}
|
async copyDirectory(oldFolderPath, newFolderPath) {
|
||||||
|
let stdout = '', error = null;
|
||||||
|
try {
|
||||||
|
const output = await this.#ampy_.cpdir(this.#port_, this.#baud_, oldFolderPath, newFolderPath);
|
||||||
|
stdout = output.stdout;
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
return [error, stdout];
|
||||||
|
}
|
||||||
|
|
||||||
async deleteDirectory(folderPath) {
|
async deleteDirectory(folderPath) {
|
||||||
let stdout = '', error = null;
|
let stdout = '', error = null;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ class AmpyExt extends Ampy {
|
|||||||
rm: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rm "{{&filePath}}"',
|
rm: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rm "{{&filePath}}"',
|
||||||
rmdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rmdir "{{&folderPath}}"',
|
rmdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rmdir "{{&folderPath}}"',
|
||||||
rename: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rename "{{&oldPath}}" "{{&newPath}}"',
|
rename: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rename "{{&oldPath}}" "{{&newPath}}"',
|
||||||
|
cpdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 cpdir "{{&startPath}}" "{{&endPath}}"',
|
||||||
|
cpfile: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 cpfile "{{&startPath}}" "{{&endPath}}"',
|
||||||
run: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 run "{{&filePath}}"'
|
run: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 run "{{&filePath}}"'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +92,14 @@ class AmpyExt extends Ampy {
|
|||||||
return this.exec(port, this.render('rename', { port, baud, oldPath, newPath }));
|
return this.exec(port, this.render('rename', { port, baud, oldPath, newPath }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async cpdir(port, baud, startPath, endPath) {
|
||||||
|
return this.exec(port, this.render('cpdir', { port, baud, startPath, endPath }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async cpfile(port, baud, startPath, endPath) {
|
||||||
|
return this.exec(port, this.render('cpfile', { port, baud, startPath, endPath }));
|
||||||
|
}
|
||||||
|
|
||||||
async run(port, baud, filePath) {
|
async run(port, baud, filePath) {
|
||||||
return this.exec(port, this.render('run', { port, baud, filePath }));
|
return this.exec(port, this.render('run', { port, baud, filePath }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,9 +125,29 @@ class AmpyFS extends FS {
|
|||||||
return this.rename(oldFilePath, newFilePath);
|
return this.rename(oldFilePath, newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// async moveFile(oldFilePath, newFilePath) {}
|
async moveFile(oldFilePath, newFilePath) {
|
||||||
|
return this.rename(oldFilePath, newFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
// async copyFile(oldFilePath, newFilePath) {}
|
async copyFile(oldFilePath, newFilePath) {
|
||||||
|
let stdout = '', error = null, ampy = null;
|
||||||
|
try {
|
||||||
|
ampy = await this.getAmpy();
|
||||||
|
await ampy.enter();
|
||||||
|
stdout = await ampy.cpfile(oldFilePath, newFilePath);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await ampy.exit();
|
||||||
|
await ampy.dispose();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
return [error, stdout];
|
||||||
|
}
|
||||||
|
|
||||||
async deleteFile(filePath) {
|
async deleteFile(filePath) {
|
||||||
let stdout = '', error = null, ampy = null;
|
let stdout = '', error = null, ampy = null;
|
||||||
@@ -206,9 +226,29 @@ class AmpyFS extends FS {
|
|||||||
return this.rename(oldFolderPath, newFolderPath);
|
return this.rename(oldFolderPath, newFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// async moveDirectory(oldFolderPath, newFolderPath) {}
|
async moveDirectory(oldFolderPath, newFolderPath) {
|
||||||
|
return this.rename(oldFolderPath, newFolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
// async copyDirectory(oldFolderPath, newFolderPath) {}
|
async copyDirectory(oldFolderPath, newFolderPath) {
|
||||||
|
let stdout = '', error = null, ampy = null;
|
||||||
|
try {
|
||||||
|
ampy = await this.getAmpy();
|
||||||
|
await ampy.enter();
|
||||||
|
stdout = await ampy.cpdir(oldFolderPath, newFolderPath);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await ampy.exit();
|
||||||
|
await ampy.dispose();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
Debug.error(error);
|
||||||
|
}
|
||||||
|
return [error, stdout];
|
||||||
|
}
|
||||||
|
|
||||||
async deleteDirectory(folderPath) {
|
async deleteDirectory(folderPath) {
|
||||||
let stdout = '', error = null, ampy = null;
|
let stdout = '', error = null, ampy = null;
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class AmpyExt extends Ampy {
|
|||||||
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
|
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
|
||||||
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
|
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
|
||||||
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
|
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
|
||||||
|
this.CPDIR = goog.readFileSync(path.join(Env.templatePath, 'python/cpdir.py'));
|
||||||
|
this.CPFILE = goog.readFileSync(path.join(Env.templatePath, 'python/cpfile.py'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#device_ = null;
|
#device_ = null;
|
||||||
@@ -338,6 +340,31 @@ class AmpyExt extends Ampy {
|
|||||||
return !dataError;
|
return !dataError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async cpdir(oldname, newname, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.CPDIR, {
|
||||||
|
oldPath: oldname,
|
||||||
|
newPath: newname
|
||||||
|
});
|
||||||
|
const { data, dataError } = await this.exec(code, timeout);
|
||||||
|
console.log(data, dataError)
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async cpfile(oldname, newname, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.CPFILE, {
|
||||||
|
oldPath: oldname,
|
||||||
|
newPath: newname
|
||||||
|
});
|
||||||
|
const { dataError } = await this.exec(code, timeout);
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
async cwd(timeout = 5000) {
|
async cwd(timeout = 5000) {
|
||||||
if (!this.isActive()) {
|
if (!this.isActive()) {
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
|||||||
27
common/templates/python/cpdir.py
Normal file
27
common/templates/python/cpdir.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
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 = '{}/{}'.format(src, item)
|
||||||
|
dst_path = '{}/{}'.format(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('{{&oldPath}}', '{{&newPath}}')
|
||||||
12
common/templates/python/cpfile.py
Normal file
12
common/templates/python/cpfile.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
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('{{&oldPath}}', '{{&newPath}}')
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import ubinascii
|
import ubinascii
|
||||||
|
|
||||||
with open('{{&path}}', 'rb') as infile:
|
with open('{{&path}}', 'rb') as infile:
|
||||||
while True:
|
while True:
|
||||||
result = infile.read(32)
|
result = infile.read(32)
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ try:
|
|||||||
import os
|
import os
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import uos as os
|
import uos as os
|
||||||
|
|
||||||
os.mkdir('{{&path}}')
|
os.mkdir('{{&path}}')
|
||||||
@@ -2,4 +2,5 @@ try:
|
|||||||
import os
|
import os
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import uos as os
|
import uos as os
|
||||||
|
|
||||||
os.remove('{{&path}}')
|
os.remove('{{&path}}')
|
||||||
@@ -2,6 +2,7 @@ try:
|
|||||||
import os
|
import os
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import uos as os
|
import uos as os
|
||||||
|
|
||||||
def rmdir(directory):
|
def rmdir(directory):
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
for f in os.listdir():
|
for f in os.listdir():
|
||||||
@@ -13,4 +14,5 @@ def rmdir(directory):
|
|||||||
rmdir(f)
|
rmdir(f)
|
||||||
os.chdir('..')
|
os.chdir('..')
|
||||||
os.rmdir(directory)
|
os.rmdir(directory)
|
||||||
|
|
||||||
rmdir('{{&path}}')
|
rmdir('{{&path}}')
|
||||||
@@ -337,7 +337,7 @@ def put(local, remote):
|
|||||||
else:
|
else:
|
||||||
sys.stdout.write("Skip " + filename + "\n")
|
sys.stdout.write("Skip " + filename + "\n")
|
||||||
sys.stdout.flush()
|
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:
|
for filename in child_files:
|
||||||
@@ -404,6 +404,22 @@ def rename(oldname, newname):
|
|||||||
board_files.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()
|
@cli.command()
|
||||||
@click.argument("local_file")
|
@click.argument("local_file")
|
||||||
@click.option(
|
@click.option(
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ class Files(object):
|
|||||||
if exit_repl:
|
if exit_repl:
|
||||||
self._pyboard.exit_raw_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.
|
"""Create or update the specified file with the provided data.
|
||||||
"""
|
"""
|
||||||
# Open the file for writing on the board and write chunks of data.
|
# Open the file for writing on the board and write chunks of data.
|
||||||
@@ -458,6 +458,7 @@ class Files(object):
|
|||||||
import os
|
import os
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import uos as os
|
import uos as os
|
||||||
|
|
||||||
def rmdir(directory):
|
def rmdir(directory):
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
for f in os.listdir():
|
for f in os.listdir():
|
||||||
@@ -506,6 +507,70 @@ class Files(object):
|
|||||||
raise ex
|
raise ex
|
||||||
self._pyboard.exit_raw_repl()
|
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):
|
def run(self, filename, wait_output=True, stream_output=True):
|
||||||
"""Run the provided script and return its output. If wait_output is 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,
|
(default) then wait for the script to finish and then return its output,
|
||||||
|
|||||||
Reference in New Issue
Block a user