Notebook Code Cleanup + Utils Test (#11754)

* Cleanup + Utils Test

* Removing unnecessary util method
This commit is contained in:
Chris LaFreniere
2020-08-14 14:08:56 -07:00
committed by GitHub
parent ff2d2d0339
commit a34a72795b
8 changed files with 9 additions and 44 deletions

View File

@@ -9,7 +9,6 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as zip from 'adm-zip';
import * as tar from 'tar';
import * as utils from '../common/utils';
import { RemoteBook } from './remoteBook';
import { IAsset } from './remoteBookController';
import * as constants from '../common/constants';
@@ -76,7 +75,7 @@ export class GitHubRemoteBook extends RemoteBook {
}
public async extractFiles(remoteBookFullPath: vscode.Uri): Promise<void> {
try {
if (utils.getOSPlatform() === utils.Platform.Windows || utils.getOSPlatform() === utils.Platform.Mac) {
if (process.platform === constants.winPlatform || process.platform === constants.macPlatform) {
let zippedFile = new zip(remoteBookFullPath.fsPath);
zippedFile.extractAllTo(this._localPath.fsPath);
} else {

View File

@@ -5,11 +5,11 @@
import * as request from 'request';
import * as loc from '../common/localizedConstants';
import * as utils from '../common/utils';
import * as vscode from 'vscode';
import { RemoteBookDialogModel } from '../dialog/remoteBookDialogModel';
import { GitHubRemoteBook } from '../book/githubRemoteBook';
import { SharedRemoteBook } from '../book/sharedRemoteBook';
import { winPlatform, macPlatform } from '../common/constants';
const assetNameRE = /([a-zA-Z0-9]+)(?:-|_)([a-zA-Z0-9.]+)(?:-|_)([a-zA-Z0-9]+).(zip|tar.gz|tgz)/;
@@ -73,7 +73,7 @@ export class RemoteBookController {
public async getAssets(release?: IRelease): Promise<IAsset[]> {
if (release) {
let format: string[] = [];
if (utils.getOSPlatform() === utils.Platform.Windows || utils.getOSPlatform() === utils.Platform.Mac) {
if (process.platform === winPlatform || process.platform === macPlatform) {
format = ['zip'];
} else {
format = ['tar.gz', 'tgz'];

View File

@@ -22,6 +22,7 @@ export const remoteBookDownloadTimeout = 'remoteBookDownloadTimeout';
export const collapseBookItems = 'collapseBookItems';
export const winPlatform = 'win32';
export const macPlatform = 'darwin';
export const jupyterNotebookProviderId = 'jupyter';
export const jupyterConfigRootFolder = 'jupyter_config';

View File

@@ -121,19 +121,6 @@ export interface IEndpoint {
protocol: string;
}
export function getOSPlatform(): Platform {
switch (process.platform) {
case 'win32':
return Platform.Windows;
case 'darwin':
return Platform.Mac;
case 'linux':
return Platform.Linux;
default:
return Platform.Others;
}
}
export function getOSPlatformId(): string {
let platformId = undefined;
switch (process.platform) {

View File

@@ -160,10 +160,3 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
}
};
}
// this method is called when your extension is deactivated
export function deactivate() {
if (controller) {
controller.deactivate();
}
}

View File

@@ -13,7 +13,6 @@ const localize = nls.loadMessageBundle();
import * as constants from '../common/constants';
import * as localizedConstants from '../common/localizedConstants';
import { JupyterServerInstallation } from './jupyterServerInstallation';
import { IServerInstance } from './common';
import * as utils from '../common/utils';
import { IPrompter, IQuestion, confirm } from '../prompts/question';
@@ -33,9 +32,8 @@ import { IconPathHelper } from '../common/iconHelper';
let untitledCounter = 0;
export class JupyterController implements vscode.Disposable {
export class JupyterController {
private _jupyterInstallation: JupyterServerInstallation;
private _notebookInstances: IServerInstance[] = [];
private _serverInstanceFactory: ServerInstanceFactory = new ServerInstanceFactory();
private _packageManageProviders = new Map<string, IPackageManageProvider>();
@@ -54,10 +52,6 @@ export class JupyterController implements vscode.Disposable {
return this._notebookProvider;
}
public dispose(): void {
this.deactivate();
}
// PUBLIC METHODS //////////////////////////////////////////////////////
public async activate(): Promise<boolean> {
this._jupyterInstallation = new JupyterServerInstallation(
@@ -112,11 +106,6 @@ export class JupyterController implements vscode.Disposable {
return this.handleNewNotebookTask(oeContext, oeContext.connectionProfile);
}
public deactivate(): void {
// Shutdown any open notebooks
this._notebookInstances.forEach(async (instance) => { await instance.stop(); });
}
// EVENT HANDLERS //////////////////////////////////////////////////////
public async getDefaultConnection(): Promise<azdata.connection.ConnectionProfile> {
return await azdata.connection.getCurrentConnection();

View File

@@ -207,11 +207,11 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
let extension = process.platform === constants.winPlatform ? 'zip' : 'tar.gz';
packageName = `python-${pythonVersion}-${platformId}-${bundleVersion}.${extension}`;
switch (utils.getOSPlatform()) {
case utils.Platform.Windows:
switch (process.platform) {
case constants.winPlatform:
pythonDownloadUrl = constants.pythonWindowsInstallUrl;
break;
case utils.Platform.Mac:
case constants.macPlatform:
pythonDownloadUrl = constants.pythonMacInstallUrl;
break;
default:
@@ -274,7 +274,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
return reject(err);
}
}
if (utils.getOSPlatform() === utils.Platform.Windows) {
if (process.platform === constants.winPlatform) {
try {
let zippedFile = new zip(pythonPackagePathLocal);
zippedFile.extractAllTo(installPath);

View File

@@ -45,10 +45,6 @@ describe('Utils Tests', function () {
should(utils.getErrorMessage(errMsg)).equal(errMsg);
});
it('getOSPlatform', async () => {
should(utils.getOSPlatform()).not.throw();
});
it('getOSPlatformId', async () => {
should(utils.getOSPlatformId()).not.throw();
});