Permalink
Browse files

[droid] trick python into using our APK as its home

Since python allows for PYTHONHOME to be a zip file, point it to our apk and
let it take care of extraction.

This way we get the best of both worlds: we don't have to install a duplicate
copy in cache, and we don't have to extract to temp at runtime.
  • Loading branch information...
1 parent 0273fc6 commit b9d9642090c89eb54480ed0481ba4ecb269d0188 Cory Fields committed Jun 19, 2012
Showing with 20 additions and 2 deletions.
  1. +12 −1 xbmc/cores/DllLoader/exports/emu_msvcrt.cpp
  2. +8 −1 xbmc/interfaces/python/XBPython.cpp
@@ -172,10 +172,21 @@ extern "C" void __stdcall init_emu_environ()
dll_putenv(string("PATH=.;" + CSpecialProtocol::TranslatePath("special://xbmc") + ";" +
CSpecialProtocol::TranslatePath("special://xbmc/system/python")).c_str());
}
+
+#if defined(TARGET_ANDROID)
+ string apkPath = getenv("XBMC_ANDROID_APK");
+ apkPath += "/assets/python2.6";
+ dll_putenv(string("PYTHONHOME=" + apkPath).c_str());
+ dll_putenv("PYTHONOPTIMIZE=");
+ dll_putenv("PYTHONNOUSERSITE=1");
+ dll_putenv("PYTHONPATH=");
+#else
+ dll_putenv("PYTHONOPTIMIZE=1");
+#endif
+
//dll_putenv("PYTHONCASEOK=1");
//dll_putenv("PYTHONDEBUG=1");
//dll_putenv("PYTHONVERBOSE=2"); // "1" for normal verbose, "2" for more verbose ?
- dll_putenv("PYTHONOPTIMIZE=1");
//dll_putenv("PYTHONDUMPREFS=1");
//dll_putenv("THREADDEBUG=1");
//dll_putenv("PYTHONMALLOCSTATS=1");
@@ -522,7 +522,7 @@ void XBPython::Initialize()
// Info about interesting python envvars available
// at http://docs.python.org/using/cmdline.html#environment-variables
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(TARGET_ANDROID)
/* PYTHONOPTIMIZE is set off intentionally when using external Python.
Reason for this is because we cannot be sure what version of Python
was used to compile the various Python object files (i.e. .pyo,
@@ -553,6 +553,13 @@ void XBPython::Initialize()
buf = "OS=win32";
pgwin32_putenv(buf.c_str());
+#elif defined(TARGET_ANDROID)
+ CStdString apkPath = getenv("XBMC_ANDROID_APK");
+ apkPath += "/assets/python2.6";
+ setenv("PYTHONHOME",apkPath.c_str(), 1);
+ setenv("PYTHONPATH", "", 1);
+ setenv("PYTHONOPTIMIZE","",1);
+ setenv("PYTHONNOUSERSITE","1",1);
#endif
if (PyEval_ThreadsInitialized())

0 comments on commit b9d9642

Please sign in to comment.