Browse Source

Early commit for issue #1135

Add support migrating single imports from the flask.ext style to flask_
pull/1342/head
Keyan Pishdadian 10 years ago
parent
commit
9d64ff420f
  1. 30
      scripts/flaskext_migrate.py
  2. 19
      scripts/temp.py
  3. 20
      scripts/test.txt

30
scripts/flaskext_migrate.py

@ -0,0 +1,30 @@
# 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
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)
new_file.write(line)
new_file.close()
if __name__ == "__main__":
old_file = open(sys.argv[1])
migrate(old_file)

19
scripts/temp.py

@ -0,0 +1,19 @@
from flask_foo import bam
import flask_foo as foo
def migrate(old_file):
new_file = open("temp.py", "w")
for line in old_file:
if line[0, 15] is "from flask.ext":
if line[15] == '.':
import_statement = line[16::].split(' ')
extension = import_statement[0]
line = line. replace("flask.ext." + extension,
"flask_" + extension)
else:
pass
new_file.write(line)
if __name__ == "__main__":
old_file = open(sys.arv[1])

20
scripts/test.txt

@ -0,0 +1,20 @@
from flask.ext.foo import bam
from flask.ext import foo
def migrate(old_file):
new_file = open("temp.py", "w")
for line in old_file:
if line[0, 15] is "from flask.ext":
if line[15] == '.':
import_statement = line[16::].split(' ')
extension = import_statement[0]
line = line. replace("flask.ext." + extension,
"flask_" + extension)
else:
pass
new_file.write(line)
if __name__ == "__main__":
old_file = open(sys.arv[1])
Loading…
Cancel
Save