Skip to content

Commit 1f540bb

Browse files
committed
fix reading and updating modules with subdirectories
1 parent 35f4fd6 commit 1f540bb

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

assets/lib/circup.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,43 @@ class Circup {
3535
console.log("Installing", module_name);
3636
var module = this.library_bundle.get_module(module_name);
3737
var module_files = await this.library_bundle.list_module_files(module);
38+
var module_base = `/lib/${module.name}/`
3839
if(module.package) {
39-
await this.workflow.create_dir(`/lib/${module.name}/`);
40+
await this.workflow.create_dir(module_base);
4041
}
4142
for(var file of module_files) {
42-
var upload_path = file.name.replace(/^[^\/]+\//, "/");
43+
const upload_path = file.name.replace(/^[^\/]+\//, "/");
44+
// list and create the intermediary sub-directories if needed
45+
const parts = upload_path.split("/").filter((x) => x.length)
46+
const subdirs = parts.slice(2,-1)
47+
var dir_path = module_base
48+
for(const sub of subdirs) {
49+
dir_path = `${dir_path}${sub}/`
50+
await this.workflow.create_dir(dir_path);
51+
}
4352
// var upload_path = file.name.replace(/^.+?\/lib\//, "/lib/");
4453
const file_content = await file.async("blob");
4554
await this.workflow.upload_file(upload_path, file_content);
4655
}
4756
}
4857
}
4958

59+
async sublist(cur_dir, module_files) {
60+
const response = await this.workflow.list_dir(cur_dir + "/");
61+
const these_files = response.content;
62+
for(var ffile of these_files) {
63+
const full_path = `${cur_dir}/${ffile.name}`
64+
if(ffile.directory) {
65+
await this.sublist(full_path, module_files)
66+
} else {
67+
if(ffile.name.endsWith(".py") || ffile.name.endsWith(".mpy")) {
68+
module_files.push(full_path)
69+
}
70+
}
71+
}
72+
module_files = module_files.map((item) => cur_dir + "/" + item.name);
73+
}
74+
5075
async get_module_version(module_name, board_libs=null) {
5176
if(board_libs === null) {
5277
board_libs = await this.library_bundle.get_lib_directory()
@@ -58,10 +83,8 @@ class Circup {
5883
var cpver = await this.workflow.cp_version();
5984

6085
if(pkg && board_libs.includes(module.name)) {
61-
// look at all files in the package
62-
var response = await this.workflow.list_dir(module_path + "/");
63-
module_files = response.content;
64-
module_files = module_files.map((item) => module_path + "/" + item.name);
86+
// look at all files in the package recursively
87+
await this.sublist(module_path, module_files)
6588
} else if(!pkg && board_libs.includes(module.name + ".py")) {
6689
module_files = [module_path+".py"];
6790
} else if(!pkg && board_libs.includes(module.name + ".mpy")) {
@@ -72,7 +95,8 @@ class Circup {
7295

7396
var version = false;
7497
for(var file_name of module_files) {
75-
var response = await this.workflow.get_file_content("/" + file_name);
98+
var file_path = ("/" + file_name).replace(/\/\/+/, "/")
99+
var response = await this.workflow.get_file_content(file_path);
76100
if(!response.ok) { continue }
77101
var file_data = response.content;
78102
// empty MPY files are bad

0 commit comments

Comments
 (0)