stdlibstubs.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. __author__ = 'bmiller'
  2. import os, shutil
  3. mymodules = ['document', 'math', 'operator', 'processing', 'random', 're', 'time', 'test', 'turtle', 'unittest', 'urllib', 'webgl']
  4. p26root = '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/'
  5. def make_stub(fname,fpath):
  6. modname = fname.replace('.py','')
  7. if modname not in mymodules:
  8. f = open(fpath, 'w')
  9. f.write('''raise NotImplementedError("%s is not yet implemented in Skulpt")\n''' % modname)
  10. f.close()
  11. for root, dirs, files in os.walk(p26root):
  12. for dname in dirs:
  13. newdir = os.path.join(root,dname)
  14. newdir = newdir.replace(p26root,'src/lib/')
  15. if not os.path.exists(newdir):
  16. print("making", newdir)
  17. os.makedirs(newdir)
  18. newfile = os.path.join(newdir,'__init__.py')
  19. make_stub(dname, newfile)
  20. for fname in [f for f in files if f.endswith(".py")]:
  21. newfile = root.replace(p26root,'src/lib/')
  22. if newfile.endswith('src/lib/'):
  23. newfile = os.path.join(newfile, fname)
  24. print("making file", newfile)
  25. make_stub(fname,newfile)