| Reply | « Previous Thread | Next Thread » |
|
Hello.
I write this little script for embed py/pyd modules into a single .py file. Here is a beta version: http://coyote.diselpro.com/boundmod.zip For example, you can embed smtplib.py, hmac.py (needed for smtplib) and miso.pyd in a single .py file. Bye. |
|
It seems very interesting
Regards Cyke64 pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 ! pys60 extension modules on http://cyke64.googlepages.com/ |
|
Hi Skarabeus,
the link is broken. Do you have another link to download the script? Regards |
| neil.young |
| View Public Profile |
| Find all posts by neil.young |
|
Quote:
So I download it from the svn repository ![]() Here's what you want : Code:
#! /usr/bin/python
# Script for embed python modules (.py/.pyd)
#
# boundmod.py is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation
#
# Author: Pepe Aracil
# Send questions to: pepe@diselpro.com
#
# Tips:
# the module file name must match module name, since
# module name is extracted from file name.
# exaples:
# mod. name mod. file name stat.
# ========= ============== =====
# keypress keypress.pyd OK
# keypress KEYPRESS.PYD WRONG!
# StringIO StringIO.py OK
# StringIO stringio.py WRONG!
import sys
import zlib
from os.path import *
# Defaults
tmp_dir = "D:/system/temp/" # default dir for C extensions (PyS60)
if len(sys.argv) < 4:
print """
boundmod.py is a tool for embed python modules (.py) or C extensions (.pyd)
into a single python source file.
Usage:
boundmod.py out_script main_script module [module ...]
"""
sys.exit(0)
# Script args.
output = sys.argv[1]
main = sys.argv[2]
modules = sys.argv[3:]
of = file(output,"w")
of.write("""#! /usr/bin/python
def inline_module_py(str_module,name):
import sys
from zlib import decompress
from imp import new_module
tmp_module = new_module(name)
exec decompress(str_module.decode("base64")) in tmp_module.__dict__
if not name in sys.modules: sys.modules[name] = tmp_module
def inline_module_pyd(str_module,name,tmp_path):
from os import unlink
from zlib import decompress
from imp import find_module, load_module
tmp_file = file("%s/%s.pyd" % (tmp_path,name),"wb")
tmp_file.write(decompress(str_module.decode("base64")))
tmp_file.close()
r = find_module(name,[tmp_path])
load_module(name,*r)
r[0].close()
unlink("%s/%s.pyd" % (tmp_path,name))
""")
for mo in modules:
mo_name, mo_ext = splitext(basename(mo))
c_ext = (mo_ext.lower() == ".pyd")
mf = file(mo,"r")
tmp = zlib.compress(mf.read()).encode("base64")
mf.close()
of.write("""\n### Start of embedded module %s ###\n""" % mo_name)
of.write("str_module = '''%s'''\n" % tmp)
if not c_ext:
of.write("""inline_module_py(str_module,"%s")\n""" % mo_name)
else:
of.write("""inline_module_pyd(str_module,"%s","%s")\n""" % (mo_name,tmp_dir))
of.write("""### End of embedded moduled %s ###\n""" % mo_name)
of.write("""\ndel(str_module,inline_module_py,inline_module_pyd)\n\n""")
of.write("""### Start of main script ###\n""")
mf = file(main,"r")
of.write(mf.read())
mf.close()
of.close()
Cyke64 pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 ! pys60 extension modules on http://cyke64.googlepages.com/ |
|
Thanks!
Regards |
| neil.young |
| View Public Profile |
| Find all posts by neil.young |
|
Before anyone using a 3rd Edition phone wastes any time on this, no, it will not be possible to do this under 3rd Edition. Platform security dictates that any EXEs and DLLs are only allowed under \sys\bin. PYDs are actually DLLs and the \sys\bin directory is not writable from user applications. For pure Python modules it should work, however.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Multiple programs within single SIS file dilema | LongSteve | General Symbian C++ | 6 | 2008-03-20 07:05 |
| Compile single file (like Ctrl-F7 in Carbide.vs) | zdenko | Carbide.c++ IDE and plug-ins | 1 | 2006-12-19 17:57 |
| Saving data but not in a single file, the Symbian way? | Kaali | General Symbian C++ | 2 | 2006-10-04 20:41 |
| What is the error in my code here? Unable to Save document to file | yuva69 | General Symbian C++ | 1 | 2005-05-26 15:22 |
| how to extract multiple images from Single Image File | memphis_ | Mobile Java General | 2 | 1970-01-01 02:00 |