feat(core): 在线版ampy上传文件时首先获取工作路径

This commit is contained in:
王立帮
2025-04-17 15:57:12 +08:00
parent f578e1a242
commit d90453ecd9
4 changed files with 24 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ class AmpyExt extends Ampy {
this.RM = goog.get(path.join(Env.templatePath, 'python/rm.py')); this.RM = goog.get(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.py')); this.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.get(path.join(Env.templatePath, 'python/get.py')); this.GET = goog.get(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.get(path.join(Env.templatePath, 'python/cwd.py'));
} }
#device_ = null; #device_ = null;
@@ -262,7 +263,7 @@ class AmpyExt extends Ampy {
} }
const { data, dataError } = await this.exec(code, timeout); const { data, dataError } = await this.exec(code, timeout);
if (dataError) { if (dataError) {
return '[]'; return [];
} }
return JSON.parse(data.replaceAll('\'', '\"')); return JSON.parse(data.replaceAll('\'', '\"'));
} }
@@ -297,7 +298,6 @@ class AmpyExt extends Ampy {
oldPath: oldname, oldPath: oldname,
newPath: newname newPath: newname
}); });
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout); const { dataError } = await this.exec(code, timeout);
return !dataError; return !dataError;
} }
@@ -310,7 +310,6 @@ class AmpyExt extends Ampy {
path: filename path: filename
}); });
await this.exec(code); await this.exec(code);
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout); const { dataError } = await this.exec(code, timeout);
return !dataError; return !dataError;
} }
@@ -322,11 +321,22 @@ class AmpyExt extends Ampy {
const code = Mustache.render(AmpyExt.RMDIR, { const code = Mustache.render(AmpyExt.RMDIR, {
path: directory path: directory
}); });
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout); const { dataError } = await this.exec(code, timeout);
return !dataError; return !dataError;
} }
async cwd(timeout = 5000) {
if (!this.isActive()) {
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
}
const code = Mustache.render(AmpyExt.CWD, {});
const { data, dataError } = await this.exec(code, timeout);
if (dataError) {
return '/';
}
return data;
}
getDevice() { getDevice() {
return this.#device_; return this.#device_;
} }

View File

@@ -701,14 +701,15 @@ BU.uploadWithAmpy = (portName) => {
statusBarTerminal.addValue('Writing main.py '); statusBarTerminal.addValue('Writing main.py ');
await ampy.put('main.py', code); await ampy.put('main.py', code);
statusBarTerminal.addValue('Done!\n'); statusBarTerminal.addValue('Done!\n');
/*const rootInfo = await ampy.ls('/'); /*const cwd = await ampy.cwd();
const rootInfo = await ampy.ls(cwd);
let rootMap = {}; let rootMap = {};
for (let item of rootInfo) { for (let item of rootInfo) {
rootMap[item[0]] = item[1]; rootMap[item[0]] = item[1];
} }
if (libraries && libraries instanceof Object) { if (libraries && libraries instanceof Object) {
for (let key in libraries) { for (let key in libraries) {
if (rootMap[`/${key}`] !== undefined && rootMap[`/${key}`] === libraries[key].size) { if (rootMap[`${cwd}/${key}`] !== undefined && rootMap[`${cwd}/${key}`] === libraries[key].size) {
statusBarTerminal.addValue(`Skip ${key}\n`); statusBarTerminal.addValue(`Skip ${key}\n`);
continue; continue;
} }

View File

@@ -0,0 +1,6 @@
try:
import os
except ImportError:
import uos as os
print(os.getcwd(), end='')

View File

@@ -20,7 +20,7 @@ def check_path(path):
return 'file' return 'file'
else: else:
return 'special file' return 'special file'
except OSError: except Exception:
return 'none' return 'none'
def listdir(directory): def listdir(directory):