本文整理汇总了TypeScript中@jupyterlab/services.ContentsManager类的典型用法代码示例。如果您正苦于以下问题:TypeScript ContentsManager类的具体用法?TypeScript ContentsManager怎么用?TypeScript ContentsManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentsManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createConsole
execute: (args: ICreateConsoleArgs) => {
args = args || {};
let name = `Console ${++count}`;
// If we get a session, use it.
if (args.id) {
return manager.ready.then(() => {
return manager.connectTo(args.id);
}).then(session => {
name = session.path.split('/').pop();
name = `Console ${name.match(CONSOLE_REGEX)[1]}`;
createConsole(session, name);
return session.id;
});
}
// Find the correct path for the new session.
// Use the given path or the cwd.
let path = args.path || pathTracker.path;
if (ContentsManager.extname(path)) {
path = ContentsManager.dirname(path);
}
path = `${path}/console-${count}-${utils.uuid()}`;
// Get the kernel model.
return manager.ready.then(() => getKernel(args, name)).then(kernel => {
if (!kernel || (kernel && !kernel.id && !kernel.name)) {
return;
}
// Start the session.
let options: Session.IOptions = {
path,
kernelName: kernel.name,
kernelId: kernel.id
};
return manager.startNew(options).then(session => {
createConsole(session, name);
return session.id;
});
});
}
示例2: caption
function caption(options: ICaptionOptions): string {
let { label, path, displayName, connected, executed } = options;
let caption = (
`Name: ${label}\n` +
`Directory: ${ContentsManager.dirname(path)}\n` +
`Kernel: ${displayName}\n` +
`Connected: ${dateTime(connected.toISOString())}`
);
if (executed) {
caption += `\nLast Execution: ${dateTime(executed.toISOString())}`;
}
return caption;
}
示例3: createConsole
execute: (args: ICreateConsoleArgs) => {
args = args || {};
let name = `Console ${++count}`;
// If we get a session, use it.
if (args.sessionId) {
return manager.connectTo(args.sessionId).then(session => {
createConsole(session, name);
return session.id;
});
}
// Find the correct path for the new session.
// Use the given path or the cwd.
let path = args.path || pathTracker.path;
if (ContentsManager.extname(path)) {
path = ContentsManager.dirname(path);
}
path = `${path}/console-${utils.uuid()}`;
// Get the kernel model.
return getKernel(args, name).then(kernel => {
if (!kernel) {
return;
}
// Start the session.
let options: Session.IOptions = {
path,
kernelName: kernel.name,
kernelId: kernel.id
};
return manager.startNew(options).then(session => {
createConsole(session, name);
return session.id;
});
});
}
示例4: it
it('should create a directory', async () => {
handleRequest(contents, 201, DEFAULT_DIR);
const options: Contents.ICreateOptions = {
path: '/foo',
type: 'directory'
};
const model = await contents.newUntitled(options);
expect(model.content[0].path).to.equal(DEFAULT_DIR.content[0].path);
});
示例5: expectFailure
it('should fail for an incorrect model', async () => {
const dir = JSON.parse(JSON.stringify(DEFAULT_DIR));
dir.name = 1;
handleRequest(contents, 201, dir);
const options: Contents.ICreateOptions = {
path: '/foo',
type: 'file',
ext: 'py'
};
const newFile = contents.newUntitled(options);
await expectFailure(newFile);
});