Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # copy_pydoc.py
- import sys, os.path, keyword, webbrowser, __builtin__
- print 'SEARCHING FOR CORE MODULES... ',
- modules_in_each_path = []
- for f in sys.path:
- if '\\lib\\' in f and '\\Python' in f:
- for root, _, dir_files in os.walk(f):
- for df in dir_files:
- if '.py' in df:
- df,z = df.rsplit('.',1)
- try:
- __import__(df)
- if df not in modules_in_each_path:
- modules_in_each_path.append(df)
- except:
- 0
- #
- kwL = keyword.kwlist
- my_modules = (dir('keywords'), kwL, sys.builtin_module_names, sys.modules.keys(),
- dir(__builtin__), modules_in_each_path)
- my_modules = [val for sublist in my_modules for val in sublist]
- my_modules = list(set(my_modules))
- my_modules.sort()
- dir_x = u'C:\\'
- folder = u'Python\\'
- filename = 'corepydoc.txt'
- try: os.mkdir(dir_x+folder)
- except: pass
- fullpath = dir_x + folder + filename
- print 'CAPTURING CORE MODULE DETAILS... ',
- with open(fullpath,'w') as f:
- t = sys.stdout
- sys.stdout = f
- for module in my_modules:
- try: help(module)
- except: 0
- sys.stdout = t
- #
- print 'REFINING DETAILS OF CORE MODULES... '
- my_modules = []
- class ProgressBar():
- pointer = 0
- width = 100
- def __call__(self,x):
- # x in percent
- os.system('cls||clear')
- self.pointer = int(self.width*(x/100.0))
- progress = '\n > ' + chr(178)*self.pointer + ':'*(self.width-self.pointer)+\
- " < \n %d Percent " % int(x)
- #clear()
- sys.stdout.write(progress)
- sys.stdout.flush()
- pb = ProgressBar()
- p = 1
- i = 1
- prev = ''
- with open(fullpath,'r') as f:
- wait = len(f) / 100
- for line in f:
- if line != prev:
- prev = line
- if f.count(line) > 20 or line not in my_modules:
- my_modules.append(line)
- if not i%wait:
- pb(p)
- p+=1
- i+=1
- #
- print "\n\n *** Task Now Complete ***"
- with open(fullpath,'w') as f:
- f.write('\n'.join(my_modules))
- print 'OPENING SAVED FILE FOR USER TO NOW READ...'
- webbrowser.open('file://' + fullpath)
Add Comment
Please, Sign In to add comment