def __iter__(self):
        recursion_needed = '**' in self._path
        normal_file_iterator = glob.iglob(self._path,
                                          recursive=recursion_needed)
        if recursion_needed:
            hidden_file_iterator = glob.iglob(os.path.join(
                self._path, '**', '.*'),
                                              recursive=recursion_needed)
        else:
            hidden_file_iterator = []
        for path in itertools.chain(normal_file_iterator,
                                    hidden_file_iterator):
            # Follow symlinks unless pointing to directory or exclude flag is present.
            if os.path.islink(path) and (os.path.isdir(path)
                                         or self._ignore_symlinks):
                log.warning('Skipping symlink {}'.format(path))
                continue

            # For pattern like foo/bar/**, glob returns first path as 'foo/bar/'
            # even when foo/bar does not exist. So we skip non-existing paths.
            # Glob also returns intermediate directories if called with **. We skip
            # them to be consistent with CloudWildcardIterator.
            if self._path.endswith('**') and (not os.path.exists(path)
                                              or os.path.isdir(path)):
                continue

            file_url = storage_url.FileUrl(path)
            if os.path.isdir(path):
                yield resource_reference.FileDirectoryResource(file_url)
            else:
                yield resource_reference.FileObjectResource(file_url)
Exemple #2
0
    def __iter__(self):
        recursion_needed = '**' in self._path
        for path in glob.iglob(self._path, recursive=recursion_needed):
            # For pattern like foo/bar/**, glob returns first path as 'foo/bar/'
            # even when foo/bar does not exist. So we skip non-existing paths.
            # Glob also returns intermediate directories if called with **. We skip
            # them to be consistent with CloudWildcardIterator.
            if self._path.endswith('**') and (not os.path.exists(path)
                                              or os.path.isdir(path)):
                continue

            file_url = storage_url.FileUrl(path)
            if os.path.isdir(path):
                yield resource_reference.FileDirectoryResource(file_url)
            else:
                yield resource_reference.FileObjectResource(file_url)
def get_file_directory_resource(path):
  url = storage_url.storage_url_from_string(path)
  return resource_reference.FileDirectoryResource(url)
 def test_gets_file_directory_resource(self):
     url_string = 'hi' + os.path.sep
     parsed_url = storage_url.storage_url_from_string(url_string)
     resource = resource_reference.FileDirectoryResource(parsed_url)
     self.assertEqual(test_resources.from_url_string(url_string), resource)