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)
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 test_not_equal_with_different_type(self): url1 = storage_url.CloudUrl.from_url_string('gs://bucket/obj.txt#1234') url2 = storage_url.FileUrl('gs://bucket/obj.txt#1234') self.assertNotEqual(url1, url2)
def test_versionless_url_string(self): file_url = storage_url.FileUrl(os.path.join('dir', 'a.txt')) self.assertEqual(file_url.versionless_url_string, 'file://' + os.path.join('dir', 'a.txt'))