summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-03-27 09:09:34 -0300
committerTomás Touceda <chiiph@leap.se>2013-03-27 09:09:34 -0300
commit14f3454afd92e1ae37950eb9d8bbb1bf750a1ed9 (patch)
tree48c960df396fcf583c255c5fad4999e747ad8d52 /src
parentc890a5590d0e5ac9eaf2b7a173c827f2ca10e3be (diff)
Calculate workdir in the launcher, set PythonHome to that
It will look for dependencies in PYTHONHOME/lib
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 237b282..9db7a2d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,34 +3,44 @@
#include <string>
#include <boost/python.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
#include <frameobject.h>
-using namespace boost::python;
+namespace py = boost::python;
+namespace fs = boost::filesystem;
int
main(int argc, char** argv)
{
try {
+ fs::path full_path(fs::current_path());
+
Py_Initialize();
- object main_module = import("__main__");
- object global = (main_module.attr("__dict__"));
+
+ Py_SetPythonHome(const_cast<char*>(full_path.string().c_str()));
+
+ py::object main_module = py::import("__main__");
+ py::object global = (main_module.attr("__dict__"));
PySys_SetArgv(argc, argv);
- exec(
- "import os\n"
+ global["_pwd"] = full_path.string();
+
+ py::exec(
"import sys\n"
+ "sys.path = [_pwd + '/lib',\n"
+ " _pwd + '/apps',\n"
+ " _pwd + '/apps/eip',\n"
+ " _pwd]\n"
+ "import os\n"
"import encodings.idna\n" // we need to make sure this is imported
- "sys.path = [os.path.join(os.getcwd(), 'deps'),\n"
- " os.path.join(os.getcwd(), 'apps'),\n"
- " os.path.join(os.getcwd(), 'apps', 'eip'),\n"
- " os.getcwd()]\n"
"sys.argv.append('--standalone')\n", global, global);
- exec_file("apps/leap/app.py",
- global,
- global);
- } catch (error_already_set&) {
+ py::exec_file("apps/leap/app.py",
+ global,
+ global);
+ } catch (py::error_already_set&) {
PyErr_PrintEx(0);
return 1;
}