SourceForge.net Logo
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 "structmember.h"
48 #include "osdefs.h"
49 #include "marshal.h"
50 #include "compile.h"
51 #include <time.h>
52 
53 #include <qobject.h>
54 #include <qstring.h>
55 
56 
58 typedef struct _PythonQtImporter {
59  PyObject_HEAD
60  QString* _path;
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 
112  static PyObject * getModuleCode(PythonQtImporter *self,
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 
138  static QString getCacheFilename(const QString& sourceFile, bool isOptimizedFilename);
139 
142  static QString getSourceFilename(const QString& cacheFile);
143 };
144 
145 #endif
146 
struct _PythonQtImporter PythonQtImporter
defines a python object that stores a Qt slot info
static void init()
initialize
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...
static time_t getMTimeOfSource(const QString &path)
get time stamp of file
defines a python object that stores a Qt slot info
static PyObject * getModuleCode(PythonQtImporter *self, const char *fullname, QString &modpath, QString &cachemodpath)
PyObject_HEAD QString * _path
static QString getSourceFilename(const QString &cacheFile)
static PyObject * unmarshalCode(const QString &path, const QByteArray &data, time_t mtime)
struct _object PyObject
static PyObject * compileSource(const QString &path, const QByteArray &data)
static QString getCacheFilename(const QString &sourceFile, bool isOptimizedFilename)
static ModuleInfo getModuleInfo(PythonQtImporter *self, const QString &fullname)
Return if module exists and is a package or a module.
static QString replaceExtension(const QString &str, const QString &ext)
replace extension of file
static PyObject * getCodeFromData(const QString &path, int isbytecode=0, int ispackage=0, time_t mtime=0)
QString fullPath
the full path to the found file
static long getLong(unsigned char *buf)
implements importing of python files into PythonQt
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 QString getSubName(const QString &str)
get the last name of a dot chain (first.second.last)
QString moduleName
the module name without the package prefix