Add lib2to3 fixer base code
Switching to using RedBaron instead of lib2to3, committing to save lib2to3 code in case using Baron is not successful.
This commit is contained in:
parent
9d64ff420f
commit
0b2556f3ec
4 changed files with 28 additions and 43 deletions
|
|
@ -1,30 +1,14 @@
|
|||
# from flask.ext import foo => import flask_foo as foo
|
||||
# from flask.ext.foo import bam => from flask_foo import bam
|
||||
# import flask.ext.foo => import flask_foo
|
||||
# CASE 1 - from flask.ext.foo import bam --> from flask_foo import bam
|
||||
# CASE 2 - from flask.ext import foo --> import flask_foo as foo
|
||||
|
||||
from redbaron import RedBaron
|
||||
import sys
|
||||
|
||||
|
||||
def migrate(old_file):
|
||||
new_file = open("temp.py", "w")
|
||||
for line in old_file:
|
||||
if line[0:14] == "from flask.ext":
|
||||
if line[14] == '.':
|
||||
import_statement = line[15::].split(' ')
|
||||
extension = import_statement[0]
|
||||
line = line.replace("flask.ext." + extension,
|
||||
"flask_" + extension)
|
||||
elif line[14] == " ":
|
||||
import_statement = line[15::].split(' ')[1]
|
||||
import_statement = import_statement.strip('\n')
|
||||
line = ("import flask_" +
|
||||
import_statement +
|
||||
" as " +
|
||||
import_statement)
|
||||
with open("test.py", "r") as source_code:
|
||||
red = RedBaron(source_code.read())
|
||||
|
||||
new_file.write(line)
|
||||
new_file.close()
|
||||
print red.dumps()
|
||||
|
||||
if __name__ == "__main__":
|
||||
old_file = open(sys.argv[1])
|
||||
migrate(old_file)
|
||||
# with open("code.py", "w") as source_code:
|
||||
# source_code.write(red.dumps())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue