How to use the @jupyterlab/coreutils.PathExt.dirname function in @jupyterlab/coreutils

To help you get started, we’ve selected a few @jupyterlab/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter / nbdime / packages / labextension / src / plugin.ts View on Github external
function hasGitNotebook(): boolean {
    if (!baseEnabled()) {
      return false;
    }

    let path = tracker.currentWidget!.context.path;
    let dir = PathExt.dirname(path);
    let known_git = lut_known_git[dir];
    if (known_git === undefined) {
      const inGitPromise = isNbInGit({path: dir});
      inGitPromise.then(inGit => {
        networkRetry = INITIAL_NETWORK_RETRY;
        lut_known_git[dir] = inGit;
        // Only update if false, since it is left enabled while waiting
        if (!inGit) {
          commands.notifyCommandChanged(CommandIDs.diffNotebookGit);
        }
      });
      inGitPromise.catch((reason) => {
        hasAPI = reason.status !== undefined && reason.status !== 404;
        setTimeout(() => {
          networkRetry *= 2;
          commands.notifyCommandChanged(CommandIDs.diffNotebook);
github jupyterlab / jupyterlab / tests / test-coreutils / src / path.spec.ts View on Github external
it('should not return "." for an empty path', () => {
        const path = PathExt.dirname('');
        expect(path).to.equal('');
      });
github jupyterlab / jupyterlab / tests / test-coreutils / src / path.spec.ts View on Github external
it('should not return "." for a path in the root directory', () => {
        const path = PathExt.dirname('foo.txt');
        expect(path).to.equal('');
      });
    });
github jupyterlab / jupyterlab-google-drive / src / drive.ts View on Github external
resourceCache.forEach((value, key) => {
      let enclosingFolderPath = PathExt.dirname(key);
      if (path === enclosingFolderPath) {
        resourceCache.delete(key);
      }
    });
  }
github jupyterlab / jupyterlab-data-explorer / packages / filebrowser-extension / src / index.ts View on Github external
        return restored.then(() => model.cd(`/${PathExt.dirname(localPath)}`));
      });
github jupyterlab / jupyterlab-google-drive / src / drive.ts View on Github external
async (resolve, reject) => {
        let enclosingFolderPath = PathExt.dirname(path);
        const resource: FileResource = fileResourceFromContentsModel(
          model,
          fileType
        );
        const parentFolderResource = await getResourceForPath(
          enclosingFolderPath
        );
        if (!isDirectory(parentFolderResource)) {
          throw new Error('Google Drive: expected a folder: ' + path);
        }
        if (parentFolderResource.kind === 'drive#teamDrive') {
          resource.teamDriveId = parentFolderResource.id;
        } else if (parentFolderResource.teamDriveId) {
          resource.teamDriveId = parentFolderResource.teamDriveId;
        }
        resource.parents = [parentFolderResource.id!];
github jupyterlab / jupyterlab / packages / rendermime / src / registry.ts View on Github external
resolveUrl(url: string): Promise {
      if (this.isLocal(url)) {
        const cwd = encodeURI(PathExt.dirname(this._session.path));
        url = PathExt.resolve(cwd, url);
      }
      return Promise.resolve(url);
    }
github jupyterlab / jupyterlab-google-drive / src / drive.ts View on Github external
export async function uploadFile(
  path: string,
  model: Partial,
  fileType: DocumentRegistry.IFileType,
  existing: boolean = false,
  fileTypeForPath:
    | ((path: string) => DocumentRegistry.IFileType)
    | undefined = undefined
): Promise {
  if (isDummy(PathExt.dirname(path)) && !existing) {
    throw makeError(
      400,
      `Google Drive: "${path}"` + ' is not a valid save directory'
    );
  }
  let resourceReadyPromise: Promise;
  if (existing) {
    resourceReadyPromise = getResourceForPath(path);
  } else {
    resourceReadyPromise = new Promise(
      async (resolve, reject) => {
        let enclosingFolderPath = PathExt.dirname(path);
        const resource: FileResource = fileResourceFromContentsModel(
          model,
          fileType
        );
github altair-viz / jupyterlab_voyager / src / voyagerpanel.ts View on Github external
onClick: () => {
      var datavoyager = (widget as VoyagerPanel).voyager_cur;
      var dataSrc = (widget as VoyagerPanel).data_src;
      let spec = datavoyager.getSpec(false);
      let context = widget.context as Context;
      let path = PathExt.dirname(context.path);
      var content: any;
      if (spec !== undefined) {
        content = {
          data: dataSrc,
          mark: spec.mark,
          encoding: spec.encoding,
          height: spec.height,
          width: spec.width,
          description: spec.description,
          name: spec.name,
          selection: spec.selection,
          title: spec.title,
          transform: spec.transform
        };
      } else {
        content = {
github jupyterlab / jupyterlab / packages / docmanager / src / dialogs.ts View on Github external
}).then(result => {
    if (!result.value) {
      return null;
    }
    if (!isValidFileName(result.value)) {
      void showErrorMessage(
        'Rename Error',
        Error(
          `"${result.value}" is not a valid name for a file. ` +
            `Names must have nonzero length, ` +
            `and cannot include "/", "\\", or ":"`
        )
      );
      return null;
    }
    let basePath = PathExt.dirname(oldPath);
    let newPath = PathExt.join(basePath, result.value);
    return renameFile(manager, oldPath, newPath);
  });
}