Yield directories starting from the given directory up to the root
176467
def _walk_to_root(path):
    
    if not os.path.exists(path):
        raise IOError('Starting path not found')

    if os.path.isfile(path):
        path = os.path.dirname(path)

    last_dir = None
    current_dir = os.path.abspath(path)
    while last_dir != current_dir:
        yield current_dir
        parent_dir = os.path.abspath(os.path.join(current_dir, os.path.pardir))
        last_dir, current_dir = current_dir, parent_dir
260555
def scandir_limited(top, limit, deep=0):
    
    deep += 1
    try:
        scandir_it = Path2(top).scandir()
    except PermissionError as err:
        log.error("scandir error: %s" % err)
        return

    for entry in scandir_it:
        if entry.is_dir(follow_symlinks=False):
            if deep < limit:
                yield from scandir_limited(entry.path, limit, deep)
            else:
                yield entry
306236
def tempdir(*args, **kwargs):
    

    d = tempfile.mkdtemp(*args, **kwargs)
    try:
        yield d
    finally:
        shutil.rmtree(d)
702469
def _os_walk(directory, recurse=True, **kwargs):
    
    if recurse:
        for root, dirs, files in os.walk(directory, **kwargs):
            yield root, dirs, files
    else:
        files = []
        for filename in os.listdir(directory):
            if os.path.isfile(os.path.join(directory, filename)):
                files.append(filename)
        yield directory, [], files
322715
def list_all_directories(self):
        
        def list_dirs_recursively(directory):
            if directory == self.filesystem:
                yield directory
            d_gen = itertools.chain(
                directory.directories,
                *tuple(list_dirs_recursively(d)
                       for d in directory.directories))
            for d in d_gen:
                yield d
        return list_dirs_recursively(self.filesystem)
613045
def cd(directory):
    
    old_dir = os.getcwd()
    try:
        os.chdir(directory)
        yield
    finally:
        os.chdir(old_dir)
1192839
function traverse (root, dirs, collect, next) {
  const rootPath = path.join (root, ...dirs);
  fs.lstat (rootPath, (err0) => {
    if (err0) {
      next (err0);
    } else {
      fs.readdir (rootPath, (_, files) => {
        let pending = files.length;
        for (let file of files) {
          const filePath = path.join (root, ...dirs, file);
          fs.lstat (filePath, (err1, stats) => {
            if (err1) {
              next (err1);
            } else {
              if (stats.isDirectory ()) {
                traverse (root, [...dirs, file], collect, err2 => {
                  if (err2) {
                    next (err2);
                  } else {
                    if (--pending === 0) {
                      next ();
                    }
                  }
                });
              } else {
                if (stats.isFile ()) {
                  collect (dirs, file, files);
                  if (--pending === 0) {
                    next ();
                  }
                }
              }
            }
          });
        }
      });
    }
  });
}
1089160
def path_yield(path):
    """"""
    for part in (x for x in path.strip(SEP).split(SEP) if x not in (None, '')):
        yield part
1069370
def work_in(dirname=None):
    
    curdir = os.getcwd()
    try:
        if dirname is not None:
            os.chdir(dirname)
        yield
    finally:
        os.chdir(curdir)
758838
def globlookup(pattern, root):
    
    for subdir, dirnames, filenames in os.walk(root):
        d = subdir[len(root) + 1:]
        files = (os.path.join(d, f) for f in filenames)
        for f in fnmatch.filter(files, pattern):
            yield f
400143
private function paths(): \Generator
    {
        foreach ($this->directories() as $root => $directory) {
            foreach ($directory as $file) {
                if (preg_match(self::PATTERN, $file->getFilename()) === 1) {
                    yield $root => $file->getPathname();
                }
            }
        }
    }
541872
def linuxPaths(self):
        
        for ((dirTree, dirID, dirSeq), (dirPath, name)) in self.links.items():
            for path in self.fileSystem.volumes[dirTree].linuxPaths:
                yield path + "/" + dirPath + name
        if self.fullPath in self.fileSystem.mounts:
            yield self.fileSystem.mounts[self.fullPath]
538254
function iterateRecurse (dir, options, cb) {
  try {
    var files = fs.readdirSync(dir)
    files.forEach(function (file, index) {
      var parsedPath = path.parse(file)
      var name = parsedPath.name
      var ext = parsedPath.ext
      var srcpath = path.join(dir, file)

      if (options.skip_ && name.charAt(0) === '_') {
        logger.debug('Skipping file/folder: ' + srcpath)
      } else {
        if (fs.lstatSync(srcpath).isDirectory()) {
          if (options.dirs) {
            cb(srcpath, name)
          }

          // Do recursive search when needed
          if (options.recursive) {
            iterateRecurse(srcpath, options, cb)
          }
        } else {
          for (var i = 0; i < options.ext.length; i++) {
            if (ext === options.ext[i]) {
              cb(srcpath, name, ext)
            }
          }
        }
      }
    })
  } catch (e) {
    logger.debug('Error iterating files: ' + e)
  }
}
49805
def chdir(new_dir):
    
    # On busy filesystems can have issues accessing main directory. Allow retries
    num_tries = 0
    max_tries = 5
    cur_dir = None
    while cur_dir is None:
        try:
            cur_dir = os.getcwd()
        except OSError:
            if num_tries > max_tries:
                raise
            num_tries += 1
            time.sleep(2)
    safe_makedir(new_dir)
    os.chdir(new_dir)
    try:
        yield
    finally:
        os.chdir(cur_dir)
75785
def get_filenodes_generator(self):
        
        for topnode, dirs, files in self.walk():
            for node in files:
                yield node
985270
def _tempDirectories(self):
        
        def _dirs(path, levels):
            if levels > 0:
                for subPath in os.listdir(path):
                    for i in _dirs(os.path.join(path, subPath), levels-1):
                        yield i
            else:
                yield path
        for tempDir in _dirs(self.tempFilesDir, self.levels):
            yield tempDir
107083
def initialize_directories(self, root_dir):
        """"""
        if not root_dir:
            root_dir = os.path.expanduser('~')

        # Create config directory, if it doesn't exist
        self.config_dir = os.path.join(root_dir, '.config/pueue')
        if not os.path.exists(self.config_dir):
            os.makedirs(self.config_dir)