test_import.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/use/bin/python3
  2. import os
  3. import importlib
  4. # check all sourcefiles
  5. # if python module is indtalled
  6. cmd='grep -r -I "import " . | cut -d ":" -f 2-99 | sort | uniq ' #| sort -h | grep -v "from \|lib\|tkgui\|tksdl"'
  7. r=os.popen(cmd)
  8. data = {}
  9. for line in r.readlines():
  10. line = line.strip()
  11. if line.startswith("#"):
  12. continue
  13. #print(line)
  14. line = line.split()
  15. module = line[1]
  16. module = module.split(",")[0] #.replace(",","")
  17. module = module.replace(";","")
  18. if module.startswith("-"):
  19. continue
  20. if module.startswith("_"):
  21. continue
  22. if "." in module:
  23. continue
  24. if module.startswith("lib"):
  25. continue
  26. if "nodesca" in module:
  27. continue
  28. if module not in data:
  29. data[module] = []
  30. data[module].append(line)
  31. err = []
  32. ok = []
  33. for module in data:
  34. if importlib.util.find_spec(module):
  35. ok.append(module)
  36. else:
  37. err.append(module)
  38. print()
  39. ok.sort()
  40. err.sort()
  41. for i in ok:
  42. print((i +" OK").rjust(20," "))
  43. print()
  44. for i in err:
  45. #print(i,"ERR")
  46. print((i +" ERR").rjust(20," "))
  47. print("OK",len(ok),"ERR",len(err))
  48. print()
  49. #print(dir())