[Pymoul-svn] SF.net SVN: pymoul: [58] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-23 11:06:59
|
Revision: 58
http://pymoul.svn.sourceforge.net/pymoul/?rev=58&view=rev
Author: tiran
Date: 2007-01-23 03:06:58 -0800 (Tue, 23 Jan 2007)
Log Message:
-----------
Renamed misc to contrib
Added distutils_upx file with UpxCommand class
Fixed typo in config.darwin
Added epydoc support doc Makefile
Modified Paths:
--------------
pymoul/trunk/Makefile
pymoul/trunk/setup.py
pymoul/trunk/setup_win32.py
pymoul/trunk/src/moul/config/darwin.py
Added Paths:
-----------
pymoul/trunk/contrib/
pymoul/trunk/distutils_upx.py
pymoul/trunk/doc/
Removed Paths:
-------------
pymoul/trunk/misc/
Modified: pymoul/trunk/Makefile
===================================================================
--- pymoul/trunk/Makefile 2007-01-22 19:09:49 UTC (rev 57)
+++ pymoul/trunk/Makefile 2007-01-23 11:06:58 UTC (rev 58)
@@ -1,4 +1,5 @@
-PYTHON?=python2.5
+PYTHON?=python
+EPYDOC=$(PYTHON) -c "import epydoc.cli; epydoc.cli.cli()"
TESTFLAGS=-v
TESTOPTS=
SETUPFLAGS=
@@ -7,16 +8,16 @@
# Build in-place
inplace:
- $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i
+ PYTHONPATH="src" $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i
build: compileui
- $(PYTHON) setup.py $(SETUPFLAGS) build
+ PYTHONPATH="src" $(PYTHON) setup.py $(SETUPFLAGS) build
py2exe:
- $(PYTHON) setup.py $(SETUPFLAGS) py2exe
+ PYTHONPATH="src" $(PYTHON) setup.py $(SETUPFLAGS) py2exe
bdist_egg:
- $(PYTHON) setup.py $(SETUPFLAGS) bdist_egg
+ PYTHONPATH="src" $(PYTHON) setup.py $(SETUPFLAGS) bdist_egg
run: compileui
PYTHONPATH="src" $(PYTHON) src/moul/qt/moulqt.py
@@ -30,6 +31,9 @@
test_inplace: compileui
PYTHONPATH="src" $(PYTHON) test.py $(TESTFLAGS) $(TESTOPTS)
+doc_html:
+ PYTHONPATH="src" $(EPYDOC) -v --html --output="doc/html" moul
+
# What should the default be?
test: test_inplace
Copied: pymoul/trunk/contrib (from rev 57, pymoul/trunk/misc)
Added: pymoul/trunk/distutils_upx.py
===================================================================
--- pymoul/trunk/distutils_upx.py (rev 0)
+++ pymoul/trunk/distutils_upx.py 2007-01-23 11:06:58 UTC (rev 58)
@@ -0,0 +1,130 @@
+"""Patched distutils Command
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id"
+__revision__ = "$Revision$"
+
+import os
+import sys
+from inspect import getmro
+from tempfile import TemporaryFile
+from subprocess import call
+from distutils import log
+from stat import ST_SIZE
+
+def inEnvPath(name):
+ result = []
+ for path in os.environ['PATH'].split(';'):
+ upx = os.path.join(path, name)
+ if os.path.isfile(upx):
+ result.append(upx)
+ if result:
+ return result[0]
+
+def _call(cmd, silent=False, *args, **kwargs):
+ """Call silently - redirect stdout to dump
+ """
+ data = None
+ if silent:
+ stdout = TemporaryFile()
+ else:
+ stdout = None
+ try:
+ retcode = call(cmd, stdout=stdout, *args, **kwargs)
+ finally:
+ if stdout:
+ data = stdout.read()
+ stdout.close()
+ return retcode, data
+
+def _has_upx(upx):
+ """Search for UPX in search path
+ """
+ try:
+ retcode, stdout = _call("%s --version" % upx, silent=True)
+ except OSError:
+ log.debug('UPX not found')
+ return False
+ else:
+ if retcode == 0:
+ log.debug('UPX found')
+ return True
+ else:
+ log.debug('UPX: an error occured %i' % retcode)
+ return False
+
+def _upx_compress(upx, args, fname):
+ """Check file
+ """
+ retcode, stdout = _call('upx %s "%s"' % (args, fname), silent=False)
+ if retcode == 0: # file packed
+ pass
+ elif retcode == 2: # file already packed
+ pass
+ else: # something bad has happend
+ sys.exit(retcode)
+
+def otherclass(mycls):
+ for cls in getmro(mycls):
+ if not issubclass(cls, UpxCommand):
+ return cls
+ raise ValueError(mycls)
+
+class UpxCommand:
+ def initialize_options(self):
+ result = otherclass(self.__class__).initialize_options(self)
+ self.upx = True
+ self.upx_args = '--no-color --best'
+ self.upx_path = 'upx'
+ self.upx_extensions = (
+ 'pyd', 'dll', 'exe', # Windows
+ '', 'so', # Linux
+ 'dylib', # Mac OS X
+ )
+ return result
+
+ def finalize_options(self):
+ result = otherclass(self.__class__).finalize_options(self)
+ self.has_upx = _has_upx(self.upx_path)
+ self.upx_packed = []
+ return result
+
+ def copy_file(self, *args, **kwargs):
+ # Override to UPX copied binaries.
+ result = otherclass(self.__class__).copy_file(self, *args, **kwargs)
+ self._upx_compress(result)
+ return result
+
+ def _upx_compress(self, result):
+ fname, copied = result
+ if not self.has_upx or not self.upx or not copied:
+ return
+
+ basename = os.path.basename(fname)
+ tmp, ext = os.path.splitext(basename)
+ ext = ext[1:] # strip leading dot
+ origsize = os.stat(fname)[ST_SIZE]
+ if ext in self.upx_extensions:
+ _upx_compress(self.upx_path, self.upx_args, os.path.normpath(fname))
+ newsize = os.stat(fname)[ST_SIZE]
+ ratio = newsize*100 / origsize
+ self.upx_packed.append((basename, origsize, newsize, ratio))
+ return result
+
+ def run(self, *args, **kwargs):
+ result = otherclass(self.__class__).run(self, *args, **kwargs)
+ if self.has_upx and self.upx:
+ print "\n*** UPX result ***"
+ for basename, origsize, newsize, ratio in self.upx_packed:
+ print " %s packed to %i%%" % (basename, ratio)
+ print "\n"
+ return result
+
+
+try:
+ from py2exe.build_exe import py2exe
+except ImportError:
+ pass
+else:
+ class UpxPy2exe(UpxCommand, py2exe):
+ pass
Property changes on: pymoul/trunk/distutils_upx.py
___________________________________________________________________
Name: svn:eol-style
+ native
Property changes on: pymoul/trunk/doc
___________________________________________________________________
Name: svn:ignore
+ html
Modified: pymoul/trunk/setup.py
===================================================================
--- pymoul/trunk/setup.py 2007-01-22 19:09:49 UTC (rev 57)
+++ pymoul/trunk/setup.py 2007-01-23 11:06:58 UTC (rev 58)
@@ -23,6 +23,7 @@
# import the rest
from setuptools import setup
from setuptools import find_packages
+
from compileui import compileUi
VERSION = "0.0"
@@ -93,14 +94,9 @@
if sys.platform.startswith('win32'):
from setup_win32 import updateSetupOptions
from setup_win32 import updateSetupOptionsQT
- from setup_win32 import upxPack
updateSetupOptions(kwargs)
updateSetupOptionsQT(kwargs)
elif sys.platform.startswith('linux2'):
kwargs['packages'].append('moul.qt')
setup(**kwargs)
-
-if sys.platform.startswith('win') and 'py2exe' in sys.argv:
- pass
- upxPack('dist')
Modified: pymoul/trunk/setup_win32.py
===================================================================
--- pymoul/trunk/setup_win32.py 2007-01-22 19:09:49 UTC (rev 57)
+++ pymoul/trunk/setup_win32.py 2007-01-23 11:06:58 UTC (rev 58)
@@ -12,8 +12,11 @@
import py2exe
except ImportError:
print >>sys.stderr, "py2exe missing, unable to create executables"
+ cmdclass = {}
else:
# If run without args, build executables, in quiet mode.
+ from distutils_upx import UpxPy2exe
+ cmdclass = {'py2exe': UpxPy2exe}
if len(sys.argv) == 1:
sys.argv.append("py2exe")
@@ -50,31 +53,8 @@
# packages = ['pytz.%s.*' % pack for pack in packages]
# return packages
-def inEnvPath(name):
- result = []
- for path in os.environ['PATH'].split(';'):
- upx = os.path.join(path, name)
- if os.path.isfile(upx):
- result.append(upx)
- if result:
- return result[0]
-
-def upxPack(dst):
- """Pack PE executables with UPX http://upx.sourceforge.net/
-
- UPX can shrink dll, exe and pyd files 50 to 70% without disadvantage
- """
- if not inEnvPath('upx.exe'):
- print >>sys.stderr, "UPX not available - skipping"
- upx_pack = []
- for root, dirs, files in os.walk(dst):
- for file in files:
- if file[-4:] in ('.pyd', '.dll', '.exe'):
- upx_pack.append(os.path.join(root, file))
- # --best --all-methods --all-filters
- os.system("upx -q --mono %s" % ' '.join(upx_pack))
-
def updateSetupOptions(kw):
+ kw['cmdclass'] = cmdclass
for req in ("py2exe >=0.6.5",):
kw['setup_requires'].append(req)
for req in ():
Modified: pymoul/trunk/src/moul/config/darwin.py
===================================================================
--- pymoul/trunk/src/moul/config/darwin.py 2007-01-22 19:09:49 UTC (rev 57)
+++ pymoul/trunk/src/moul/config/darwin.py 2007-01-23 11:06:58 UTC (rev 58)
@@ -30,7 +30,7 @@
MOUL_DIR = "Uru Live"
INI_FILE = ('pyMoul', 'pymoul.ini')
EXEC_NAME = "UruLauncher"
-HOME = os.environ('HOME')
+HOME = os.environ['HOME']
def getMoulUserDataDir():
"""Get path of MOUL data directory
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|