git @ Cat's Eye Technologies klaus / 135b1da
PyLint/PEP8 Jonas Haag 13 years ago
3 changed file(s) with 14 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
22 * branch selector
33 * file history
44 * navigation: repo list, tree breadcrumbs
5 * raw file views (mimetype!)
65 * design
76
87 maybe
3636
3737 app = KlausApplication(debug=True, default_content_type='text/html')
3838
39 #pygments_formatter = HtmlFormatter(linenos=True, cssclass='code')
40
4139 def pygmentize(code, language=None, formatter=HtmlFormatter(linenos=True)):
4240 if language is None:
4341 lexer = guess_lexer(code)
4644 return highlight(code, lexer, formatter)
4745
4846 def timesince(when, now=time.time):
49 delta = time.time() - when
47 delta = now() - when
5048 result = []
5149 for unit, seconds in [
5250 ('year', 365*24*60*60),
104102
105103 def make_title(repo, branch, path):
106104 if path:
107 return '%s in %s/%s' % (path, repo.name, branch)
105 return '%s in %s/%s' % (path, repo.name, branch)
108106 else:
109107 return '%s/%s' % (repo.name, branch)
110108
113111
114112 @app.route('/')
115113 def repo_list(env):
116 return {'repos' : app.repos.items()}
114 return {'repos': app.repos.items()}
117115
118116 @app.route('/:repo:/')
119117 def view_repo(env, repo):
120118 redirect_to = app.build_url('view_tree', repo=repo, commit_id='master', path='')
121 return '302 Move On', {'Location' : redirect_to}, ''
119 return '302 Move On', {'Location': redirect_to}, ''
122120
123121 @app.route('/:repo:/tree/:commit_id:/(?P<path>.*)')
124122 def view_tree(env, repo, commit_id, path):
125123 repo, commit = get_repo_and_commit(repo, commit_id)
126124 files = ((name, get_tree_or_blob_url(repo, commit_id, entry))
127125 for name, entry in repo.listdir(commit, path))
128 return {'repo' : repo, 'files' : files, 'path' : path, 'commit_id' : commit_id,
129 'title' : make_title(repo, commit_id, path)}
126 return {'repo': repo, 'files': files, 'path': path, 'commit_id': commit_id,
127 'title': make_title(repo, commit_id, path)}
130128
131129 @app.route('/:repo:/history/:commit_id:/(?P<path>.*)')
132130 def history(env, repo, commit_id, path):
136134 except (KeyError, ValueError):
137135 page = 0
138136 this_url = app.build_url('history', repo=repo.name, commit_id=commit_id, path=path)
139 urls = {'next' : this_url + '?page=%d' % (page+1),
140 'prev' : this_url + '?page=%d' % (page-1)}
141 return {'repo' : repo, 'path' : path, 'page' : page, 'urls' : urls,
142 'title' : make_title(repo, commit_id, path)}
137 urls = {'next': this_url + '?page=%d' % (page+1),
138 'prev': this_url + '?page=%d' % (page-1)}
139 return {'repo': repo, 'path': path, 'page': page, 'urls': urls,
140 'title': make_title(repo, commit_id, path)}
143141
144142 @app.route('/:repo:/blob/:commit_id:/(?P<path>.*)')
145143 def view_blob(env, repo, commit_id, path):
149147 if '/raw/' in env['PATH_INFO']:
150148 raw_data = blob.data
151149 mime = 'application/octet-stream' if guess_is_binary(filename) else 'text/plain'
152 return '200 yo', {'Content-Type' : mime}, raw_data
150 return '200 yo', {'Content-Type': mime}, raw_data
153151 else:
154 return {'blob' : blob, 'title' : make_title(repo, commit_id, path),
155 'raw_url' : app.build_url('raw_file', repo=repo.name,
152 return {'blob': blob, 'title': make_title(repo, commit_id, path),
153 'raw_url': app.build_url('raw_file', repo=repo.name,
156154 commit_id=commit_id, path=path)}
157155
158156 @app.route('/:repo:/raw/:commit_id:/(?P<path>.*)')
162160 @app.route('/:repo:/commit/:id:/')
163161 def view_commit(env, repo, id):
164162 repo, commit = get_repo_and_commit(repo, id)
165 return {'commit' : commit, 'repo' : repo}
163 return {'commit': commit, 'repo': repo}
166164
167165
168166 if app.debug:
22 from cStringIO import StringIO
33 except ImportError:
44 from StringIO import StringIO
5 import difflib
65 import dulwich, dulwich.patch
76
87 def pairwise(iterable):