667a455c46e25be1dcfd42d86e3d9c26e86e96d6 — Emil Oppeln-Bronikowski 3 months ago 9269565
I confused myself, better start tomorrow
1 files changed, 23 insertions(+), 9 deletions(-)

M __main__.py
M __main__.py => __main__.py +23 -9
@@ 25,12 25,24 @@ return True
      return False
  
+ def has_use(line: str) -> bool:
+     if 'use' in line:
+         return True
+     return False
+ 
  def extract_namespace(line: str) -> list:
  
      elements = line[line.find("\\"):].split("\\")
-     class_element = elements[-1:]
+     org_class_element = elements[-1:][0]
+ 
+     if '::' in org_class_element:
+         class_element = org_class_element.split('::')[0]
+     else:
+         class_element = org_class_element
+ 
+     elements[len(elements)-1] = class_element
  
-     return("\\".join(elements[:-1]), elements[-1:])
+     return("\\".join(elements), org_class_element)
  
  
  def test_bool_call(func, param):


@@ 46,16 58,18 @@ return use
  
  
- def main():
+ def main(file_path: str):
  
      namespaces = []
-     for line in examples:
-         if is_line_namespaced(line) and not is_slash_quoted(line):
-             path, class_element = extract_namespace(line)
-             namespaces.append(path)
-             print(line.replace(path, "").replace("\\", ""))
+     with open(file_path, 'r') as f:
+         for line in f.readlines():
+             if is_line_namespaced(line) and not is_slash_quoted(line) and has_use(line):
+                 path, class_element = extract_namespace(line)
+                 namespaces.append(path)
+                 print("{}\n{}".format(line, line.replace(path[:-1], "").replace("\\", "")))
  
      print(set(namespaces))
      print(return_import_statements(set(namespaces)))
  
- main()
+ if len(sys.argv) == 2:
+     main(sys.argv[1])