== installation paths ==

remove deprecated python BLI_gethome_folder calls

Patch by Brecht, thanks a lot
This commit is contained in:
Andrea Weikert 2010-07-15 20:02:53 +00:00
parent 7fc9eee08a
commit 05fb497f75
5 changed files with 18 additions and 181 deletions

@ -19,7 +19,7 @@
# <pep8 compliant>
"""
This module contains utility functions spesific to blender but
This module contains utility functions specific to blender but
not assosiated with blenders internal data.
"""
@ -27,7 +27,8 @@ import bpy as _bpy
import os as _os
import sys as _sys
from _bpy import home_paths, blend_paths
from _bpy import blend_paths
from _bpy import script_paths as _bpy_script_paths
def _test_import(module_name, loaded_modules):
@ -313,7 +314,7 @@ def script_paths(subdir=None, user=True):
else:
user_script_path = None
for path in home_paths("scripts") + (user_script_path, ):
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):

@ -41,31 +41,6 @@ struct ListBase;
struct direntry;
char *BLI_gethome(void);
char *BLI_gethome_folder(char *folder_name, int flag);
/* BLI_gethome_folder flag */
#define BLI_GETHOME_LOCAL 1<<1 /* relative location for portable binaries */
#define BLI_GETHOME_SYSTEM 1<<2 /* system location, or set from the BLENDERPATH env variable (UNIX only) */
#define BLI_GETHOME_USER 1<<3 /* home folder ~/.blender */
#define BLI_GETHOME_ALL (BLI_GETHOME_SYSTEM|BLI_GETHOME_LOCAL|BLI_GETHOME_USER)
#ifdef __APPLE__
typedef enum {
BasePath_Temporary = 1,
BasePath_BlenderShared,
BasePath_BlenderUser,
BasePath_ApplicationBundle
} basePathesTypes;
/**
* Gets the base path. The path may not exist.
* Note that return string must be copied as its persistence is not guaranteed
*
* @return base path of pathType
*/
const char* BLI_osx_getBasePath(basePathesTypes pathType);
#endif
char *BLI_get_folder(int folder_id, char *subfolder);
char *BLI_get_folder_create(int folder_id, char *subfolder);

@ -795,121 +795,6 @@ char *BLI_gethome(void) {
#endif
}
/* this function returns the path to a blender folder, if it exists
* utility functions for BLI_gethome_folder */
// #define PATH_DEBUG /* for testing paths that are checked */
static int test_data_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
{
char tmppath[FILE_MAXDIR];
if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep);
else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
BLI_make_file_string("/", targetpath, tmppath, folder_name);
if (BLI_is_dir(targetpath)) {
#ifdef PATH_DEBUG
printf("\tpath found: %s\n", targetpath);
#endif
return 1;
}
else {
#ifdef PATH_DEBUG
printf("\tpath missing: %s\n", targetpath);
#endif
targetpath[0] = '\0';
return 0;
}
}
static int gethome_path_local(char *targetpath, char *folder_name)
{
extern char bprogname[]; /* argv[0] from creator.c */
char bprogdir[FILE_MAXDIR];
char cwd[FILE_MAXDIR];
char *s;
int i;
#ifdef PATH_DEBUG
printf("gethome_path_local...\n");
#endif
/* try release/folder_name (binary relative) */
/* use argv[0] (bprogname) to get the path to the executable */
s = BLI_last_slash(bprogname);
i = s - bprogname + 1;
BLI_strncpy(bprogdir, bprogname, i);
/* try release/folder_name (BIN relative) */
if(test_data_path(targetpath, bprogdir, "release", folder_name))
return 1;
/* try release/folder_name (CWD relative) */
if(test_data_path(targetpath, BLI_getwdN(cwd), "release", folder_name))
return 1;
/* try ./.blender/folder_name */
if(test_data_path(targetpath, bprogdir, ".blender", folder_name))
return 1;
return 0;
}
static int gethome_path_user(char *targetpath, char *folder_name)
{
char *home_path= BLI_gethome();
#ifdef PATH_DEBUG
printf("gethome_path_user...\n");
#endif
/* try $HOME/folder_name */
return test_data_path(targetpath, home_path, ".blender", folder_name);
}
static int gethome_path_system(char *targetpath, char *folder_name)
{
extern char blender_path[]; /* unix prefix eg. /usr/share/blender/2.5 creator.c */
if(!blender_path[0])
return 0;
#ifdef PATH_DEBUG
printf("gethome_path_system...\n");
#endif
/* try $BLENDERPATH/folder_name */
return test_data_path(targetpath, blender_path, NULL, folder_name);
}
char *BLI_gethome_folder(char *folder_name, int flag)
{
static char fulldir[FILE_MAXDIR] = "";
/* first check if this is a redistributable bundle */
if(flag & BLI_GETHOME_LOCAL) {
if (gethome_path_local(fulldir, folder_name))
return fulldir;
}
/* then check if the OS has blender data files installed in a global location */
if(flag & BLI_GETHOME_SYSTEM) {
if (gethome_path_system(fulldir, folder_name))
return fulldir;
}
/* now check the users home dir for data files */
if(flag & BLI_GETHOME_USER) {
if (gethome_path_user(fulldir, folder_name))
return fulldir;
}
return NULL;
}
/* NEW stuff, to be cleaned up when fully migrated */
/* ************************************************************* */
/* ************************************************************* */

@ -41,33 +41,23 @@
#include "../generic/blf_api.h"
#include "../generic/IDProp.h"
static char bpy_home_paths_doc[] =
".. function:: home_paths(subfolder)\n"
static char bpy_script_paths_doc[] =
".. function:: script_paths()\n"
"\n"
" Return 3 paths to blender home directories.\n"
" Return 2 paths to blender scripts directories.\n"
"\n"
" :arg subfolder: The name of a subfolder to find within the blenders home directory.\n"
" :type subfolder: string\n"
" :return: (system, local, user) strings will be empty when not found.\n"
" :return: (system, user) strings will be empty when not found.\n"
" :rtype: tuple of strigs\n";
PyObject *bpy_home_paths(PyObject *self, PyObject *args)
PyObject *bpy_script_paths(PyObject *self)
{
PyObject *ret= PyTuple_New(3);
PyObject *ret= PyTuple_New(2);
char *path;
char *subfolder= "";
if (!PyArg_ParseTuple(args, "|s:blender_homes", &subfolder))
return NULL;
path= BLI_gethome_folder(subfolder, BLI_GETHOME_SYSTEM);
path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
path= BLI_gethome_folder(subfolder, BLI_GETHOME_LOCAL);
path= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
path= BLI_gethome_folder(subfolder, BLI_GETHOME_USER);
PyTuple_SET_ITEM(ret, 2, PyUnicode_FromString(path?path:""));
return ret;
}
@ -120,7 +110,7 @@ static PyObject *bpy_blend_paths(PyObject * self, PyObject *args, PyObject *kw)
return list;
}
static PyMethodDef meth_bpy_home_paths[] = {{ "home_paths", (PyCFunction)bpy_home_paths, METH_VARARGS, bpy_home_paths_doc}};
static PyMethodDef meth_bpy_script_paths[] = {{ "script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc}};
static PyMethodDef meth_bpy_blend_paths[] = {{ "blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc}};
static void bpy_import_test(char *modname)
@ -191,7 +181,7 @@ void BPy_init_modules( void )
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
/* utility func's that have nowhere else to go */
PyModule_AddObject(mod, meth_bpy_home_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_home_paths, NULL));
PyModule_AddObject(mod, meth_bpy_script_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_script_paths, NULL));
PyModule_AddObject(mod, meth_bpy_blend_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_blend_paths, NULL));
/* add our own modules dir, this is a python package */

@ -131,14 +131,6 @@ extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
char btempdir[FILE_MAXDIR+FILE_MAXFILE];
/* unix path support.
* defined by the compiler. eg "/usr/share/blender/2.5" "/opt/blender/2.5" */
#ifndef BLENDERPATH
#define BLENDERPATH ""
#endif
char blender_path[FILE_MAXDIR+FILE_MAXFILE] = BLENDERPATH;
/* Initialise callbacks for the modules that need them */
static void setCallbacks(void);
@ -297,14 +289,14 @@ static int print_help(int argc, char **argv, void *data)
printf (" $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n");
printf (" $BLENDER_SYSTEM_PYTHON Directory for system python libraries.\n");
#ifdef WIN32
printf (" $TEMP Store temporary files here.\n");
printf (" $TEMP Store temporary files here.\n");
#else
printf (" $TMP or $TMPDIR Store temporary files here.\n");
printf (" $TMP or $TMPDIR Store temporary files here.\n");
#endif
#ifndef DISABLE_SDL
printf (" $SDL_AUDIODRIVER LibSDL audio driver - alsa, esd, alsa, dma.\n");
printf (" $SDL_AUDIODRIVER LibSDL audio driver - alsa, esd, dma.\n");
#endif
printf (" $PYTHONHOME Path to the python directory, eg. /usr/lib/python.\n\n");
printf (" $PYTHONHOME Path to the python directory, eg. /usr/lib/python.\n\n");
exit(0);
@ -1040,12 +1032,6 @@ int main(int argc, char **argv)
BLI_where_am_i(bprogname, argv[0]);
{ /* override the hard coded blender path */
char *blender_path_env = getenv("BLENDERPATH");
if(blender_path_env)
BLI_strncpy(blender_path, blender_path_env, sizeof(blender_path));
}
#ifdef BUILD_DATE
strip_quotes(build_date);
strip_quotes(build_time);