Advertisement
here2share

# modules_plus.py

Jul 28th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. # modules_plus.py
  2.  
  3. import os, sys, imp, inspect
  4.  
  5. print '\nSeaching for modules, this might take a short while...\n\n'
  6.  
  7. try:
  8.     import distutils.sysconfig
  9.     std_lib = distutils.sysconfig.get_python_lib(standard_lib=True)
  10. except: std_lib=0
  11.  
  12. t = []
  13. if std_lib:
  14.     for top, dirs, files in os.walk(std_lib):
  15.         for fn in files:
  16.             x='.'.join(fn.split('.')[:-1])
  17.             try:
  18.                 if x not in t and not x[0].isdigit():
  19.                     t.append(x)
  20.             except: pass
  21.  
  22. def SaveText(txt, filename = 'demo', target = 'tmp\\', folder = 'python\\', dir = u'E:\\'):
  23.     try:
  24.         os.mkdir(dir+folder+target)
  25.         print "\n\nNew Folder Has Been Added..."
  26.     except: pass
  27.     saveas = dir+folder+target+filename+'.txt'
  28.     f = open(saveas,"w")
  29.     f.write(txt)
  30.     f.close()
  31.     print '\n\nSaved As...\n', saveas
  32. #
  33.  
  34. def B(zzz):
  35.     for z in zzz:
  36.         if z not in t:
  37.             t.append(z)
  38. B(dir('keyword'))
  39. B(dir('import'))
  40. B(dir('modules package'))
  41. B(dir(__builtins__))
  42. B(sys.builtin_module_names)
  43. B(sys.modules)
  44. B(sys.modules.keys())
  45. try: B(dir(__package__))
  46. except: pass
  47.  
  48. m = []
  49. v = []
  50. from pkgutil import iter_modules
  51. for z in iter_modules():
  52.     z=str(z)
  53.     if not v: v = z.split()[3]
  54.     try:
  55.         if v not in z:
  56.             x = z.split()[-2][1:-2]
  57.             if x not in t+m: m.append(x)
  58.     except: pass
  59.  
  60. m.sort()
  61. t.sort()
  62.  
  63. ttt = []
  64. skip = ['antigravity','test','idle']
  65. print
  66. for z in t:
  67.     try:
  68.         imp.find_module(z)
  69.         ttt.append(z)
  70.         if z not in skip:
  71.             mods = dir(__import__(z))
  72.             if '_main_' in z:
  73.                 mods = ['*** Current Attributes ***']
  74.             for mod in mods:
  75.                 ttt.append(('    +++ '+mod))
  76.                
  77.                 try:
  78.                     x = inspect.getmoduleinfo(mod)
  79.                     if x: ttt.append('    --- '+x)
  80.                 except: pass
  81.         else:
  82.             print
  83.     except: pass
  84.  
  85. txt = '\n'.join(ttt+m)
  86.  
  87. print
  88. print
  89. print txt
  90. print
  91. print len(ttt+m)
  92.  
  93. try:
  94.     SaveText(txt,'sys_modules')
  95. except: print "\n\nWas Unable To Save That Data"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement