298
298
params['start_revid'] = navigation.start_revid
300
300
if navigation.prev_page_revid:
301
navigation.prev_page_url = navigation.branch.url([ navigation.scan_url, navigation.prev_page_revid ], **get_context(**params))
301
navigation.prev_page_url = navigation.branch.url([ navigation.scan_url, navigation.prev_page_revid ], **params)
302
302
if navigation.next_page_revid:
303
navigation.next_page_url = navigation.branch.url([ navigation.scan_url, navigation.next_page_revid ], **get_context(**params))
303
navigation.next_page_url = navigation.branch.url([ navigation.scan_url, navigation.next_page_revid ], **params)
306
306
def log_exception(log):
329
329
def _decorator(unbound):
330
330
def locked(self, *args, **kw):
331
#self.log.debug('-> %r lock %r', id(threading.currentThread()), debug_name)
331
332
getattr(self, lockname).acquire()
333
334
return unbound(self, *args, **kw)
335
336
getattr(self, lockname).release()
337
#self.log.debug('<- %r unlock %r', id(threading.currentThread()), debug_name)
337
339
return _decorator
341
def strip_whitespace(f):
345
out = re.sub(r'\n\s+', '\n', out)
346
out = re.sub(r'[ \t]+', ' ', out)
347
out = re.sub(r'\s+\n', '\n', out)
349
log.debug('Saved %sB (%d%%) by stripping whitespace.',
350
human_size(orig_len - new_len),
351
round(100.0 - float(new_len) * 100.0 / float(orig_len)))
356
# just thinking out loud here...
358
# so, when browsing around, there are 5 pieces of context, most optional:
360
# current location along the navigation path (while browsing)
361
# - starting revid (start_revid)
362
# the current beginning of navigation (navigation continues back to
363
# the original revision) -- this may not be along the primary revision
364
# path since the user may have navigated into a branch
366
# if navigating the revisions that touched a file
368
# if navigating the revisions that matched a search query
370
# a previous revision to remember for future comparisons
372
# current revid is given on the url path. the rest are optional components
375
# other transient things can be set:
377
# to compare one revision to another, on /revision only
379
# for re-ordering an existing page by different sort
381
t_context = threading.local()
382
_valid = ('start_revid', 'file_id', 'q', 'remember', 'compare_revid', 'sort')
385
def set_context(map):
386
t_context.map = dict((k, v) for (k, v) in map.iteritems() if k in _valid)
389
def get_context(**overrides):
391
return a context map that may be overriden by specific values passed in,
392
but only contains keys from the list of valid context keys.
394
if 'clear' is set, only the 'remember' context value will be added, and
395
all other context will be omitted.
398
if overrides.get('clear', False):
399
map['remember'] = t_context.map.get('remember', None)
401
map.update(t_context.map)
402
overrides = dict((k, v) for (k, v) in overrides.iteritems() if k in _valid)
403
map.update(overrides)