SliceInfoJob.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Job import Job
  4. from UM.Logger import Logger
  5. from UM.Platform import Platform
  6. import ssl
  7. import urllib.request
  8. import urllib.error
  9. class SliceInfoJob(Job):
  10. def __init__(self, url, data):
  11. super().__init__()
  12. self._url = url
  13. self._data = data
  14. def run(self):
  15. if not self._url or not self._data:
  16. Logger.log("e", "URL or DATA for sending slice info was not set!")
  17. return
  18. # Submit data
  19. kwoptions = {"data" : self._data, "timeout" : 5}
  20. if Platform.isOSX():
  21. kwoptions["context"] = ssl._create_unverified_context()
  22. Logger.log("i", "Sending anonymous slice info to [%s]...", self._url)
  23. try:
  24. f = urllib.request.urlopen(self._url, **kwoptions)
  25. Logger.log("i", "Sent anonymous slice info.")
  26. f.close()
  27. except urllib.error.HTTPError:
  28. Logger.logException("e", "An HTTP error occurred while trying to send slice information")
  29. except Exception: # We don't want any exception to cause problems
  30. Logger.logException("e", "An exception occurred while trying to send slice information")