-
Notifications
You must be signed in to change notification settings - Fork 0
/
imports.py
35 lines (27 loc) · 907 Bytes
/
imports.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
import os
class ImportManager:
def __init__(self,filePath) -> None:
self.modules = []
self.file = filePath
self.GetImports()
self.CheckImports()
def GetImports(self):
with open(self.file, "r") as f:
for line in f:
line = line.strip()
if line.startswith("import") or line.startswith("from"):
module = line.split()[1]
if not module in self.modules:
self.modules.append(module)
def CheckImports(self):
imp = ""
for module in self.modules:
imp+="import "+str(module)+"\n"
try:
exec(imp)
except Exception as importError:
print(f"[!] ImportManager error: {importError}")
os._exit(-1)
@property
def imports(self):
return self.modules