Example #1
0
def import_structure(directory,structure_name='structure'):
    """Make a structure object based on thepian.conf.global_structure and structure variables
    found in the file specified.
    directory Current directory, or some other directory in the repository
    """
    import imp, hashlib

    repo_dir, basedir, repo_type = find_basedir(directory)
    k = hashlib.sha1(structure_name + ":" + basedir).hexdigest()
    if k in _already_imported:
        return _already_imported[k]
        
    struct = Structure()  
    struct.apply_basedir(repo_dir, basedir, repo_type)

    f, filename, description = imp.find_module(structure_name,[struct.CONF_DIR])
    if not f:
        raise ImportError, "ad hoc structure, %s not found in %s" % (structure_name,struct.CONF_DIR)
    try:
        mod = imp.load_module("thepian.conf."+k, f, filename, description)
        struct.blend(mod)
        _already_imported[k] = struct
    finally:
        f.close()
        return struct
Example #2
0
def test_base_Structure_class():
    from os.path import dirname
    from thepian.conf import global_structure
    from thepian.conf.base import Structure
    structure = Structure()
    assert structure.__file__ == ''
    
    # All entries in global_structure are found in a new structure
    for name in dir(global_structure):
        if name == name.upper():
            assert getattr(structure,name) == getattr(global_structure,name)
            
    # All entries in global_structure are found after blending in a blank structure module
    from samples import sample_structure
    repo_dir = basedir = dirname(sample_structure.__file__)
    structure.apply_basedir(repo_dir, basedir, "single")
            
    structure.blend(sample_structure)
    for name in dir(sample_structure):
        if name == name.upper():
            assert getattr(structure,name) == getattr(sample_structure,name)
    assert structure.__file__ == sample_structure.__file__

    # New properties are found after blending in a structure module
    from samples import sample_structure2
    structure.blend(sample_structure2)
    assert structure.BOGUS == sample_structure2.BOGUS
    assert structure.SILLY_TUPLE == sample_structure2.SILLY_TUPLE
    assert structure.__file__ == sample_structure2.__file__
Example #3
0
def create_site_structure(site_name,structure_name="structure"):
    """Make a structure object based on thepian.conf.global_structure. Then create skeleton 
    structure in directory. This doesn't import and blend structure.py, which can be done
    afterwards.
    directory - Must be the exact project directory. Normally ~/Sites/<project>
    extended - Should the extended tree be created?
    """
    import hashlib

    directory = expanduser(join("/Sites",site_name))
    release_directory = join("/Sites",site_name)
    k = hashlib.sha1(structure_name + ":" + directory).hexdigest()
    if k in _already_imported:
        return _already_imported[k]
        
    struct = Structure()  
    make_project_tree(directory,single=True)
    struct.apply_basedir(directory, directory, "single")
    
    _already_imported[k] = struct
    return struct
Example #4
0
def create_structure(directory,structure_name="structure",extended=False):
    """Make a structure object based on thepian.conf.global_structure. Then create skeleton 
    structure in directory. This doesn't import and blend structure.py, which can be done
    afterwards.
    directory - Must be the exact project directory. Normally ~/Sites/<project>
    extended - Should the extended tree be created?
    """
    import hashlib

    directory = expanduser(directory)
    repo_dir = join(directory,"src")
    basedir = join(directory,"src","main")
    k = hashlib.sha1(structure_name + ":" + basedir).hexdigest()
    if k in _already_imported:
        return _already_imported[k]

    struct = Structure()  
    make_project_tree(directory,extended)
    struct.apply_basedir(repo_dir, basedir, "src")
    
    _already_imported[k] = struct
    return struct