X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fpython%2Fsigrok%2Fcore%2Fclasses.py;h=15bfc9379cb8942d6ca022b24831dde38e0f01c1;hb=f0e764de7babf8004169732749040d9a2fc4ad71;hp=6b55eb3f99754c7c431290898961874776097e59;hpb=a64198c8ea721c3a7867e9a753f1a761b89769c9;p=libsigrok.git diff --git a/bindings/python/sigrok/core/classes.py b/bindings/python/sigrok/core/classes.py index 6b55eb3f..15bfc937 100644 --- a/bindings/python/sigrok/core/classes.py +++ b/bindings/python/sigrok/core/classes.py @@ -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):