pgcontents/hybridmanager.py
def _apply_prefix(prefix, model):
    """
    Prefix all path entries in model with the given prefix.
    """
    if not isinstance(model, dict):
        raise TypeError("Expected dict for model, got %s" % type(model))

    # We get unwanted leading/trailing slashes if prefix or model['path'] are
    # '', both of which are legal values.
    model['path'] = '/'.join((prefix, model['path'])).strip('/')
    if model['type'] in ('notebook', 'file'):
        return model

    if model['type'] != 'directory':
        raise ValueError("Unknown model type %s." % type(model))

    content = model.get('content', None)
    if content is not None:
        for sub_model in content:
            _apply_prefix(prefix, sub_model)

    return model
def _apply_prefix(prefix, model):
    """
    Prefix all path entries in model with the given prefix.
    """
    if not isinstance(model, dict):
        raise TypeError("Expected dict for model, got %s" % type(model))

    # We get unwanted leading/trailing slashes if prefix or model['path'] are
    # '', both of which are legal values.
    model['path'] = '/'.join((prefix, model['path'])).strip('/')
    if model['type'] in ('notebook', 'file'):
        return model

    if model['type'] != 'directory':
        raise ValueError("Unknown model type %s." % type(model))

    content = model.get('content', None)
    if content is not None:
        for sub_model in content:
            _apply_prefix(prefix, sub_model)

    return model
Prefix all path entries in model with the given prefix.