def Stat(self, path): directory = path.rsplit('/', 1)[0] result = self._stat_fetcher.Fetch(directory + '/') if result.status_code == 404: raise file_system.FileNotFoundError(path) stat_info = self._CreateStatInfo(result.content) if not path.endswith('/'): filename = path.rsplit('/', 1)[-1] if filename not in stat_info.child_versions: raise file_system.FileNotFoundError(path) stat_info.version = stat_info.child_versions[filename] return stat_info
def _ReadFile(self, filename, binary): try: with open(os.path.join(self._base_path, filename), 'r') as f: contents = f.read() if binary: return contents return file_system._ProcessFileData(contents, filename) except IOError: raise file_system.FileNotFoundError(filename)
def _ReadFile(self, filename, binary): try: mode = 'rb' if binary else 'r' with open(os.path.join(self._base_path, filename), mode) as f: contents = f.read() if binary: return contents return file_system._ToUnicode(contents) except IOError: raise file_system.FileNotFoundError(filename)
def Get(self): for path, future in self._fetches: result = future.Get() if result.status_code == 404: raise file_system.FileNotFoundError(path) elif path.endswith('/'): self._value[path] = self._ListDir(result.content) elif not self._binary: self._value[path] = file_system._ToUnicode(result.content) else: self._value[path] = result.content if self._error is not None: raise self._error return self._value
def _ListDir(self, dir_name): all_files = [] full_path = os.path.join(self._base_path, dir_name) try: files = os.listdir(full_path) except OSError: raise file_system.FileNotFoundError(dir_name) for path in files: if path.startswith('.'): continue if os.path.isdir(os.path.join(full_path, path)): all_files.append(path + '/') else: all_files.append(path) return all_files
def Stat(self, path): try: return self._CreateStatInfo(os.path.join(self._base_path, path)) except OSError: raise file_system.FileNotFoundError(path)