Klaus Demo ~jonashaag/klaus / ee3d293
Modernize codebase for Python 2/3 dual support Jonas Haag 6 years ago
6 changed file(s) with 18 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1515 }
1616
1717 def __init__(self, repo_paths, site_name, use_smarthttp):
18 self.repos = map(FancyRepo, repo_paths)
18 self.repos = list(map(FancyRepo, repo_paths))
1919 self.repo_map = dict((repo.name, repo) for repo in self.repos)
2020 self.site_name = site_name
2121 self.use_smarthttp = use_smarthttp
0 from __future__ import print_function
01 import os
12 import time
23 import threading
3334 def app(environ, start_response):
3435 if _.should_reload:
3536 # Refresh inner application with new repo list
36 print "Reloading repository list..."
37 print("Reloading repository list...")
3738 _.inner_app = make_app(
3839 [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
3940 *args, **kwargs
7272 lineiter = iter(self.lines)
7373 files = []
7474 try:
75 line = lineiter.next()
75 line = next(lineiter)
7676 while 1:
7777 # continue until we found the old file
7878 if not line.startswith('--- '):
7979 if in_header:
8080 header.append(line)
81 line = lineiter.next()
81 line = next(lineiter)
8282 continue
8383
8484 if header and all(x.strip() for x in header):
9292 files.append({
9393 'is_header': False,
9494 'old_filename': self._extract_filename(line),
95 'new_filename': self._extract_filename(lineiter.next()),
95 'new_filename': self._extract_filename(next(lineiter)),
9696 'additions': adds,
9797 'deletions': dels,
9898 'chunks': chunks
9999 })
100100
101 line = lineiter.next()
101 line = next(lineiter)
102102 while line:
103103 match = self._chunk_re.match(line)
104104 if not match:
114114 new_line -= 1
115115 old_end += old_line
116116 new_end += new_line
117 line = lineiter.next()
117 line = next(lineiter)
118118
119119 while old_line < old_end or new_line < new_end:
120120 if line:
147147 # StopIteration is raised
148148 files[-1]['additions'] = adds
149149 files[-1]['deletions'] = dels
150 line = lineiter.next()
150 line = next(lineiter)
151151
152152 except StopIteration:
153153 pass
160160 lineiter = iter(chunk)
161161 try:
162162 while True:
163 line = lineiter.next()
163 line = next(lineiter)
164164 if line['action'] != 'unmod':
165 nextline = lineiter.next()
165 nextline = next(lineiter)
166166 if nextline['action'] == 'unmod' or \
167167 nextline['action'] == line['action']:
168168 continue
00 import os
1 import cStringIO
1 from six.moves import cStringIO
22
33 import dulwich, dulwich.patch
44
1616 return self.path.replace(".git", "").rstrip(os.sep).split(os.sep)[-1]
1717
1818 def get_last_updated_at(self):
19 refs = [self[ref_hash] for ref_hash in self.get_refs().itervalues()]
19 refs = [self[ref_hash] for ref_hash in self.get_refs().values()]
2020 refs.sort(key=lambda obj:getattr(obj, 'commit_time', None),
2121 reverse=True)
2222 if refs:
7272 return obj.tag_time
7373 return obj.commit_time
7474
75 return sorted(refs.iterkeys(), key=get_commit_time, reverse=True)
75 return sorted(refs.keys(), key=get_commit_time, reverse=True)
7676
7777 def get_branch_names(self, exclude=None):
7878 """ Returns a sorted list of branch names. """
44 import datetime
55 import mimetypes
66 import locale
7 import six
78 try:
89 import chardet
910 except ImportError:
107108 def force_unicode(s):
108109 """ Does all kind of magic to turn `s` into unicode """
109110 # It's already unicode, don't do anything:
110 if isinstance(s, unicode):
111 if isinstance(s, six.text_type):
111112 return s
112113
113114 # Try some default encodings:
144144 history_length = 30
145145 skip = (self.context['page']-1) * 30 + 10
146146 if page > 7:
147 self.context['previous_pages'] = [0, 1, 2, None] + range(page)[-3:]
147 self.context['previous_pages'] = [0, 1, 2, None] + list(range(page))[-3:]
148148 else:
149 self.context['previous_pages'] = xrange(page)
149 self.context['previous_pages'] = range(page)
150150 else:
151151 history_length = 10
152152 skip = 0