Similar to workspace_from_dir, but this returns the root directory
    of a workspace rather than a workspace object.
505961
def root_from_dir(directory, recurse=True):
    

    directory = os.path.abspath(directory)
    pickle_path = os.path.join(directory, 'workspace.pkl')

    # Make sure the given directory contains a 'workspace' file.  This file is
    # needed to instantiate the right kind of workspace.

    if not os.path.exists(pickle_path):
        if recurse:
            parent_dir = os.path.dirname(directory)

            # Keep looking for a workspace as long as we haven't hit the root
            # of the file system.  If an exception is raised, that means no
            # workspace was found.  Catch and re-raise the exception so that
            # the name of the directory reported in the exception is meaningful
            # to the user.

            try:
                return root_from_dir(parent_dir, parent_dir != '/')
            except WorkspaceNotFound:
                raise WorkspaceNotFound(directory)
        else:
            raise WorkspaceNotFound(directory)

    # Return the directory in which the pkl file was found.

    return pickle_path[:-len('workspace.pkl')]
75505
@Override
  public Path getWorkingDirectory() {
    // Hadoop eco system depends on working directory value
    // Although it's not needed by Spark, it still in use when native Hadoop uses Stocator
    // Current approach is similar to the hadoop-openstack logic that generates working folder
    // We should re-consider another approach
    final String username = System.getProperty("user.name");
    return new Path("/user", username)
        .makeQualified(filesystemURI, new Path(username));
  }
1260486
def _GetDirectory(self):
    
    if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
      return None
    return TSKPartitionDirectory(self._file_system, self.path_spec)
41001
def root_dir(self):
        
        if self.cfg.script:
            return os.path.dirname(self.cfg.script)
1215922
def fetch_parent_dir(filepath, n=1):
    '''
    '''
    filepath = os.path.realpath(filepath)
    for i in range(n):
        filepath = os.path.dirname(filepath)
    return os.path.basename(filepath)
406292
def get_directory_relative_to_git_root(directory: str):
    
    return os.path.relpath(os.path.realpath(directory), get_git_root_directory(directory))
649126
def get_folder(self, si, path, root=None):
        

        search_index = si.content.searchIndex
        sub_folder = root if root else si.content.rootFolder

        if not path:
            return sub_folder

        paths = [p for p in path.split("/") if p]

        child = None
        try:
            new_root = search_index.FindChild(sub_folder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)
        except:
            child = None

        if child is None and hasattr(sub_folder, self.ChildEntity):
            new_root = search_index.FindChild(sub_folder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.VM):
            new_root = search_index.FindChild(sub_folder.vmFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Datastore):
            new_root = search_index.FindChild(sub_folder.datastoreFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Network):
            new_root = search_index.FindChild(sub_folder.networkFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Host):
            new_root = search_index.FindChild(sub_folder.hostFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Datacenter):
            new_root = search_index.FindChild(sub_folder.datacenterFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, 'resourcePool'):
            new_root = search_index.FindChild(sub_folder.resourcePool, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        return child
94436
def _get_path_for(root, tlobject):
    """"""
    out_dir = root / ('methods' if tlobject.is_function else 'constructors')
    if tlobject.namespace:
        out_dir /= tlobject.namespace

    return out_dir / _get_file_name(tlobject)
1081103
def _get_node_dir(node):
        """"""
        path = os.path.abspath(node)
        return path if os.path.isdir(path) else os.path.dirname(path)
1358575
def getRootDirectory(cls):
        
        if cls._is_running_on_worker:
            return cls._root_directory
        else:
            # This will have to change if we support multiple SparkContexts:
            return cls._sc._jvm.org.apache.spark.SparkFiles.getRootDirectory()
846026
private File getWorkDir() throws IOException
    {
        if (_workDir == null)
        {    
            File   dummy   = File.createTempFile("dummy", ".log");
            String workDir = dummy.getPath().substring(0, dummy.getPath().lastIndexOf(File.separatorChar));
    
            if ((workDir == null) || (workDir.length() == 0))
            {
                workDir = ".";
            }
            dummy.delete();
            _workDir = new File(workDir);
        }
        return _workDir;
    }
90996
def versions_from_parentdir(parentdir_prefix, root, verbose):
    
    dirname = os.path.basename(root)
    if not dirname.startswith(parentdir_prefix):
        if verbose:
            print("guessing rootdir is '%s', but '%s' doesn't start with "
                  "prefix '%s'" % (root, dirname, parentdir_prefix))
        raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
    return {"version": dirname[len(parentdir_prefix):],
            "full-revisionid": None,
            "dirty": False, "error": None}
1268118
public static WorkspacePath parsePathInWorkspace( String path ) {
        // Extract the workspace name and absPath from the supplied path ...
        java.util.regex.Matcher pathMatcher = WORKSPACE_AND_PATH_PATTERN.matcher(path);
        if (!pathMatcher.matches()) {
            // No match ...
            return null;
        }
        String workspaceName = pathMatcher.group(2);
        String absolutePath = pathMatcher.group(3);
        if (workspaceName == null || workspaceName.length() == 0 || workspaceName.trim().length() == 0) workspaceName = null;
        return new WorkspacePath(workspaceName, absolutePath);
    }
1322
def get_root_folder():
    
    locations = {
     'linux':{'hme':'/home/duncan/', 'core_folder':'/home/duncan/dev/src/python/AIKIF'},
     'win32':{'hme':'T:\\user\\',    'core_folder':'T:\\user\\dev\\src\\python\\AIKIF'},
     'cygwin':{'hme':os.getcwd() + os.sep,    'core_folder':os.getcwd()},
     'darwin':{'hme':os.getcwd() + os.sep,    'core_folder':os.getcwd()}
    }
    hme = locations[sys.platform]['hme']
    core_folder = locations[sys.platform]['core_folder']

    if not os.path.exists(core_folder):
        hme = os.getcwd()        
        core_folder = os.getcwd()
        print('config.py : running on CI build (or you need to modify the paths in config.py)')
    return hme, core_folder
203080
def load_from_path(self, filepath, container, **opts):
        
        root = ET.parse(filepath).getroot()
        nspaces = _namespaces_from_file(filepath)
        return root_to_container(root, container=container,
                                 nspaces=nspaces, **opts)
968608
private synchronized File getWorkingDirectory() {
    if (workingDirectory == null) {
      try {
        workingDirectory =
            Files.createTempDirectory(TEMP_DIRECTORY_PREFIX).toFile();
      } catch (IOException e) {
        throw new UnexpectedException(e);
      }
    }
    return workingDirectory;
  }
1331159
def absolute_git_root_dir(fpath=""):
    
    if len(fpath) == 0:
        dirname_str = os.getcwd()
    else:
        dirname_str = os.path.dirname(fpath)
    dirname_str = os.path.abspath(dirname_str)
    dirnames = dirname_str.split(os.sep)
    n = len(dirnames)
    for i in xrange(n):
        # is there a .git directory at this level?
        # FIXME hack
        basedir = "/" + os.path.join(*dirnames[0:n - i])
        gitdir = os.path.join(basedir, ".git")
        if os.path.exists(gitdir):
            return basedir