here2share

# copy_pydoc.py

Apr 14th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. # copy_pydoc.py
  2.  
  3. import sys, os.path, keyword, webbrowser, __builtin__
  4.  
  5. print 'SEARCHING FOR CORE MODULES... ',
  6. modules_in_each_path = []
  7. for f in sys.path:
  8.     if '\\lib\\' in f and '\\Python' in f:
  9.         for root, _, dir_files in os.walk(f):
  10.             for df in dir_files:
  11.                 if '.py' in df:
  12.                     df,z = df.rsplit('.',1)
  13.                     try:
  14.                         __import__(df)
  15.                         if df not in modules_in_each_path:
  16.                             modules_in_each_path.append(df)
  17.                     except:
  18.                         0
  19. #
  20.  
  21. kwL = keyword.kwlist
  22. my_modules =   (dir('keywords'), kwL, sys.builtin_module_names, sys.modules.keys(),
  23.                 dir(__builtin__), modules_in_each_path)
  24. my_modules = [val for sublist in my_modules for val in sublist]
  25.  
  26. my_modules = list(set(my_modules))
  27. my_modules.sort()
  28.  
  29. dir_x = u'C:\\'
  30. folder = u'Python\\'
  31. filename = 'corepydoc.txt'
  32. try: os.mkdir(dir_x+folder)
  33. except: pass
  34. fullpath = dir_x + folder + filename
  35.  
  36. print 'CAPTURING CORE MODULE DETAILS... ',
  37. with open(fullpath,'w') as f:
  38.     t = sys.stdout
  39.     sys.stdout = f
  40.     for module in my_modules:
  41.         try: help(module)
  42.         except: 0
  43.     sys.stdout = t
  44. #
  45.  
  46. print 'REFINING DETAILS OF CORE MODULES... '
  47. my_modules = []
  48.  
  49. class ProgressBar():
  50.     pointer = 0
  51.     width = 100
  52.  
  53.     def __call__(self,x):
  54.         # x in percent
  55.         os.system('cls||clear')
  56.         self.pointer = int(self.width*(x/100.0))
  57.         progress = '\n > ' + chr(178)*self.pointer + ':'*(self.width-self.pointer)+\
  58.         " < \n %d Percent " % int(x)
  59.        
  60.         #clear()
  61.         sys.stdout.write(progress)
  62.         sys.stdout.flush()
  63.  
  64. pb = ProgressBar()
  65.  
  66. p = 1
  67. i = 1
  68. prev = ''
  69. with open(fullpath,'r') as f:
  70.     wait = len(f) / 100
  71.     for line in f:
  72.         if line != prev:
  73.             prev = line
  74.             if f.count(line) > 20 or line not in my_modules:
  75.                 my_modules.append(line)
  76.             if not i%wait:
  77.                 pb(p)
  78.                 p+=1
  79.             i+=1
  80. #
  81. print "\n\n *** Task Now Complete ***"
  82.  
  83. with open(fullpath,'w') as f:
  84.     f.write('\n'.join(my_modules))
  85.  
  86. print 'OPENING SAVED FILE FOR USER TO NOW READ...'
  87. webbrowser.open('file://' + fullpath)
Add Comment
Please, Sign In to add comment