-
Notifications
You must be signed in to change notification settings - Fork 1
/
3to2
executable file
·42 lines (36 loc) · 1009 Bytes
/
3to2
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
#!/bin/sh
# This file fixes MINOR issues so that Python 2.x compatible Python 3.x code
# will potentially compile with the ShedSkin C++ cross-compiler.
find "${1:-usage: ./3to2 <dir>}" -iname "*.py" \
| \
while IFS="" read -r py_file; do
# Change:
# try:
# python_2_operations()
# except:
# python_3_operations()
# To:
# # try:
# python_2_operations()
# # except:
# # python_3_operations()
awk '/^try/,/^except/ {
$0="# " $0;
gsub("^# ", "", $0)
} /^# except/,/^$/ {
$0="# " $0;
gsub("^# # ", "# ", $0);
gsub("^# $", "", $0)
} {
print
}' "$py_file" > "${py_file}.edit"
# Change:
# from . import stuff
# from .file import more_stuff
# To:
# import stuff
# from file import more_stuff
sed 's/from \. //g' "${py_file}.edit" \
| sed 's/from \./from /g' > "$py_file"
rm -f "${py_file}.edit"
done