36 | 36 |
|
37 | 37 |
app = KlausApplication(debug=True, default_content_type='text/html')
|
38 | 38 |
|
39 | |
#pygments_formatter = HtmlFormatter(linenos=True, cssclass='code')
|
40 | |
|
41 | 39 |
def pygmentize(code, language=None, formatter=HtmlFormatter(linenos=True)):
|
42 | 40 |
if language is None:
|
43 | 41 |
lexer = guess_lexer(code)
|
|
46 | 44 |
return highlight(code, lexer, formatter)
|
47 | 45 |
|
48 | 46 |
def timesince(when, now=time.time):
|
49 | |
delta = time.time() - when
|
|
47 |
delta = now() - when
|
50 | 48 |
result = []
|
51 | 49 |
for unit, seconds in [
|
52 | 50 |
('year', 365*24*60*60),
|
|
104 | 102 |
|
105 | 103 |
def make_title(repo, branch, path):
|
106 | 104 |
if path:
|
107 | |
return '%s in %s/%s' % (path, repo.name, branch)
|
|
105 |
return '%s in %s/%s' % (path, repo.name, branch)
|
108 | 106 |
else:
|
109 | 107 |
return '%s/%s' % (repo.name, branch)
|
110 | 108 |
|
|
113 | 111 |
|
114 | 112 |
@app.route('/')
|
115 | 113 |
def repo_list(env):
|
116 | |
return {'repos' : app.repos.items()}
|
|
114 |
return {'repos': app.repos.items()}
|
117 | 115 |
|
118 | 116 |
@app.route('/:repo:/')
|
119 | 117 |
def view_repo(env, repo):
|
120 | 118 |
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}, ''
|
122 | 120 |
|
123 | 121 |
@app.route('/:repo:/tree/:commit_id:/(?P<path>.*)')
|
124 | 122 |
def view_tree(env, repo, commit_id, path):
|
125 | 123 |
repo, commit = get_repo_and_commit(repo, commit_id)
|
126 | 124 |
files = ((name, get_tree_or_blob_url(repo, commit_id, entry))
|
127 | 125 |
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)}
|
130 | 128 |
|
131 | 129 |
@app.route('/:repo:/history/:commit_id:/(?P<path>.*)')
|
132 | 130 |
def history(env, repo, commit_id, path):
|
|
136 | 134 |
except (KeyError, ValueError):
|
137 | 135 |
page = 0
|
138 | 136 |
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)}
|
143 | 141 |
|
144 | 142 |
@app.route('/:repo:/blob/:commit_id:/(?P<path>.*)')
|
145 | 143 |
def view_blob(env, repo, commit_id, path):
|
|
149 | 147 |
if '/raw/' in env['PATH_INFO']:
|
150 | 148 |
raw_data = blob.data
|
151 | 149 |
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
|
153 | 151 |
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,
|
156 | 154 |
commit_id=commit_id, path=path)}
|
157 | 155 |
|
158 | 156 |
@app.route('/:repo:/raw/:commit_id:/(?P<path>.*)')
|
|
162 | 160 |
@app.route('/:repo:/commit/:id:/')
|
163 | 161 |
def view_commit(env, repo, id):
|
164 | 162 |
repo, commit = get_repo_and_commit(repo, id)
|
165 | |
return {'commit' : commit, 'repo' : repo}
|
|
163 |
return {'commit': commit, 'repo': repo}
|
166 | 164 |
|
167 | 165 |
|
168 | 166 |
if app.debug:
|