Esempio n. 1
0
def script_paths(subdir=None, user=True):
    """
    Returns a list of valid script paths from the home directory and user preferences.

    Accepts any number of string arguments which are joined to make a path.
    """
    scripts = list(_scripts)

    # add user scripts dir
    if user:
        user_script_path = _bpy.context.user_preferences.filepaths.script_directory
    else:
        user_script_path = None

    for path in _bpy_script_paths() + (user_script_path, ):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if not subdir:
        return scripts

    script_paths = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            script_paths.append(path_subdir)

    return script_paths
def script_paths(subdir=None, user=True):
    """
    Returns a list of valid script paths from the home directory and user preferences.

    Accepts any number of string arguments which are joined to make a path.
    """
    scripts = list(_scripts)

    # add user scripts dir
    if user:
        user_script_path = _bpy.context.user_preferences.filepaths.script_directory
    else:
        user_script_path = None

    for path in _bpy_script_paths() + (user_script_path, ):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if not subdir:
        return scripts

    script_paths = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            script_paths.append(path_subdir)

    return script_paths
Esempio n. 3
0
def script_paths(subdir=None, user_pref=True, check_all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg check_all: Include local, user and system paths rather just the paths
       blender uses.
    :type check_all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)
    prefs = _bpy.context.user_preferences

    # add user scripts dir
    if user_pref:
        user_script_path = prefs.filepaths.script_directory
    else:
        user_script_path = None

    if check_all:
        # all possible paths
        base_paths = tuple(
            _os.path.join(resource_path(res), "scripts")
            for res in ('LOCAL', 'USER', 'SYSTEM'))
    else:
        # only paths blender uses
        base_paths = _bpy_script_paths()

    for path in base_paths + (user_script_path, ):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if subdir is None:
        return scripts

    script_paths = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            script_paths.append(path_subdir)

    return script_paths
Esempio n. 4
0
def script_paths(subdir=None, user_pref=True, all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg all: Include local, user and system paths rather just the paths
       blender uses.
    :type all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)
    prefs = _bpy.context.user_preferences

    # add user scripts dir
    if user_pref:
        user_script_path = prefs.filepaths.script_directory
    else:
        user_script_path = None

    if all:
        # all possible paths
        base_paths = tuple(_os.path.join(resource_path(res), "scripts")
                           for res in ('LOCAL', 'USER', 'SYSTEM'))
    else:
        # only paths blender uses
        base_paths = _bpy_script_paths()

    for path in base_paths + (user_script_path, ):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if subdir is None:
        return scripts

    script_paths = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            script_paths.append(path_subdir)

    return script_paths
Esempio n. 5
0
def script_paths(subdir=None, user_pref=True, check_all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg check_all: Include local, user and system paths rather just the paths
       blender uses.
    :type check_all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)

    # Only paths Blender uses.
    #
    # Needed this is needed even when 'check_all' is enabled,
    # so the 'BLENDER_SYSTEM_SCRIPTS' environment variable will be used.
    base_paths = _bpy_script_paths()

    if check_all:
        # All possible paths, no duplicates, keep order.
        base_paths = (
            *(path for path in (_os.path.join(resource_path(res), "scripts")
                                for res in ('LOCAL', 'USER', 'SYSTEM'))
              if path not in base_paths),
            *base_paths,
        )

    for path in (*base_paths, script_path_user(), script_path_pref()):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if subdir is None:
        return scripts

    scripts_subdir = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            scripts_subdir.append(path_subdir)

    return scripts_subdir
Esempio n. 6
0
def script_paths(subdir=None, user_pref=True, check_all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg check_all: Include local, user and system paths rather just the paths
       blender uses.
    :type check_all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)

    # Only paths Blender uses.
    #
    # Needed this is needed even when 'check_all' is enabled,
    # so the 'BLENDER_SYSTEM_SCRIPTS' environment variable will be used.
    base_paths = _bpy_script_paths()

    if check_all:
        # All possible paths, no duplicates, keep order.
        base_paths = (
            *(path for path in (_os.path.join(resource_path(res), "scripts")
              for res in ('LOCAL', 'USER', 'SYSTEM')) if path not in base_paths),
            *base_paths,
            )

    for path in (*base_paths, script_path_user(), script_path_pref()):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if subdir is None:
        return scripts

    scripts_subdir = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            scripts_subdir.append(path_subdir)

    return scripts_subdir
Esempio n. 7
0
def script_paths(subdir=None, user_pref=True, check_all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg check_all: Include local, user and system paths rather just the paths
       blender uses.
    :type check_all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)

    if check_all:
        # all possible paths
        base_paths = tuple(_os.path.join(resource_path(res), "scripts") for res in ("LOCAL", "USER", "SYSTEM"))
    else:
        # only paths blender uses
        base_paths = _bpy_script_paths()

    for path in base_paths + (script_path_user(), script_path_pref()):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    if subdir is None:
        return scripts

    scripts_subdir = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            scripts_subdir.append(path_subdir)

    return scripts_subdir
Esempio n. 8
0
def script_paths(subdir=None, user_pref=True, check_all=False):
    """
    Returns a list of valid script paths.

    :arg subdir: Optional subdir.
    :type subdir: string
    :arg user_pref: Include the user preference script path.
    :type user_pref: bool
    :arg check_all: Include local, user and system paths rather just the paths
       blender uses.
    :type check_all: bool
    :return: script paths.
    :rtype: list
    """
    scripts = list(_scripts)

    # Only paths Blender uses.
    #
    # Needed this is needed even when 'check_all' is enabled,
    # so the 'BLENDER_SYSTEM_SCRIPTS' environment variable will be used.
    base_paths = _bpy_script_paths()

    if check_all:
        # All possible paths, no duplicates, keep order.
        base_paths = (
            *(path for path in (_os.path.join(resource_path(res), "scripts")
              for res in ('LOCAL', 'USER', 'SYSTEM')) if path not in base_paths),
            *base_paths,
            )

    for path in (*base_paths, script_path_user(), script_path_pref()):
        if path:
            path = _os.path.normpath(path)
            if path not in scripts and _os.path.isdir(path):
                scripts.append(path)

    def user_paths(name):
        paths = []
        dirpath = _os.path.join(resource_path('USER'), 'config')
        path = _os.path.join(dirpath, name + '.pth')
        if _os.path.isfile(path):
            cwd = _os.getcwd()
            _os.chdir(dirpath)
            try:
                with open(path) as f:
                    for line in f.readlines():
                        line = line.rstrip('\n')
                        if line:
                            if line.startswith('#'):
                                continue
                            p = _os.path.abspath(_os.path.expanduser(line))
                            if _os.path.isdir(p):
                                if p not in paths:
                                    paths.append(p)
            except:
                pass
            _os.chdir(cwd)
        return paths

    for p in user_paths('scripts'):
        if p not in scripts:
            scripts.append(p)

    if subdir is None:
        return scripts

    scripts_subdir = []
    for path in scripts:
        path_subdir = _os.path.join(path, subdir)
        if _os.path.isdir(path_subdir):
            scripts_subdir.append(path_subdir)

    for p in user_paths(subdir):
        if p not in scripts_subdir:
            scripts_subdir.append(p)

    return scripts_subdir