|
@@ -0,0 +1,42 @@
|
|
|
+import sys
|
|
|
+import logging
|
|
|
+import PyTango
|
|
|
+
|
|
|
+
|
|
|
+class Workspace(object):
|
|
|
+ def __init__(self, device, workspace_id):
|
|
|
+ self._device = device
|
|
|
+ self._workspace_id = workspace_id
|
|
|
+ self._path = self.device.GetPath(workspace)
|
|
|
+ logging.getLogger().info("Created workspace={}".format(self))
|
|
|
+
|
|
|
+ def __enter__(self):
|
|
|
+ return self
|
|
|
+
|
|
|
+ def __exit__(self, *exc):
|
|
|
+ self.close()
|
|
|
+
|
|
|
+ def __repr__(self):
|
|
|
+ return '<Workspace:id={} path={}>'.format(self._workspace_id, self._path)
|
|
|
+
|
|
|
+ @property
|
|
|
+ def path(self):
|
|
|
+ return self._path
|
|
|
+
|
|
|
+ def close(self):
|
|
|
+ self._device.CloseWorkspace(self._workspace_id)
|
|
|
+ logging.getLogger().info("Closed workspace={}".format(self))
|
|
|
+
|
|
|
+
|
|
|
+class WorkspaceCreator(object):
|
|
|
+ def __init__(self, device_name):
|
|
|
+ try:
|
|
|
+ self._device = PyTango.DeviceProxy(device_name)
|
|
|
+ except PyTango.DevFailed as e:
|
|
|
+ raise IOError("PyTango: {}".format(e[0].desc))
|
|
|
+
|
|
|
+ self._last_workspace = None
|
|
|
+
|
|
|
+ def create(self):
|
|
|
+ workspace_id = self._device.CreateWorkspace
|
|
|
+ return Workspace(self._device, workspace_id)
|