Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make it possible to pass non string arguments at start of a python sc…

…ript. (Since the python api doesn't really allow that, I pass those objects under sys.PARAMETERNAME
  • Loading branch information...
commit 81ff31cf9cf272ad1c2605e1f22de04a0669f428 1 parent d43af28
Fice authored
12 xbmc/interfaces/python/XBPyThread.cpp
@@ -82,6 +82,7 @@ XBPyThread::XBPyThread(XBPython *pExecuter, int id) : CThread("XBPyThread")
82 82 m_source = NULL;
83 83 m_argc = 0;
84 84 m_type = 0;
  85 + m_sysParameterPtr = NULL;
85 86 }
86 87
87 88 XBPyThread::~XBPyThread()
@@ -148,6 +149,12 @@ int XBPyThread::setArgv(const std::vector<CStdString> &argv)
148 149 return 0;
149 150 }
150 151
  152 +void XBPyThread::setSysParameter(char* sysName, PyObject* sysObject)
  153 +{
  154 + m_sysParameterPtr = sysObject;
  155 + m_sysParameterName = sysName;
  156 +}
  157 +
151 158 #define GC_SCRIPT \
152 159 "import gc\n" \
153 160 "gc.collect(2)\n"
@@ -245,6 +252,11 @@ void XBPyThread::Process()
245 252 // set current directory and python's path.
246 253 if (m_argv != NULL)
247 254 PySys_SetArgv(m_argc, m_argv);
  255 +
  256 + if (m_sysParameterPtr != NULL) {
  257 + if(0!=PySys_SetObject(m_sysParameterName, m_sysParameterPtr))
  258 + CLog::Log(LOGDEBUG, "setSysParameter failed!");
  259 + }
248 260
249 261 CLog::Log(LOGDEBUG, "%s - Setting the Python path to %s", __FUNCTION__, path.c_str());
250 262
5 xbmc/interfaces/python/XBPyThread.h
@@ -25,6 +25,7 @@
25 25 #include "threads/Thread.h"
26 26 #include "threads/Event.h"
27 27 #include "addons/IAddon.h"
  28 +#include <Python.h>
28 29
29 30 class XBPython;
30 31
@@ -35,6 +36,7 @@ class XBPyThread : public CThread
35 36 virtual ~XBPyThread();
36 37 int evalFile(const CStdString &src);
37 38 int evalString(const CStdString &src);
  39 + void setSysParameter(char* sysName, PyObject* sysObject);
38 40 int setArgv(const std::vector<CStdString> &argv);
39 41 bool isStopping();
40 42 void stop();
@@ -46,6 +48,9 @@ class XBPyThread : public CThread
46 48 CEvent stoppedEvent;
47 49 void *m_threadState;
48 50
  51 + PyObject* m_sysParameterPtr;
  52 + char* m_sysParameterName;
  53 +
49 54 char m_type;
50 55 char *m_source;
51 56 char **m_argv;
38 xbmc/interfaces/python/XBPython.cpp
@@ -732,6 +732,44 @@ int XBPython::evalFile(const CStdString &src, ADDON::AddonPtr addon)
732 732 std::vector<CStdString> argv;
733 733 return evalFile(src, argv, addon);
734 734 }
  735 +
  736 +
  737 +int XBPython::evalFile(const CStdString &src, PyObject* sysObject, char* sysName, ADDON::AddonPtr addon)
  738 +{
  739 +
  740 + CSingleExit ex(g_graphicsContext);
  741 + // return if file doesn't exist
  742 + if (!XFILE::CFile::Exists(src))
  743 + {
  744 + CLog::Log(LOGERROR, "Python script \"%s\" does not exist", CSpecialProtocol::TranslatePath(src).c_str());
  745 + return -1;
  746 + }
  747 +
  748 + // check if locked
  749 + if (g_settings.GetCurrentProfile().programsLocked() && !g_passwordManager.IsMasterLockUnlocked(true))
  750 + return -1;
  751 +
  752 + CSingleLock lock(m_critSection);
  753 + Initialize();
  754 +
  755 + if (!m_bInitialized) return -1;
  756 +
  757 + m_nextid++;
  758 + boost::shared_ptr<XBPyThread> pyThread = boost::shared_ptr<XBPyThread>(new XBPyThread(this, m_nextid));
  759 + pyThread->setSysParameter(sysName, sysObject);
  760 + pyThread->setAddon(addon);
  761 + pyThread->evalFile(src);
  762 + PyElem inf;
  763 + inf.id = m_nextid;
  764 + inf.bDone = false;
  765 + inf.strFile = src;
  766 + inf.pyThread = pyThread;
  767 +
  768 + m_vecPyList.push_back(inf);
  769 +
  770 + return m_nextid;
  771 +}
  772 +
735 773 // execute script, returns -1 if script doesn't exist
736 774 int XBPython::evalFile(const CStdString &src, const std::vector<CStdString> &argv, ADDON::AddonPtr addon)
737 775 {
2  xbmc/interfaces/python/XBPython.h
@@ -26,7 +26,6 @@
26 26 #include "threads/CriticalSection.h"
27 27 #include "interfaces/IAnnouncer.h"
28 28 #include "addons/IAddon.h"
29   -
30 29 #include <boost/shared_ptr.hpp>
31 30 #include <vector>
32 31
@@ -92,6 +91,7 @@ class XBPython :
92 91 int GetPythonScriptId(int scriptPosition);
93 92 int evalFile(const CStdString &src, ADDON::AddonPtr addon);
94 93 int evalFile(const CStdString &src, const std::vector<CStdString> &argv, ADDON::AddonPtr addon);
  94 + int evalFile(const CStdString &src, PyObject* sysObject, char* sysName, ADDON::AddonPtr addon);
95 95 int evalString(const CStdString &src, const std::vector<CStdString> &argv);
96 96
97 97 bool isRunning(int scriptId);

0 comments on commit 81ff31c

Please sign in to comment.
Something went wrong with that request. Please try again.