osCommands.ts 2.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

'use strict';

import { RemoteCommandResult } from "./remoteMachineData";

abstract class OsCommands {

    protected pathSpliter: string = '/';
11
12
    protected multiplePathSpliter: RegExp = new RegExp(`[\\\\/]{2,}`);
    protected normalizePath: RegExp = new RegExp(`[\\\\/]`);
13

14
15
16
17
18
19
20
    public abstract getScriptExt(): string;
    public abstract generateStartScript(workingDirectory: string, trialJobId: string, experimentId: string,
        trialSequenceId: string, isMultiPhase: boolean, jobIdFileName: string,
        command: string, nniManagerAddress: string, nniManagerPort: number,
        nniManagerVersion: string, logCollection: string, exitCodeFile: string,
        codeDir: string, cudaVisibleSetting: string): string;
    public abstract generateGpuStatsScript(scriptFolder: string): string;
21
22
23
24
25
26
27
    public abstract createFolder(folderName: string, sharedFolder: boolean): string;
    public abstract allowPermission(isRecursive: boolean, ...folders: string[]): string;
    public abstract removeFolder(folderName: string, isRecursive: boolean, isForce: boolean): string;
    public abstract removeFiles(folderOrFileName: string, filePattern: string): string;
    public abstract readLastLines(fileName: string, lineCount: number): string;
    public abstract isProcessAliveCommand(pidFileName: string): string;
    public abstract isProcessAliveProcessOutput(result: RemoteCommandResult): boolean;
28
    public abstract killChildProcesses(pidFileName: string, killSelf: boolean): string;
29
30
    public abstract extractFile(tarFileName: string, targetFolder: string): string;
    public abstract executeScript(script: string, isFile: boolean): string;
31
    public abstract addPreCommand(preCommand: string | undefined, command: string | undefined): string | undefined;
32
33
34
35
36
37

    public joinPath(...paths: string[]): string {
        let dir: string = paths.filter((path: any) => path !== '').join(this.pathSpliter);
        if (dir === '') {
            dir = '.';
        } else {
38
39
40
            // normalize
            dir = dir.replace(this.normalizePath, this.pathSpliter);
            // reduce duplicate ones
41
42
43
44
45
46
47
            dir = dir.replace(this.multiplePathSpliter, this.pathSpliter);
        }
        return dir;
    }
}

export { OsCommands };