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