diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2011-04-10 17:46:24 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2011-04-14 10:04:46 -0400 |
commit | 6391cc510f4bba95fab79575246aa83003cdacaa (patch) | |
tree | 7df73ec32797e78b45c7c7e27e8743338ac6ee73 | |
parent | f275c4a8341a4c49833cbcf244f602f59e2ff904 (diff) |
This will allow scripts to run in a backward compatible way without requiring modifications to the core python behavior.
-rw-r--r-- | xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp b/xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp index 7eaaec7cff..517a620e9f 100644 --- a/xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp +++ b/xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp @@ -24,6 +24,7 @@ #include "pythreadstate.h" #include "addons/AddonManager.h" #include "addons/GUIDialogAddonSettings.h" +#include "utils/log.h" #ifndef __GNUC__ #pragma code_seg("PY_TEXT") @@ -41,6 +42,22 @@ using ADDON::CAddonMgr; namespace PYXBMC { + + static const char* getDefaultId() + { + const char* id = NULL; + + // Get a reference to the main module + // and global dictionary + PyObject* main_module = PyImport_AddModule((char*)"__main__"); + PyObject* global_dict = PyModule_GetDict(main_module); + // Extract a reference to the function "func_name" + // from the global dictionary + PyObject* pyid = PyDict_GetItemString(global_dict, "__xbmcaddonid__"); + id = PyString_AsString(pyid); + return id; + } + PyObject* Addon_New(PyTypeObject *type, PyObject *args, PyObject *kwds) { Addon *self; @@ -66,22 +83,18 @@ namespace PYXBMC // if the id wasn't passed then get the id from // the global dictionary - if (id == NULL) + if (!id || !CAddonMgr::Get().GetAddon(id, self->pAddon)) { - // Get a reference to the main module - // and global dictionary - PyObject* main_module = PyImport_AddModule((char*)"__main__"); - PyObject* global_dict = PyModule_GetDict(main_module); - // Extract a reference to the function "func_name" - // from the global dictionary - PyObject* pyid = PyDict_GetItemString(global_dict, "__xbmcaddonid__"); - id = PyString_AsString(pyid); - } - - if (!CAddonMgr::Get().GetAddon(id, self->pAddon)) - { - PyErr_SetString(PyExc_Exception, "Could not get AddonPtr!"); - return NULL; + // try the default ... + id = getDefaultId(); + + if (!CAddonMgr::Get().GetAddon(id, self->pAddon)) + { + PyErr_SetString(PyExc_Exception, "Could not get AddonPtr!"); + return NULL; + } + else + CLog::Log(LOGERROR,"Use of deprecated functionality. Please to not assume that \"os.getcwd\" will return the script directory."); } return (PyObject*)self; |