-
Notifications
You must be signed in to change notification settings - Fork 0
/
expansion.py
35 lines (29 loc) · 917 Bytes
/
expansion.py
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
import os
import sys
def main(input_file, output_file):
with open(output_file, "w") as f:
se = set()
def dfs(path):
filename = "/".join(path)
if not os.path.exists(filename):
return False
if filename in se:
return True
se.add(filename)
path.pop()
with open(filename, "r") as f2:
for row in f2:
if row[:4] == "from":
P = row.split()[1].split(".")
P[-1] += ".py"
if not dfs(P):
f.write(row)
else:
f.write(row)
return True
path = input_file.split("/")
dfs(path)
if __name__ == "__main__":
input_file = sys.argv[1]
output_file = sys.argv[2]
main(input_file, output_file)