contents.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { ContentsManager } from '@jupyterlab/services';
  4. import { log } from './log';
  5. export async function main() {
  6. const contents = new ContentsManager();
  7. log('Create a new directory');
  8. const model = await contents.newUntitled({ path: '/', type: 'directory' });
  9. log(`Created directory ${model.path}`);
  10. log('Move the new directory to /tmp');
  11. await contents.rename(model.path, '/tmp');
  12. log('Create new python file');
  13. const model2 = await contents.newUntitled({
  14. path: '/tmp',
  15. type: 'file',
  16. ext: 'py'
  17. });
  18. log(`Created ${model2.path}`);
  19. log('Rename file');
  20. await contents.rename(model2.path, '/tmp/foo.txt');
  21. log('Get contents of /tmp');
  22. await contents.get('/tmp');
  23. log('Save a file');
  24. await contents.save('/tmp/bar.txt');
  25. log('Copy a file');
  26. const model3 = await contents.copy('/tmp/bar.txt', '/tmp');
  27. log(`Copied to ${model3.path}`);
  28. log('Create a checkpoint');
  29. const checkpoint = await contents.createCheckpoint('/tmp/bar.txt');
  30. log('Restore a checkpoint');
  31. await contents.restoreCheckpoint('/tmp/bar.txt', checkpoint.id);
  32. log('List checkpoints for a file');
  33. const models2 = await contents.listCheckpoints('/tmp/bar.txt');
  34. log(models2[0].id);
  35. log('Delete a checkpoint');
  36. await contents.deleteCheckpoint('/tmp/bar.txt', checkpoint.id);
  37. log('Delete a file');
  38. await contents.delete('/tmp/bar.txt');
  39. }