~mnordhoff/loggerhead/cheezum

« back to all changes in this revision

Viewing changes to loggerhead/util.py

  • Committer: Guillermo Gonzalez
  • Date: 2008-09-10 00:13:18 UTC
  • mfrom: (164.18.29 trunk)
  • mto: (164.35.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 242.
  • Revision ID: guillo.gonzo@gmail.com-20080910001318-78w16x9zl9p7f1k3
 * merge with trunk 

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import struct
33
33
import threading
34
34
import time
35
 
import types
 
35
 
36
36
 
37
37
log = logging.getLogger("loggerhead.controllers")
38
38
 
342
342
            [navigation.scan_url, next_page_revno], **params)
343
343
 
344
344
 
 
345
def directory_breadcrumbs(path, is_root, view):
 
346
    """
 
347
    Generate breadcrumb information from the directory path given
 
348
 
 
349
    The path given should be a path up to any branch that is currently being
 
350
    served
 
351
 
 
352
    Arguments:
 
353
    path -- The path to convert into breadcrumbs
 
354
    is_root -- Whether or not loggerhead is serving a branch at its root
 
355
    view -- The type of view we are showing (files, changes etc)
 
356
    """
 
357
    # Is our root directory itself a branch?
 
358
    if is_root:
 
359
        if view == 'directory':
 
360
            directory = 'files'
 
361
        breadcrumbs = [{
 
362
            'dir_name': path,
 
363
            'path': '',
 
364
            'suffix': view,
 
365
        }]
 
366
    else:
 
367
        # Create breadcrumb trail for the path leading up to the branch
 
368
        breadcrumbs = [{
 
369
            'dir_name': "(root)",
 
370
            'path': '',
 
371
            'suffix': '',
 
372
        }]
 
373
        if path != '/':
 
374
            dir_parts = path.strip('/').split('/')
 
375
            for index, dir_name in enumerate(dir_parts):
 
376
                breadcrumbs.append({
 
377
                    'dir_name': dir_name,
 
378
                    'path': '/'.join(dir_parts[:index + 1]),
 
379
                    'suffix': '',
 
380
                })
 
381
            # If we are not in the directory view, the last crumb is a branch,
 
382
            # so we need to specify a view
 
383
            if view != 'directory':
 
384
                breadcrumbs[-1]['suffix'] = '/' + view
 
385
    return breadcrumbs
 
386
 
 
387
 
 
388
def branch_breadcrumbs(path, inv, view):
 
389
    """
 
390
    Generate breadcrumb information from the branch path given
 
391
 
 
392
    The path given should be a path that exists within a branch
 
393
 
 
394
    Arguments:
 
395
    path -- The path to convert into breadcrumbs
 
396
    inv -- Inventory to get file information from
 
397
    view -- The type of view we are showing (files, changes etc)
 
398
    """
 
399
    dir_parts = path.strip('/').split('/')
 
400
    inner_breadcrumbs = []
 
401
    for index, dir_name in enumerate(dir_parts):
 
402
        inner_breadcrumbs.append({
 
403
            'dir_name': dir_name,
 
404
            'file_id': inv.path2id('/'.join(dir_parts[:index + 1])),
 
405
            'suffix': '/' + view ,
 
406
        })
 
407
    return inner_breadcrumbs
 
408
 
 
409
 
345
410
def decorator(unbound):
346
411
    def new_decorator(f):
347
412
        g = unbound(f)