From NRCwikis
import sys
import os
def generate_project_stub(appUID, appName):
"""
Generates a directory with the project stub with the given name and UID.
"""
print "Making project directory: %s"%(appName)
os.mkdir(appName)
dataDir = appName + '/data'
groupDir = appName + '/group'
incDir = appName + '/inc'
srcDir = appName + '/src'
sisDir = appName + '/sis'
pythonDir = appName + '/python'
print "Making subdirectories"
print " "+dataDir
os.mkdir(dataDir)
print " "+groupDir
os.mkdir(groupDir)
print " "+incDir
os.mkdir(incDir)
print " "+srcDir
os.mkdir(srcDir)
print " "+sisDir
os.mkdir(sisDir)
print " "+pythonDir
os.mkdir(pythonDir)
mmpFile = groupDir + '/' + appName + '.mmp'
bldFile = groupDir + '/bld.inf'
pkgFile = sisDir + '/' + appName + '.pkg'
srcFile = srcDir +'/PythonWrappers.cpp'
pythonFile = pythonDir + '/' + appName + '.py'
print "Making stub files"
######################################################
print " "+mmpFile
fd = open(mmpFile, 'w')
fd.write(
"""
TARGET _%s.pyd
TARGETTYPE dll
TARGETPATH \\system\\libs
SYSTEMINCLUDE \\epoc32\\include \\epoc32\\include\\variant
SYSTEMINCLUDE \\epoc32\\include
SYSTEMINCLUDE \\epoc32\\include\\libc
SYSTEMINCLUDE \\epoc32\\include\\python
USERINCLUDE . ..\\inc
LIBRARY hal.lib
LIBRARY euser.lib
LIBRARY python222.lib
LIBRARY estlib.lib
CAPABILITY ReadUserData WriteUserData UserEnvironment LocalServices NetworkServices
NOSTRICTDEF
EXPORTUNFROZEN
EPOCALLOWDLLDATA
SOURCEPATH ..\\src
SOURCE PythonWrappers.cpp
"""
%(appName))
fd.close()
######################################################
######################################################
print " "+bldFile
fd = open(bldFile, 'w')
fd.write(
"""
PRJ_MMPFILES
%s.mmp
"""
%(appName))
fd.close()
#####################################################
#####################################################
print " "+pkgFile
fd = open(pkgFile, 'w')
fd.write(
"""&EN
#{\"%s\"},(%s),1,0,0, TYPE=SA
"""%(appName, appUID))
fd.write(
"""
"""+'%'+
"""{"Vendor-EN"}
:"Vendor"
[0x101F7961], 0, 0, 0, {\"S60ProductID\"}
"$(EPOCROOT)\\epoc32\\release\\$(PLATFORM)\\$(TARGET)\\_%s.pyd" -"!:\\sys\\bin\\_%s.pyd"
"..\\python\\%s.py"-"c:\\resource\\%s.py"
"""
%(appName, appName, appName, appName))
fd.close()
#####################################################
#####################################################
fd = open(srcFile, 'w')
fd.write("""
/**
* %s.cpp
*
* Copyright Nokia
* 2007
*/"""%(appName))
fd.write("""
#include <Python.h>
#include <symbian_python_ext_util.h>
/*
* Make a table of the module's exported methods.
* Add your methods here.
*/
static const PyMethodDef %s_methods[] = {
{0, 0} // sentinel
};
/**
* Finish setting up the types we need.
* Export the methods into a python module.
*/
DL_EXPORT(void) init_%s() {
PyObject* module = Py_InitModule("_%s", (PyMethodDef*) %s_methods);
if (!module) return;
}
/**
* Magic made a dll woodoo.
*/
#ifndef EKA2
GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}
#endif
"""%(appName, appName, appName, appName))
fd.close()
#####################################################
#####################################################
fd = open(pythonFile, 'w')
fd.write("""
import imp
# Load the dll. This step will fail if signing permissions don't match up.
_%s=imp.load_dynamic('_%s', 'c:\\\\sys\\\\bin\\\\_%s.pyd')
#remove unnecessary names from namespace
del imp
# pull entire c module namespace into this one
from _%s import *
"""%(appName, appName, appName, appName))
fd.close()
if __name__ == '__main__':
try:
appUID = sys.argv[1];
appName = sys.argv[2];
except:
print "Usage: make_dll_stub.py UID name"
generate_project_stub(appUID, appName)