Example #1
0
def use_cwd_structure():
    """Used by the shell to run of the current sys.path and merge a structure.py module into
    the thepian.conf.structure object."""
    script_file_name = realpath(sys.argv[0] or sys.executable)
    try:
        project_directory = find_basedir(os.getcwd())[1]
        conf_dir = join(project_directory,"conf")
        if exists(conf_dir):
            sys.path.append(conf_dir)
    except Exception,e:
        print e, ':: will use Thepian Maestro as project'
        project_directory = find_basedir(script_file_name)
Example #2
0
def django_execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    from os.path import realpath
    script_file_name=realpath((argv or sys.argv)[0])
    try:
        project_directory = find_basedir(os.getcwd())[1]
    except:
        #TODO exlude project based commands
        from os.path import dirname
        project_directory = dirname(dirname(script_file_name))
        
    from thepian.conf import structure, use_structure, use_default_structure
    structure.SCRIPT_PATH = script_file_name
    try:
        from os.path import join
        sys.path.insert(0,join(project_directory,"conf")) #TODO too simplistic, use real project tree
        import structure as conf_structure
        use_structure(conf_structure)
        site.addsitedir(structure.PYTHON_DIR)
    except ImportError:
        use_default_structure()

    structure.COMMAND_VARIABLE_PREFIX = "MAESTRO" 
    settings_module = determine_settings_module(argv or sys.argv)
    from thepian.conf import use_settings, settings
    use_settings(settings_module)

    import django.conf
    django.conf.settings.configure(**settings.__dict__)
    import django.core.management
    django.core.management.execute_from_command_line(argv)
Example #3
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 #4
0
def maestro_execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    from os.path import realpath
    script_file_name=realpath((argv or sys.argv)[0])
    try:
        project_directory = find_basedir(os.getcwd())[1]
    except Exception,e:
        print e, ':: will use Thepian Maestro as project'
        from os.path import dirname
        project_directory = dirname(dirname(script_file_name))
Example #5
0
def execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    from os.path import realpath
    script_file_name=realpath((argv or sys.argv)[0])
    try:
        project_directory = find_basedir(os.getcwd())[1]
    except Exception,e:
        print e, ':: will use Thepian Maestro as project'
        #TODO rather than fail if used outside a project, use thepian.config as project?
        #TODO exlude project based commands
        from os.path import dirname
        project_directory = dirname(dirname(script_file_name))
Example #6
0
def use_structure(mod):
    """Used by the shell to run of the current sys.path and merge a structure.py module into
    the thepian.conf.structure object."""
    structure.apply_basedir(*find_basedir(dirname(abspath(mod.__file__))))
    structure.blend(mod)
Example #7
0
def use_default_structure():
    """Used by the shell to run of the current sys.path and merge a structure.py module into
    the thepian.conf.structure object."""
    script_file_name = realpath(sys.argv[0] or sys.executable)
    structure.SCRIPT_PATH = script_file_name
    structure.apply_basedir(*find_basedir(abspath(structure.SCRIPT_PATH)))