You Are Here:

Community: Developer Discussion Boards

#1 Old Embedding .py/.pyd modules into a single .py file - 2007-01-26, 13:36

Join Date: Jan 2007
Posts: 21
Location: Spain
Skarabeus
Offline
Registered User
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.
Reply With Quote

#2 Old Re: Embedding .py/.pyd modules into a single .py file - 2007-01-26, 13:55

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
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/
Reply With Quote

#3 Old Re: Embedding .py/.pyd modules into a single .py file - 2007-08-19, 21:00

Join Date: Nov 2006
Posts: 502
neil.young
Offline
Super Contributor
Hi Skarabeus,

the link is broken. Do you have another link to download the script?

Regards
Reply With Quote

#4 Old Re: Embedding .py/.pyd modules into a single .py file - 2007-08-20, 10:27

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
Quote:
Originally Posted by neil.young View Post
Hi Skarabeus,

the link is broken. Do you have another link to download the script?

Regards
The link is broken but Skarabeus is the author of pyspy a sourceforgeproject and he is using boundmod in it 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()
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/
Reply With Quote

#5 Old Re: Embedding .py/.pyd modules into a single .py file - 2007-08-20, 10:38

Join Date: Nov 2006
Posts: 502
neil.young
Offline
Super Contributor
Thanks!
Regards
Reply With Quote

#6 Old Re: Embedding .py/.pyd modules into a single .py file - 2007-08-20, 11:26

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by cyke64 View Post
Code:

# Defaults
tmp_dir = "D:/system/temp/" # default dir for C extensions (PyS60)
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia