concert_workspacecreator.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. import logging
  3. import PyTango
  4. class Workspace(object):
  5. def __init__(self, device, workspace_id):
  6. self._device = device
  7. self._workspace_id = workspace_id
  8. self._path = self.device.GetWorkspacePath(workspace_id)
  9. logging.getLogger().info("Created workspace={}".format(self))
  10. def __enter__(self):
  11. return self
  12. def __exit__(self, *exc):
  13. self.close()
  14. def __repr__(self):
  15. return '<Workspace:id={} path={}>'.format(self._workspace_id, self._path)
  16. @property
  17. def path(self):
  18. return self._path
  19. def close(self):
  20. self._device.CloseWorkspace(self._workspace_id)
  21. logging.getLogger().info("Closed workspace={}".format(self))
  22. class WorkspaceCreator(object):
  23. def __init__(self, device_name):
  24. try:
  25. self._device = PyTango.DeviceProxy(device_name)
  26. except PyTango.DevFailed as e:
  27. raise IOError("PyTango: {}".format(e[0].desc))
  28. self._last_workspace = None
  29. def create(self):
  30. workspace_id = self._device.CreateWorkspace
  31. return Workspace(self._device, workspace_id)