From 3e763544025de8b5f5607fe8b9e87b3f5d93106c Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Thu, 19 Mar 2015 18:32:39 +0100 Subject: [PATCH] Allow python sample classes to be used as sample_ref's Update packaging --- lib/python/labcomm2014/LabComm.py | 23 +++++++++++++++-------- packaging/make_srpm | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/python/labcomm2014/LabComm.py b/lib/python/labcomm2014/LabComm.py index 208b92f..bff63de 100644 --- a/lib/python/labcomm2014/LabComm.py +++ b/lib/python/labcomm2014/LabComm.py @@ -375,6 +375,9 @@ class SAMPLE(primitive): return encoder.encode_type(i_SAMPLE) def encode(self, encoder, value): + if not isinstance(value, type_decl): + # Probably trying to encode a sample class, grab signature + value = value.signature return encoder.encode_int(encoder.ref_to_index.get(value, 0)) def decode(self, decoder, obj=None): @@ -729,6 +732,9 @@ class Codec(object): return True def add_ref(self, ref, index=0): + if not isinstance(ref, type_decl): + # Probably trying to register a sample class, grab signature + ref = ref.signature if index == 0: if ref.sample in self.ref_to_index: return False @@ -783,15 +789,16 @@ class Encoder(Codec): decl.encode_decl(self) self.writer.mark_end(decl, None) - def add_ref(self, decl, index=0): - if not isinstance(decl, type_decl): - decl = decl.signature - ref = sample_ref(name=decl.name, decl=decl.decl, sample=decl) + def add_ref(self, ref, index=0): + if not isinstance(ref, type_decl): + # Trying to register a sample class + ref = ref.signature + decl = sample_ref(name=ref.name, decl=ref.decl, sample=ref) if index == 0: - self.writer.mark_begin(decl, None) - if super(Encoder, self).add_ref(ref, index): - ref.encode_decl(self) - self.writer.mark_end(decl, None) + self.writer.mark_begin(ref, None) + if super(Encoder, self).add_ref(decl, index): + decl.encode_decl(self) + self.writer.mark_end(ref, None) def encode(self, object, decl=None): if decl == None: diff --git a/packaging/make_srpm b/packaging/make_srpm index 4925a83..b62f47b 100755 --- a/packaging/make_srpm +++ b/packaging/make_srpm @@ -68,7 +68,7 @@ install -m u=r,g=r,o=r lib/csharp/labcomm2014.dll ${RPM_BUILD_ROOT}/usr/lib # Python # install -d ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2014 -install lib/python/labcomm/* ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2014 +install lib/python/labcomm2014/* ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2014 %files %defattr (-, root, root) -- GitLab