mirror of https://github.com/mitsuhiko/flask.git
Browse Source
Add support migrating single imports from the flask.ext style to flask_pull/1342/head
Keyan Pishdadian
10 years ago
3 changed files with 69 additions and 0 deletions
@ -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) |
@ -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]) |
@ -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…
Reference in new issue