-
Notifications
You must be signed in to change notification settings - Fork 4
/
ets3to4.py
executable file
·126 lines (110 loc) · 4 KB
/
ets3to4.py
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
124
125
126
"""
updates ETS imports to avoid proxy
"""
import sys
import os
from os.path import abspath, isdir, join
# Please note that the order of items in this list matters.
MAP = [
# pyface
('enthought.pyface', 'pyface'),
('enthought.qt', 'pyface.qt'),
('enthought.resource', 'pyface.resource'),
('enthought.util.guisupport', 'pyface.util.guisupport'),
('enthought.util.wx', 'pyface.wx'),
# traitsui
('enthought.traits.ui', 'traitsui'),
# traits
('enthought.traits', 'traits'),
('enthought.etsconfig', 'traits.etsconfig'),
('enthought.util', 'traits.util'),
('enthought.testing', 'traits.testing'),
# enable
('enthought.enable', 'enable'),
('enthought.kiva', 'kiva'),
('enthought.savage', 'enable.savage'),
# chaco
('enthought.chaco', 'chaco'),
# envisage
('enthought.envisage', 'envisage'),
('enthought.plugins', 'envisage.plugins'),
# graphcanvas
('enthought.graphcanvas', 'graphcanvas'),
# scimath
('enthought.interpolate', 'scimath.interpolate'),
('enthought.physical_quantities', 'scimath.physical_quantities'),
('enthought.mathematics', 'scimath.mathematics'),
('enthought.units', 'scimath.units'),
# blockcanvas
('enthought.block_canvas', 'blockcanvas'),
('enthought.greenlet', 'blockcanvas.greenlet'),
('enthought.numerical_modeling', 'blockcanvas.numerical_modeling'),
('enthought.model', 'blockcanvas.model'),
# codetools
('enthought.blocks', 'codetools.blocks'),
('enthought.blocks2', 'codetools.blocks2'),
('enthought.contexts', 'codetools.contexts'),
('enthought.execution', 'codetools.execution'),
# etsdevtools
('enthought.debug', 'etsdevtools.debug'),
('enthought.developer', 'etsdevtools.developer'),
('enthought.endo', 'etsdevtools.endo'),
# apptools
('enthought.appscripting', 'apptools.appscripting'),
('enthought.help', 'apptools.help'),
('enthought.io', 'apptools.io'),
('enthought.logger', 'apptools.logger'),
('enthought.naming', 'apptools.naming'),
('enthought.permissions', 'apptools.permissions'),
('enthought.persistence', 'apptools.persistence'),
('enthought.preferences', 'apptools.preferences'),
('enthought.scripting', 'apptools.scripting'),
('enthought.sweet_pickle', 'apptools.sweet_pickle'),
('enthought.template', 'apptools.template'),
('enthought.type_manager', 'apptools.type_manager'),
('enthought.undo', 'apptools.undo'),
# mayavi
('enthought.mayavi', 'mayavi'),
('enthought.tvtk', 'tvtk'),
]
def update_file(path):
fi = open(path)
data = fi.read()
fi.close()
orig_data = data
for old, new in MAP:
data = data.replace(old, new)
if data == orig_data:
return
print 'rewriting', path
fo = open(path, 'w')
fo.write(data)
fo.close()
def help():
print """usage: ets3to4 DIRECTORY
This utility, can be used to convert projects from ETS version 3 to 4.
It simply replaces old namespace strings (e.g. 'enthought.traits.api')
to new ones (e.g. 'traits.api'), in all Python files in DIRECTORY
recursively.
Once the conversion of your project is complete, the etsproxy module
should no longer be necessary. However, this tool is very simple and
does not catch all corner cases.
"""
sys.exit()
def main():
if '-h' in sys.argv or '--help' in sys.argv:
help()
if len(sys.argv) != 2:
sys.exit('Error: exactly one argument required, try -h')
dir_path = sys.argv[1]
if not isdir(dir_path):
sys.exit('Error: not a directory: %s' % dir_path)
for root, dirs, files in os.walk(dir_path):
parts = root.split(os.sep)
if '.git' in parts or '.svn' in parts or '.hg' in parts:
continue
for fn in files:
if fn.endswith('.py')&(not fn.endswith('ets3to4.py')):
update_file(join(root, fn))
if __name__ == '__main__':
main()