forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.ts
More file actions
68 lines (60 loc) · 1.72 KB
/
Copy pathUtils.ts
File metadata and controls
68 lines (60 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
import {IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult} from "./Contracts";
import * as path from "path";
import * as fs from 'fs';
const PathValidity: Map<string, boolean> = new Map<string, boolean>();
export function validatePath(filePath: string): Promise<string> {
if (filePath.length === 0) {
return Promise.resolve('');
}
if (PathValidity.has(filePath)) {
return Promise.resolve(PathValidity.get(filePath) ? filePath : '');
}
return new Promise<string>(resolve => {
fs.exists(filePath, exists => {
PathValidity.set(filePath, exists);
return resolve(exists ? filePath : '');
});
});
}
export function validatePathSync(filePath: string): boolean {
if (filePath.length === 0) {
return false;
}
if (PathValidity.has(filePath)) {
return PathValidity.get(filePath);
}
const exists = fs.existsSync(filePath);
PathValidity.set(filePath, exists);
return exists;
}
export function CreatePythonThread(id: number, isWorker: boolean, process: IPythonProcess, name: string = ""): IPythonThread {
return {
IsWorkerThread: isWorker,
Process: process,
Name: name,
Id: id,
Frames: []
};
}
export function CreatePythonModule(id: number, fileName: string): IPythonModule {
let name = fileName;
if (typeof fileName === "string") {
try {
name = path.basename(fileName);
}
catch (ex) {
}
}
else {
name = "";
}
return {
ModuleId: id,
Name: name,
Filename: fileName
};
}
export function FixupEscapedUnicodeChars(value: string): string {
return value;
}