134
128
Convert a dict into an object with attributes.
137
130
def __init__(self, _dict=None, **kw):
138
131
if _dict is not None:
139
132
for key, value in _dict.iteritems():
144
137
def __repr__(self):
146
139
for key, value in self.__dict__.iteritems():
147
if key.startswith('_') or (getattr(self.__dict__[key],
148
'__call__', None) is not None):
140
if key.startswith('_') or (getattr(self.__dict__[key], '__call__', None) is not None):
150
142
out += '%r => %r, ' % (key, value)
241
227
s = s.decode('utf-8')
242
228
except UnicodeDecodeError:
243
229
s = s.decode('iso-8859-15')
245
s = s.expandtabs().replace(' ', NONBREAKING_SPACE)
247
return HSC.clean(s).replace('\n', '<br/>')
230
return s.expandtabs().replace(' ', NONBREAKING_SPACE)
250
233
def fake_permissions(kind, executable):
329
311
navigation.position = 0
330
312
navigation.count = len(navigation.revid_list)
331
313
navigation.page_position = navigation.position // navigation.pagesize + 1
332
navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize\
333
- 1)) // navigation.pagesize
314
navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize - 1)) // navigation.pagesize
335
316
def get_offset(offset):
336
if (navigation.position + offset < 0) or (
337
navigation.position + offset > navigation.count - 1):
317
if (navigation.position + offset < 0) or (navigation.position + offset > navigation.count - 1):
339
319
return navigation.revid_list[navigation.position + offset]
347
327
navigation.next_page_revid)
348
328
start_revno = navigation.history.get_revno(navigation.start_revid)
350
params = {'filter_file_id': navigation.filter_file_id}
330
params = { 'filter_file_id': navigation.filter_file_id }
351
331
if getattr(navigation, 'query', None) is not None:
352
332
params['q'] = navigation.query
362
342
[navigation.scan_url, next_page_revno], **params)
365
def directory_breadcrumbs(path, is_root, view):
367
Generate breadcrumb information from the directory path given
369
The path given should be a path up to any branch that is currently being
373
path -- The path to convert into breadcrumbs
374
is_root -- Whether or not loggerhead is serving a branch at its root
375
view -- The type of view we are showing (files, changes etc)
377
# Is our root directory itself a branch?
379
if view == 'directory':
387
# Create breadcrumb trail for the path leading up to the branch
389
'dir_name': "(root)",
394
dir_parts = path.strip('/').split('/')
395
for index, dir_name in enumerate(dir_parts):
397
'dir_name': dir_name,
398
'path': '/'.join(dir_parts[:index + 1]),
401
# If we are not in the directory view, the last crumb is a branch,
402
# so we need to specify a view
403
if view != 'directory':
404
breadcrumbs[-1]['suffix'] = '/' + view
408
def branch_breadcrumbs(path, inv, view):
410
Generate breadcrumb information from the branch path given
412
The path given should be a path that exists within a branch
415
path -- The path to convert into breadcrumbs
416
inv -- Inventory to get file information from
417
view -- The type of view we are showing (files, changes etc)
419
dir_parts = path.strip('/').split('/')
420
inner_breadcrumbs = []
421
for index, dir_name in enumerate(dir_parts):
422
inner_breadcrumbs.append({
423
'dir_name': dir_name,
424
'file_id': inv.path2id('/'.join(dir_parts[:index + 1])),
425
'suffix': '/' + view,
427
return inner_breadcrumbs
430
345
def decorator(unbound):
432
346
def new_decorator(f):
434
348
g.__name__ = f.__name__
444
358
# common threading-lock decorator
447
359
def with_lock(lockname, debug_name=None):
448
360
if debug_name is None:
449
361
debug_name = lockname
452
363
def _decorator(unbound):
454
364
def locked(self, *args, **kw):
455
365
getattr(self, lockname).acquire()
467
376
def _f(*a, **kw):
468
377
from loggerhead.lsprof import profile
471
380
ret, stats = profile(f, *a, **kw)
472
log.debug('Finished profiled %s in %d msec.' % (f.__name__,
473
int((time.time() - z) * 1000)))
381
log.debug('Finished profiled %s in %d msec.' % (f.__name__, int((time.time() - z) * 1000)))
476
384
now = time.time()
477
385
msec = int(now * 1000) % 1000
478
timestr = time.strftime('%Y%m%d%H%M%S',
479
time.localtime(now)) + ('%03d' % msec)
386
timestr = time.strftime('%Y%m%d%H%M%S', time.localtime(now)) + ('%03d' % msec)
480
387
filename = f.__name__ + '-' + timestr + '.lsprof'
481
388
cPickle.dump(stats, open(filename, 'w'), 2)
538
445
overrides = dict((k, v) for (k, v) in overrides.iteritems() if k in _valid)
539
446
map.update(overrides)
543
class Reloader(object):
545
This class wraps all paste.reloader logic. All methods are @classmethod.
548
_reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
551
def _turn_sigterm_into_systemexit(self):
553
Attempts to turn a SIGTERM exception into a SystemExit exception.
560
def handle_term(signo, frame):
562
signal.signal(signal.SIGTERM, handle_term)
565
def is_installed(self):
566
return os.environ.get(self._reloader_environ_key)
570
from paste import reloader
571
reloader.install(int(1))
574
def restart_with_reloader(self):
575
"""Based on restart_with_monitor from paste.script.serve."""
576
print 'Starting subprocess with file monitor'
578
args = [sys.executable] + sys.argv
579
new_environ = os.environ.copy()
580
new_environ[self._reloader_environ_key] = 'true'
584
self._turn_sigterm_into_systemexit()
585
proc = subprocess.Popen(args, env=new_environ)
586
exit_code = proc.wait()
588
except KeyboardInterrupt:
589
print '^C caught in monitor process'
593
and hasattr(os, 'kill')):
596
os.kill(proc.pid, signal.SIGTERM)
597
except (OSError, IOError):
600
# Reloader always exits with code 3; but if we are
601
# a monitor, any exit code will restart
604
print '-'*20, 'Restarting', '-'*20