def fetch(self, url): path = ChromiumPath(_ExtractPathFromSvnUrl(url)) if self._IsDir(path): html = ['<table><tbody><tr>...</tr>'] # The version of the directory. dir_stat = self._Stat(path) html.append('<tr>') html.append('<td>Directory revision:</td>') html.append('<td><a>%s</a><a></a></td>' % dir_stat) html.append('</tr>') # The version of each file. for f in self._ListDir(path): if f.startswith('.'): continue html.append('<tr>') html.append( ' <td><a>%s%s</a></td>' % (f, '/' if self._IsDir(os.path.join(path, f)) else '')) html.append(' <td><a><strong>%s</strong></a></td>' % self._Stat(os.path.join(path, f))) html.append('<td></td><td></td><td></td>') html.append('</tr>') html.append('</tbody></table>') return '\n'.join(html) try: return ReadFile(path) except IOError: return None
def fetch(self, url): if _GITILES_URL_TO_COMMIT_PATTERN.match(url) is not None: return json.dumps({'commit': '1' * 40}) path = _ExtractPathFromGitilesUrl(url) chromium_path = ChromiumPath(path) if self._IsDir(chromium_path): jsn = {} dir_stat = self._Stat(chromium_path) jsn['id'] = dir_stat jsn['entries'] = [] for f in self._ListDir(chromium_path): if f.startswith('.'): continue f_path = os.path.join(chromium_path, f) jsn['entries'].append({ 'id': self._Stat(f_path), 'name': f, 'type': 'tree' if self._IsDir(f_path) else 'blob' }) return json.dumps(jsn) try: return base64.b64encode(ReadFile(path)) except IOError: return None
def fetch(self, url): path = _ExtractPathFromSvnUrl(url) if IsDirectory(path): html = ['<html>Revision 000000'] try: for f in self._ListDir(ChromiumPath(path)): if f.startswith('.'): continue if self._IsDir(ChromiumPath(path, f)): html.append('<a>' + f + '/</a>') else: html.append('<a>' + f + '</a>') html.append('</html>') return '\n'.join(html) except OSError as e: return None try: return ReadFile(path) except IOError: return None
def walk(path, prefix=''): path = ChromiumPath(path) public_files = {} for root, dirs, files in os.walk(path, topdown=True): relative_root = root[len(path):].lstrip(os.path.sep) dirs[:] = _FilterHidden(dirs) for filename in _FilterHidden(files): with open(os.path.join(root, filename), 'r') as f: request_path = posixpath.join(prefix, relative_root, filename) public_files[request_path] = f.read() return public_files
def _GetPublicFiles(): '''Gets all public files mapped to their contents. ''' public_path = ChromiumPath(PUBLIC_TEMPLATES) public_files = {} for path, dirs, files in os.walk(public_path, topdown=True): dirs[:] = [d for d in dirs if d != '.svn'] relative_posix_path = _ToPosixPath(path[len(public_path):]) for filename in files: with open(os.path.join(path, filename), 'r') as f: public_files['/'.join((relative_posix_path, filename))] = f.read() return public_files
def Create(*path): return LocalFileSystem(ChromiumPath(*path))