]>
Commit | Line | Data |
---|---|---|
1fded56b RD |
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 | __cvsid__ = \"\x24Id: \x24\" | |
25 | __revision__ = \"\x24Revision: \x24\"[11:-2] | |
26 | ||
27 | from wx import _rename | |
28 | from wxPython%(prefix)s import %(suffix)s | |
29 | _rename(globals(), %(suffix)s.__dict__, modulename='%(name)s') | |
30 | del %(suffix)s | |
31 | del _rename | |
32 | """ | |
33 | ||
34 | wxPython_dir = "../wxPython" | |
35 | ||
36 | subpackage_list = ['.', | |
37 | 'lib', 'lib/mixins', 'lib/editor', 'lib/colourchooser', | |
38 | 'py', | |
39 | 'tools', 'tools/XRCed', | |
40 | ] | |
41 | ||
42 | skip_modules = [ '__init__', '__version__', | |
43 | 'wx', 'windows', 'windows2', 'windows3', 'events', 'fonts', 'misc', | |
44 | 'misc2', 'gdi', 'mdi', 'controls', 'controls2', 'cmndlgs', | |
45 | 'stattool', 'frames', 'image', 'printfw', 'sizers', 'clip_dnd', | |
46 | 'filesys', 'streams', 'htmlhelp', 'oglbasic', 'oglshapes', | |
47 | 'oglshapes2', 'oglcanvas', 'stc_', 'utils', 'dllwidget_', | |
48 | ||
49 | 'PyAlaModeTest', | |
50 | ] | |
51 | ||
52 | ||
53 | ||
54 | ||
55 | ||
56 | # Check for command-line arg | |
57 | if len(sys.argv) > 1: | |
58 | wxPython_dir = sys.argv[1] | |
59 | ||
60 | # check wxPython_dir | |
61 | if not os.path.exists(wxPython_dir) or not os.path.isdir(wxPython_dir): | |
62 | print wxPython_dir, "does not exist or is not a directory!" | |
63 | sys.exit() | |
64 | ||
65 | # check current location | |
66 | if os.path.basename(os.getcwd()) <> 'wx': | |
67 | print 'This must be run from inside the target "wx" directory' | |
68 | sys.exit() | |
69 | ||
70 | ||
71 | # build the modules and subpackages as needed | |
72 | for subdir in subpackage_list: | |
73 | # create subdir if needed | |
74 | if not os.path.exists(subdir): | |
75 | os.mkdir(subdir) | |
76 | ||
77 | # create __init__.py if needed | |
78 | if os.path.isdir(subdir): | |
79 | fname = os.path.join(subdir, '__init__.py') | |
80 | if not os.path.exists(fname): | |
81 | f = open(fname, 'w') | |
82 | f.write("# Python package\n") | |
83 | f.close() | |
84 | else: | |
85 | print subdir + 'exists but is not a directory' | |
86 | sys.exit() | |
87 | ||
88 | # find the .py files there and make renamer stubs for them here | |
89 | src = os.path.join(wxPython_dir, subdir, "*.py") | |
90 | for srcname in glob.glob(src): | |
91 | suffix = os.path.splitext(os.path.basename(srcname))[0] | |
92 | if suffix in skip_modules: | |
93 | continue | |
94 | prefix = subdir.replace('/', '.') | |
95 | if prefix == '.': | |
96 | prefix = '' | |
97 | name = suffix | |
98 | else: | |
99 | name = prefix + '.' + suffix | |
100 | prefix = '.' + prefix | |
101 | ||
102 | fname = os.path.join(subdir, suffix+".py") | |
103 | ||
104 | content = wxmodule_template % globals() | |
105 | f = open(fname, 'w') | |
106 | f.write(content) | |
107 | f.close() | |
108 | print fname + ' created' | |
109 | ||
110 | ||
111 | ||
112 | sys.exit() | |
113 | ||
114 | ||
115 | ||
116 |