Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EdgeTpu] Implements Explorer #1737

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ class NodeFactory {
undefined,
"Config nodes cannot have attributes"
);
node = new ConfigNode(uri, parent);
const ext = path.extname(fpath);
switch (ext) {
case ".edgetpucfg": {
node = new ConfigNode(uri, parent, "one.editor.edgetpucfg");
break;
}
case ".cfg":
default: {
node = new ConfigNode(uri, parent);
}
}
break;
}
case NodeType.product: {
Expand Down Expand Up @@ -252,6 +262,26 @@ class DirectoryNode extends Node {
super(uri, parent);
}

private isOneBaseModel(fname: string): boolean {
return (
fname.endsWith(".pb") ||
fname.endsWith(".tflite") ||
fname.endsWith(".onnx")
);
}

private isEdgetpuBaseModel(fname: string): boolean {
return fname.endsWith(".tflite")
? !fname.endsWith("_edgetpu.tflite")
: true;
}

/*
Check if the file is a basemodel.
*/
private isBaseModel(fname: string): boolean {
return this.isOneBaseModel(fname) && this.isEdgetpuBaseModel(fname);
}
/**
* Build a sub-tree under the node
*
Expand All @@ -271,11 +301,10 @@ class DirectoryNode extends Node {

if (fstat.isDirectory()) {
const dirNode = NodeFactory.create(NodeType.directory, fpath, this);

if (dirNode && dirNode.getChildren().length > 0) {
this._childNodes!.push(dirNode);
}
} else if (fstat.isFile()) {
} else if (fstat.isFile() && this.isBaseModel(fname)) {
if (fname.endsWith(".pb")) {
const baseModelNode = NodeFactory.create(
NodeType.baseModel,
Expand Down Expand Up @@ -359,15 +388,14 @@ class BaseModelNode extends Node {
*/
_buildChildren = (): void => {
this._childNodes = [];

const configPaths = OneStorage.getCfgs(this.path);

if (!configPaths) {
return;
}

configPaths.forEach((configPath) => {
const configNode = NodeFactory.create(NodeType.config, configPath, this);

if (configNode) {
this._childNodes!.push(configNode);
}
Expand All @@ -378,7 +406,7 @@ class BaseModelNode extends Node {
class ConfigNode extends Node {
readonly type = NodeType.config;

static readonly extList = [".cfg"];
static readonly extList = [".cfg", ".edgetpucfg"];
// Open file with one.editor.cfg as default
static defaultOpenViewType = "one.editor.cfg";
// Display gear icon as default
Expand Down Expand Up @@ -451,6 +479,8 @@ class ProductNode extends Node {
".tv2o",
".json",
".circle.log",
"_edgetpu.tflite",
"_edgetpu.log",
];
// Do not open file as default
static defaultOpenViewType = undefined;
Expand Down
6 changes: 5 additions & 1 deletion src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ export class OneStorage {
};

try {
const extList = [".cfg", ".edgetpucfg"];

return roots
.map((root) =>
readdirSyncRecursive(root).filter((val) => val.endsWith(".cfg"))
readdirSyncRecursive(root).filter((val) =>
extList.some((ext) => val.endsWith(ext))
)
)
.reduce((prev, cur) => [...prev, ...cur]);
} catch {
Expand Down
23 changes: 23 additions & 0 deletions src/Tests/OneExplorer/OneExplorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ suite("OneExplorer", function () {
}
});

test("create a config node with edgetpucfg", function () {
const configName = "test.edgetpucfg";

// Write a file inside temp directory
testBuilder.writeFileSync(configName, "");

// Get file paths inside the temp directory
const configPath = testBuilder.getPath(configName);

// Validation
{
const configNode = NodeFactory.create(
NodeType.config,
configPath,
undefined
);
assert.strictEqual(configNode.openViewType, "one.editor.edgetpucfg");
assert.strictEqual(configNode.icon, ConfigNode.defaultIcon);
assert.strictEqual(configNode.canHide, ConfigNode.defaultCanHide);
assert.strictEqual(configNode.getChildren().length, 0);
}
});

test("NEG: create a product node with not existing path", function () {
assert.throw(() => {
NodeFactory.create(NodeType.product, "path/not/exist", undefined);
Expand Down
Loading