Commits

Stefan Scherfke committed af34ac1

Some fixes and a BaseStorage class.

Comments (0)

Files changed (6)

collectors/__init__.py

 from collectors.core import Collector
 from collectors.shortcuts import get, manual, get_objects
 
-__all__ = ['Collector', 'backends', 'manual', 'get', 'get_objects']
+__all__ = ['Collector', 'storage', 'manual', 'get', 'get_objects']

collectors/core.py

 
 """
 
-import tables
+class BaseStorage(object):
+    def __init__(self):
+        self.append_func = None
 
+    def create_series(self, name, index, dtype=None):
+        raise NotImplementedError(self)
 
-class ListBackend(object):
+
+class DefaultStorage(BaseStorage):
     def __init__(self):
         self.append_func = list.append
 
             raise AttributeError('Nothing to be monitored.')
 
         backend = kwargs['backend'] \
-                if 'backend' in kwargs else ListBackend()
+                if 'backend' in kwargs else DefaultStorage()
 
         # Parse arguments using a helper function. This method will populate the
         # following lists.

collectors/examples.py

 
     from xlwt import Workbook
 
-    from collectors import backends
+    from collectors import storage
 
     w = Workbook()
     s = w.add_sheet('my collected data')
         pass
 
     obj = ObserveMe()
-    c = Collector(get(obj, 'value_a', 'value_b'), backend=backends.Excel(w, s))
+    c = Collector(get(obj, 'value_a', 'value_b'), backend=storage.Excel(w, s))
 
     for a, b in zip(range(10), reversed(range(10))):
         obj.value_a, obj.value_b = a, b

collectors/storage/__init__.py

 
 try:
     from excel import Excel, ExcelSeries
-except ImportError as e:
+except ImportError:
     pass
+
+try:
+    from pytables import PyTables
+except ImportError:
+    pass

collectors/storage/excel.py

 # encoding: utf-8
 
+from collectors.core import BaseStorage
+
+
 class ExcelSeries(object):
     def __init__(self, sheet, col_name, col_index):
         self.sheet = sheet
         self.sheet.write(self.row_index, self.col_index, value)
         self.row_index += 1
 
-class Excel(object):
+
+class Excel(BaseStorage):
     def __init__(self, book, sheet):
+        self.append_func = lambda series, value: series.append(value)
+
         self.book = book
         self.sheet = sheet
 
     def create_series(self, name, index, dtype=None):
         return ExcelSeries(self.sheet, name, index)
-
-    @staticmethod
-    def append_func(series, value):
-        series.append(value)

collectors/storage/pytables.py

 
 import tables
 
+from collectors.core import BaseStorage
 
-class PyTablesBackend(object):
+
+class PyTablesBackend(BaseStorage):
     def __init__(self, hd5file, group):
         self.hd5file = hd5file
-        self group = group \
+        self.group = group \
                 if isinstance(group, tables.HDF5Group) \
                 else self.hd5file.createGroup('/', group)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.