2020-07-09 22:20:38 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
filename_in = sys.argv[1]
|
|
|
|
filename_out = sys.argv[2]
|
|
|
|
file_in = open(filename_in, "r")
|
2020-07-09 23:15:08 +00:00
|
|
|
lines = file_in.readlines()
|
2020-07-09 22:20:38 +00:00
|
|
|
file_out = open(filename_out, "w")
|
|
|
|
|
|
|
|
imports = set()
|
|
|
|
|
|
|
|
for line in lines:
|
2020-07-09 23:15:08 +00:00
|
|
|
match1 = re.search(r"(from *(?!\.)(.+?)(?= |\.))", line)
|
|
|
|
match2 = re.search(r"(: *(import) (.+))", line)
|
2020-07-09 22:20:38 +00:00
|
|
|
if match1 is not None:
|
|
|
|
imports.add(match1.group(2))
|
|
|
|
if match2 is not None:
|
|
|
|
imports.add(match2.group(3))
|
|
|
|
|
|
|
|
|
|
|
|
for imp in sorted(list(imports)):
|
|
|
|
file_out.write(f"{imp}\n")
|