PythonTools.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. import time
  3. class Tools:
  4. _public_methods_ = [ 'reload', 'adddir', 'echo', 'sleep' ]
  5. def reload(self, module):
  6. if module in sys.modules:
  7. from importlib import reload
  8. reload(sys.modules[module])
  9. return "reload succeeded."
  10. return "no reload performed."
  11. def adddir(self, dir):
  12. if type(dir) == type(''):
  13. sys.path.append(dir)
  14. return str(sys.path)
  15. def echo(self, arg):
  16. return repr(arg)
  17. def sleep(self, t):
  18. time.sleep(t)
  19. if __name__=='__main__':
  20. from win32com.server.register import RegisterServer, UnregisterServer
  21. clsid = "{06ce7630-1d81-11d0-ae37-c2fa70000000}"
  22. progid = "Python.Tools"
  23. verprogid = "Python.Tools.1"
  24. if "--unregister" in sys.argv:
  25. print("Unregistering...")
  26. UnregisterServer(clsid, progid, verprogid)
  27. print("Unregistered OK")
  28. else:
  29. print("Registering COM server...")
  30. RegisterServer(clsid,
  31. "win32com.servers.PythonTools.Tools",
  32. "Python Tools",
  33. progid,
  34. verprogid)
  35. print("Class registered.")