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.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.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;
@@ -262,7 +263,7 @@ class AmpyExt extends Ampy {
}
const { data, dataError } = await this.exec(code, timeout);
if (dataError) {
return '[]';
return [];
}
return JSON.parse(data.replaceAll('\'', '\"'));
}
@@ -297,7 +298,6 @@ class AmpyExt extends Ampy {
oldPath: oldname,
newPath: newname
});
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout);
return !dataError;
}
@@ -310,7 +310,6 @@ class AmpyExt extends Ampy {
path: filename
});
await this.exec(code);
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout);
return !dataError;
}
@@ -322,11 +321,22 @@ class AmpyExt extends Ampy {
const code = Mustache.render(AmpyExt.RMDIR, {
path: directory
});
const result = await this.exec(code, timeout);
const { dataError } = await this.exec(code, timeout);
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() {
return this.#device_;
}

View File

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