Browse Source

Initial commit

Matthias Vogelgesang 9 years ago
commit
e279ec5b2d
4 changed files with 77 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 19 0
      README.md
  3. 42 0
      concert_workspacecreator.py
  4. 13 0
      setup.py

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+build/
+dist/
+*.egg-info

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+### WorkspaceCreator for Concert/Python
+
+Create a workspace with
+
+```python
+from concert.third.workspacecreator import WorkspaceCreator
+
+creator = WorkspaceCreator('foo/bar/baz')
+workspace = creator.create()
+print(workspace.path)
+workspace.close()
+```
+
+or let close automatically with the context manager
+
+```python
+with creator.create() as workspace:
+    print(workspace.path)
+```

+ 42 - 0
concert_workspacecreator.py

@@ -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)

+ 13 - 0
setup.py

@@ -0,0 +1,13 @@
+from setuptools import setup
+
+
+setup(
+    name='Concert-WorkspaceCreator',
+    version='1.0',
+    py_modules=['concert_workspacecreator'],
+    zip_safe=False,
+    install_requires=[
+        'concert',
+        'PyTango',
+    ]
+)