makeExe.py

  • Thread starter =?iso-8859-1?q?Premshree=20Pillai?=
  • Start date
?

=?iso-8859-1?q?Premshree=20Pillai?=

Wrote a simple Python script that makes life a wee bit
easier when using py2exe:

Also available at
http://premshree.resource-locator.com/python/makeExe.py

"""
makeExe.py
- Simple Python script to automate the creation
of Python executables using py2exe.

(c) 2004 Premshree Pillai (24/01/04)
http://www.qiksearch.com/
"""

## Run this file from Python root dir

import sys
import re

fileName = raw_input("Enter file name (rel or abs
path, eg., python/file.py): ")

package = re.split(":",fileName)
package = re.split("/",package[len(package) - 1])
package = re.split(".py",package[len(package) - 1])
package = package[0]

fp = open("setup.py","w")
temp = """from distutils.core import setup
import py2exe
setup(name = "%s",
scripts = ["%s"],
)""" % (package,fileName)
fp.write(temp)
fp.close()

sys.argv.append("py2exe")
execfile("setup.py")

fp = open("setup.py","w")
temp = ""
fp.write(temp)
fp.close()

print "\n", "Executable created!"
print "Press <enter> to exit..."
if(raw_input()):
exit


=====
-Premshree
[http://www.qiksearch.com/]

________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com
 
J

Josiah Carlson

package = re.split("/",package[len(package) - 1])
package = re.split(".py",package[len(package) - 1])

You'll find the readability increases when using:

package = re.split("/", package[-1])
package = re.split(".py", package[-1])

Negative indices are your friends.
- Josiah
 
P

Peter Hansen

Premshree said:
Wrote a simple Python script that makes life a wee bit
easier when using py2exe:

"""
makeExe.py
- Simple Python script to automate the creation
of Python executables using py2exe.
[snip]
fp = open("setup.py","w")
temp = """from distutils.core import setup
import py2exe
setup(name = "%s",
scripts = ["%s"],
)""" % (package,fileName)
fp.write(temp)
fp.close()

You could save yourself a fair bit of trouble, and avoid writing a
"setup.py" file to the filesystem (possibly overwriting an existing
one which might be important) by just calling the setup() method
directly yourself. The only trick is that it checks sys.argv[] for
the "py2exe" argument, so you have to fake that first:

sys.argv[1:] = ['py2exe']

from distutils.core import setup
setup(name=package,
scripts=[fileName])

That should do the trick.... if you're interested in integrating the
changes, and maintaining it, I'll forward our own script which you can
pull apart and reuse as required...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top