PythonQt
PythonQtImporter.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTIMPORTER_
2 #define _PYTHONQTIMPORTER_
3 
4 /*
5  *
6  * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * Further, this software is distributed without any warranty that it is
19  * free of the rightful claim of any third person regarding infringement
20  * or the like. Any license provided herein, whether implied or
21  * otherwise, applies only to this software file. Patent licenses, if
22  * any, provided herein do not apply to combinations of this program with
23  * other software, or any other product whatsoever.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29  * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30  * 28359 Bremen, Germany or:
31  *
32  * http://www.mevis.de
33  *
34  */
35 
36 //----------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------
44 
45 #include "PythonQtPythonInclude.h"
46 
47 #include "compile.h"
48 #include "marshal.h"
49 #include "osdefs.h"
50 #include "structmember.h"
51 #include <ctime>
52 
53 #include <qobject.h>
54 #include <qstring.h>
55 
56 
59  PyObject_HEAD
60  QString* _path;
61 };
62 
63 
65 
68 {
69 public:
70 
71  enum ModuleType {
76  };
77 
78  struct ModuleInfo {
81  }
82  QString fullPath;
83  QString moduleName;
85  };
86 
88  static void init();
89 
91  static void writeCompiledModule(PyCodeObject *co, const QString& filename, long mtime, long sourceSize);
92 
98  static PyObject *unmarshalCode(const QString& path, const QByteArray& data, time_t mtime);
99 
102  static PyObject *compileSource(const QString& path, const QByteArray& data);
103 
106  static PyObject *getCodeFromData(const QString& path, int isbytecode = 0, int ispackage = 0,
107  time_t mtime = 0);
108 
113  const char* fullname, QString& modpath, QString& cachemodpath);
114 
115 
117  static PyObject* getCodeFromPyc(const QString& file);
118 
120  static ModuleInfo getModuleInfo(PythonQtImporter* self, const QString& fullname);
121 
123  static QString getSubName(const QString& str);
124 
128  static long getLong(unsigned char *buf);
129 
131  static time_t getMTimeOfSource(const QString& path);
132 
134  static QString replaceExtension(const QString& str, const QString& ext);
135 
137  static QString getCacheFilename(const QString& sourceFile, bool isOptimizedFilename);
138 
140  static QString getSourceFilename(const QString& cacheFile);
141 };
142 
143 #endif
144 
struct _object PyObject
implements importing of python files into PythonQt
static QString getSubName(const QString &str)
get the last name of a dot chain (first.second.last)
static QString getSourceFilename(const QString &cacheFile)
Returns the filename of the source file for the given cache file, e.g. test.py for test....
static QString getCacheFilename(const QString &sourceFile, bool isOptimizedFilename)
Returns the filename of the cache file for the given source file, e.g. test.pyc for test....
static PyObject * getCodeFromData(const QString &path, int isbytecode=0, int ispackage=0, time_t mtime=0)
static time_t getMTimeOfSource(const QString &path)
get time stamp of file
static ModuleInfo getModuleInfo(PythonQtImporter *self, const QString &fullname)
Return if module exists and is a package or a module.
static PyObject * unmarshalCode(const QString &path, const QByteArray &data, time_t mtime)
static QString replaceExtension(const QString &str, const QString &ext)
replace extension of file
static PyObject * compileSource(const QString &path, const QByteArray &data)
static void writeCompiledModule(PyCodeObject *co, const QString &filename, long mtime, long sourceSize)
writes the python code to disk, marshalling and writing the time stamp
static PyObject * getModuleCode(PythonQtImporter *self, const char *fullname, QString &modpath, QString &cachemodpath)
static void init()
initialize
static long getLong(unsigned char *buf)
static PyObject * getCodeFromPyc(const QString &file)
gets the compiled code for the given *.py file if there is a valid pyc file, otherwise compiles the f...
QString moduleName
the module name without the package prefix
QString fullPath
the full path to the found file
defines a python object that stores a Qt slot info
PyObject_HEAD QString * _path