1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
"""
wx_create.py
Originally written by David Hughes <dfh@forestfield.co.uk>
Massivly hacked by Robin Dunn
This automatically creates all the stub modules that are required in
the wx package in addition to __init__.py
The module names to make stubs for are found by scanning the wxPython
package directory. The default directory searched is ../wxPython, but
you can specify a different one on the command-line if needed.
The content of each module (.py file) is taken from wxmodule_template
with appropriate substitution of the %name% tokens
"""
import os, sys, glob
wxmodule_template = """
\"\"\"Renamer stub: provides a way to drop the wx prefix from wxPython objects.\"\"\"
from wx import _rename
from wxPython%(prefix)s import %(suffix)s
_rename(globals(), %(suffix)s.__dict__, modulename='%(name)s')
del %(suffix)s
del _rename
"""
call_main = """
if __name__ == '__main__':
main()
"""
wxPython_dir = "../wxPython"
subpackage_list = ['.',
'lib', 'lib/mixins', 'lib/editor', 'lib/colourchooser',
'py',
'tools', 'tools/XRCed',
]
skip_modules = [ '__init__', '__version__',
'wx', 'windows', 'windows2', 'windows3', 'events', 'fonts', 'misc',
'misc2', 'gdi', 'mdi', 'controls', 'controls2', 'cmndlgs',
'stattool', 'frames', 'image', 'printfw', 'sizers', 'clip_dnd',
'filesys', 'streams', 'htmlhelp', 'oglbasic', 'oglshapes',
'oglshapes2', 'oglcanvas', 'stc_', 'utils', 'dllwidget_',
'PyAlaModeTest',
]
add_call_main = ['py/PyAlaCarte.py', 'py/PyAlaMode.py', 'py/PyCrust.py',
'py/PyFilling.py', 'py/PyShell.py', 'py/PyWrap.py'
]
# Check for command-line arg
if len(sys.argv) > 1:
wxPython_dir = sys.argv[1]
# check wxPython_dir
if not os.path.exists(wxPython_dir) or not os.path.isdir(wxPython_dir):
print wxPython_dir, "does not exist or is not a directory!"
sys.exit()
# check current location
if os.path.basename(os.getcwd()) <> 'wx':
print 'This must be run from inside the target "wx" directory'
sys.exit()
# build the modules and subpackages as needed
for subdir in subpackage_list:
# create subdir if needed
if not os.path.exists(subdir):
os.mkdir(subdir)
# create __init__.py if needed
if os.path.isdir(subdir):
fname = os.path.join(subdir, '__init__.py')
if not os.path.exists(fname):
f = open(fname, 'w')
f.write("# Python package\n")
f.close()
else:
print subdir + 'exists but is not a directory'
sys.exit()
# find the .py files there and make renamer stubs for them here
src = os.path.join(wxPython_dir, subdir, "*.py")
for srcname in glob.glob(src):
suffix = os.path.splitext(os.path.basename(srcname))[0]
if suffix in skip_modules:
continue
prefix = subdir.replace('/', '.')
if prefix == '.':
prefix = ''
name = suffix
else:
name = prefix + '.' + suffix
prefix = '.' + prefix
fname = os.path.join(subdir, suffix+".py")
content = wxmodule_template % globals()
f = open(fname, 'w')
f.write(content)
if fname in add_call_main:
f.write(call_main)
f.close()
print fname + ' created'
sys.exit()
|