From 35177fd505518b88706dec81afc897b44c8bb839 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 29 Oct 2010 19:46:33 +1030 Subject: [PATCH] web: don't try to link to old bzr repository, use git. --- web/bzrbrowse/bzrbrowse.cgi | 238 ------------------------------------ web/bzrbrowse/file.png | Bin 361 -> 0 bytes web/bzrbrowse/folder.png | Bin 498 -> 0 bytes web/bzrbrowse/symlink.png | Bin 210 -> 0 bytes web/static-configuration | 4 +- 5 files changed, 2 insertions(+), 240 deletions(-) delete mode 100755 web/bzrbrowse/bzrbrowse.cgi delete mode 100644 web/bzrbrowse/file.png delete mode 100644 web/bzrbrowse/folder.png delete mode 100644 web/bzrbrowse/symlink.png diff --git a/web/bzrbrowse/bzrbrowse.cgi b/web/bzrbrowse/bzrbrowse.cgi deleted file mode 100755 index 2e3bf3c8..00000000 --- a/web/bzrbrowse/bzrbrowse.cgi +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2008 Lukas Lalinsky -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -# CHANGE THIS: -config = { - 'root': '/home/ccan/ccan', - 'base_url': '/browse', - 'images_url': '', - 'branch_url': 'http://ccan.ozlabs.org/repo', -} - -import os, sys, string -from bzrlib.branch import Branch -from bzrlib.errors import NotBranchError -from bzrlib import urlutils, osutils - -__version__ = '0.0.1-rusty' - - -class HTTPError(Exception): - - def __init__(self, code, message): - self.code = code - self.message = message - - -class NotFound(HTTPError): - - def __init__(self, message): - super(NotFound, self).__init__('404 Not Found', message) - - -def escape_html(text): - return text.replace('&', '&').replace('<', '<').replace('>', '>').replace("\n", '
') - - -class BzrBrowse(object): - - icons = { - 'file': 'file.png', - 'directory': 'folder.png', - 'symlink': 'symlink.png', - } - - page_tmpl = ''' -%(title)s - -

%(header)s

-
%(contents)s
- -''' - - def __init__(self, config): - self.config = config - self.base_url = None - - def list_to_html(self, entries): - content = [] - for entry in entries: - line = ' %(name)s
' % { - 'base_url': self.config['base_url'], - 'images_url': self.config['images_url'], - 'path': entry['path'], - 'name': entry['name'], - 'icon': self.icons.get(entry['kind'], self.icons['file']) - } - content.append(line) - return ''.join(content) - - def list_fs_directory(self, path): - entries = [] - if path: - entries.append({ - 'name': '..', - 'path': os.path.dirname(path), - 'kind': 'directory', - }) - if path: - prefix = path + '/' - else: - prefix = '' - try: - filelist = os.listdir(os.path.join(self.config['root'], path)) - except OSError: - raise NotFound('Path not found: ' + path) - for name in sorted(filelist): - if name.startswith('.'): - continue - abspath = os.path.join(path, name) - if os.path.isdir(os.path.join(self.config['root'], abspath)): - entries.append({ - 'name': name, - 'path': prefix + name, - 'kind': 'directory', - }) - return self.list_to_html(entries) - - def view_branch_file(self, tree, ie): - if ie.text_size > 1024 * 1024: - return 'File too big. (%d bytes)' % (ie.text_size) - tree.lock_read() - try: - text = tree.get_file_text(ie.file_id) - finally: - tree.unlock() - if '\0' in text: - return 'Binary file. (%d bytes)' % (ie.text_size) - try: - text = text.decode('utf-8') - except UnicodeDecodeError: - text = text.decode('latin-1') - linenumbers = [] - for i in range(1, text.count('\n') + 1): - linenumbers.append('%d' % (i, i, i)) - linenumbers = '\n'.join(linenumbers) - return ('
' +
-                linenumbers + '
' + escape_html(text) +
-                '
') - - # Symlinks in ccan contain .., and bzr refuses to serve that. Simplify. - def squish(self, linkname): - result = [] - for elem in string.split(linkname, os.sep): - if elem == '..': - result = result[:-1] - else: - result.append(elem) - return string.join(result, os.sep) - - def list_branch_directory(self, branch, path, relpath): - tree = branch.basis_tree() - file_id = tree.path2id(relpath) - ie = tree.inventory[file_id] - if ie.kind == 'file': - return self.view_branch_file(tree, ie) - if ie.kind == 'symlink': - return self.list_branch_directory(branch, path, self.squish(osutils.dirname(relpath) + os.sep + ie.symlink_target)) - entries = [] - if path: - entries.append({ - 'name': '..', - 'path': urlutils.dirname(path), - 'kind': 'directory', - }) - if path: - prefix = path + '/' - else: - prefix = '' - for name, child in sorted(ie.children.iteritems()): - entries.append({ - 'name': name, - 'path': prefix + name, - 'kind': child.kind, - }) - html = self.list_to_html(entries) - base = self.config['branch_url'] + '/' + osutils.relpath(self.config['root'], urlutils.local_path_from_url(branch.base)) - html = ('

This is a Bazaar branch. ' + - 'Use bzr branch ' + base + ' to download it.

' + html) - return html - - def request(self, path): - abspath = os.path.join(self.config['root'], path) - try: - branch, relpath = Branch.open_containing(abspath) - except NotBranchError: - return self.list_fs_directory(path) - return self.list_branch_directory(branch, path, relpath) - - def title(self, path): - return '/' + path - - def header(self, path): - title = [] - p = '' - title.append('root' % (self.config['base_url'], p)) - for name in path.split('/'): - p += '/' + name - title.append('%s' % (self.config['base_url'], p, name)) - return '/'.join(title) - - def __call__(self, environ, start_response): - try: - path = '/'.join(filter(bool, environ.get('PATH_INFO', '').split('/'))) - contents = self.page_tmpl % { - 'title': self.title(path), - 'header': self.header(path), - 'contents': self.request(path), - 'version': __version__ - } - contents = contents.encode('utf-8') - headers = [('Content-type','text/html; charset=UTF-8')] - start_response('200 OK', headers) - return [contents] - except HTTPError, e: - headers = [('Content-type','text/html; charset=UTF-8')] - start_response(e.code, headers) - return [e.message] - except: - import cgitb, sys - traceback_html = cgitb.html(sys.exc_info()) - headers = [('Content-type','text/html; charset=UTF-8')] - start_response('200 OK', headers) - return [traceback_html] - - -from wsgiref.handlers import CGIHandler -CGIHandler().run(BzrBrowse(config)) diff --git a/web/bzrbrowse/file.png b/web/bzrbrowse/file.png deleted file mode 100644 index df545eb91dfa2f7e8eba37c4178b1fcf0e723bb0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 361 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4^n7 BkMaNj diff --git a/web/bzrbrowse/folder.png b/web/bzrbrowse/folder.png deleted file mode 100644 index 901edc9624a23d92a9fcbc0c9c450bf37409da18..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 498 zcmVT` z=fK?B+ueUcgw&mTx8?fP8#5oZ_IS4UlwPlQrCO;yj|7yQi?lwqqD*+(cr$(Vs9LE# z0Eh#m(;1HB@{s`NLMd=l3Z)da7uEYf05Hbjc`mO%_Gxx9%%#H)XKp%DNa@dEf@UYf zg64HNtq;9mzz z0TxYQt&biCWrx3zi1`R0A}FO05k$Zj!CGNxeauK0j4VSdL!1G*==LU59h96xI zMByWh2N4hikuew;S(yNSb=sUhdyWrZ|BROccMMviB*Wb(P{I#8i on>e<%XnEP;xA*VLo2x9V1Hy;2%BQg6_y7O^07*qoM6N<$g5ayrIRF3v diff --git a/web/bzrbrowse/symlink.png b/web/bzrbrowse/symlink.png deleted file mode 100644 index da3fa7860134c0bd1718facaf1f9909db7ac5d19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=f!eQwFr$;k>u1h>((9qb}xG?=O?;;kKXBl{iH@TwNsP)nH-4DEYNG)U1B2cbX^)Lxk9Go0XYh3Ob6Mw<&;$S#T}fd8 diff --git a/web/static-configuration b/web/static-configuration index 1f392eba..23773693 100644 --- a/web/static-configuration +++ b/web/static-configuration @@ -17,8 +17,8 @@ $frommail = "ccan@ozlabs.org"; //tar home dir $tar_dir = 'tarballs'; -//where bzr repo is: attach module name to browse -$repo_base = 'http://ccan.ozlabs.org/browse/ccan/'; +//where repo is: attach module name to browse +$repo_base = 'http://git.ozlabs.org/?p=ccan;a=tree;f=ccan/'; function extract_field($field,$module) { -- 2.39.2