]> git.parisson.com Git - timeside.git/commitdiff
feature(tools): add buffering method based on PyTables
authorThomas Fillon <thomas@parisson.com>
Fri, 4 Jul 2014 10:26:56 +0000 (12:26 +0200)
committerThomas Fillon <thomas@parisson.com>
Fri, 4 Jul 2014 10:26:56 +0000 (12:26 +0200)
.travis.yml
README.rst
setup.py
timeside/tools/buffering.py [new file with mode: 0644]

index 5334bcd7cfa26838738b0044f1b1d8f0546caa7f..751a6f25976360ff5950db1491f1441efd3f2c08 100644 (file)
@@ -10,7 +10,7 @@ before_install:
  - sudo apt-get -qq update
  - sudo apt-get install python-setuptools
  - sudo apt-get install -qq python-numpy python-scipy python-matplotlib
- - sudo apt-get install -qq libhdf5-serial-dev python-h5py
+ - sudo apt-get install -qq libhdf5-serial-dev python-h5py pytables
  - sudo apt-get install -qq python-gst0.10 gstreamer0.10-plugins-good gstreamer0.10-gnonlin gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad
 
 # command to install dependencies
index 713385a72d95a03a15ced8cb1ce97f93981626f3..c7a79fb4550b4671d8b2dc23fde72b06119c0a0f 100644 (file)
@@ -292,7 +292,7 @@ Dependencies
 Needed::
 
  python (>=2.7) python-setuptools python-numpy python-scipy python-h5py python-matplotlib python-imaging
- python-simplejson python-yaml python-mutagen libhdf5-serial-dev python-gst0.10
+ python-simplejson python-yaml python-mutagen libhdf5-serial-dev pytables python-gst0.10
  gstreamer0.10-gnonlin gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly
 
 Optional::
index f6b5a583cc7378b89f9d08529477228fe59c5442..96607b475e2b0498dd3f46ac0f8cdc32ae1df4e8 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -50,6 +50,7 @@ setup(
         'mutagen',
         'pillow',
         'h5py',
+        'tables',
         'pyyaml',
         'simplejson',
         'scipy',
diff --git a/timeside/tools/buffering.py b/timeside/tools/buffering.py
new file mode 100644 (file)
index 0000000..f0e8320
--- /dev/null
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Parisson SARL
+# Copyright (c) 2014 Thomas Fillon <thomas@parisson.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author : Thomas Fillon <thomas@parisson.com>
+
+import tables
+from tempfile import NamedTemporaryFile
+
+
+class BufferTable(object):
+    def __init__(self, array_names=None):
+        self._tempfile = NamedTemporaryFile(mode='w', suffix='.h5',
+                                            prefix='ts_buf_',
+                                            delete=True)
+        self.fileh = tables.open_file(self._tempfile.name, mode='w')
+
+        if not array_names:
+            array_names = []
+        if isinstance(array_names, list):
+            self.array_names = array_names
+        else:
+            self.array_names = [array_names]
+        for name in array_names:
+            if not isinstance(name, basestring):
+                raise(TypeError, 'String argument require in array_names')
+
+    def __getitem__(self, name):
+        return self.fileh.root.__getattr__(name)
+
+    #def __set_item__(self, name, value):
+    #    self.fileh.root.__setattr__(name, value)
+
+    def append(self, name, new_array):
+        try:
+            self.fileh.root.__getattr__(name).append([new_array])
+        except tables.exceptions.NoSuchNodeError:
+            if name not in self.array_names:
+                self.array_names.append(name)
+            self.fileh.create_earray(where=self.fileh.root,
+                                     name=name,
+                                     obj=[new_array])
+
+    def close(self):
+        for name in self.array_names:
+            self.fileh.remove_node(self.fileh.root, name)
+        self.fileh.close()
+        self._tempfile.close()