]> sigrok.org Git - libsigrok.git/blobdiff - bindings/python/sigrok/core/classes.py
python: Finish input format support.
[libsigrok.git] / bindings / python / sigrok / core / classes.py
index 6b55eb3f99754c7c431290898961874776097e59..15bfc9379cb8942d6ca022b24831dde38e0f01c1 100644 (file)
@@ -25,7 +25,8 @@ import itertools
 
 __all__ = ['Error', 'Context', 'Driver', 'Device', 'Session', 'Packet', 'Log',
     'LogLevel', 'PacketType', 'Quantity', 'Unit', 'QuantityFlag', 'ConfigKey',
-    'ProbeType', 'Probe', 'ProbeGroup']
+    'ProbeType', 'Probe', 'ProbeGroup', 'InputFormat', 'OutputFormat',
+    'InputFile']
 
 class Error(Exception):
 
@@ -434,6 +435,28 @@ class InputFormat(object):
     def description(self):
         return self.struct.description
 
+    def format_match(self, filename):
+        return bool(self.struct.call_format_match(filename))
+
+class InputFile(object):
+
+    def __init__(self, format, filename, **kwargs):
+        self.format = format
+        self.filename = filename
+        self.struct = sr_input()
+        self.struct.format = self.format.struct
+        self.struct.param = g_hash_table_new_full(
+            g_str_hash, g_str_equal, g_free, g_free)
+        for key, value in kwargs.items():
+            g_hash_table_insert(self.struct.param, g_strdup(key), g_strdup(str(value)))
+        check(self.format.struct.call_init(self.struct, self.filename))
+
+    def load(self):
+        check(self.format.struct.call_loadfile(self.struct, self.filename))
+
+    def __del__(self):
+        g_hash_table_destroy(self.struct.param)
+
 class OutputFormat(object):
 
     def __init__(self, context, struct):