From 21bddd13e2e284d87dfa133bd8d08df465c8d102 Mon Sep 17 00:00:00 2001 From: andamian Date: Tue, 12 Nov 2019 13:16:28 -0800 Subject: [PATCH] 2.4 (#117) * Initial version of 2.4 --- caom2/caom2/caom_util.py | 4 +- caom2/caom2/checksum.py | 2 + caom2/caom2/common.py | 20 ++--- caom2/caom2/obs_reader_writer.py | 7 ++ .../tests/data/SampleDerived-CAOM-2.4.xml | 84 +++++++++---------- caom2/caom2/tests/test_caom_util.py | 4 - caom2/setup.cfg | 2 +- 7 files changed, 59 insertions(+), 64 deletions(-) diff --git a/caom2/caom2/caom_util.py b/caom2/caom2/caom_util.py index 68a3b873..f14bc009 100644 --- a/caom2/caom2/caom_util.py +++ b/caom2/caom2/caom_util.py @@ -122,10 +122,10 @@ def validate_path_component(caller, name, test): is invalid """ - if ' ' in test or '/' in test or '||' in test or '%' in test: + if ' ' in test or '||' in test or '%' in test: raise \ ValueError(caller.__class__.__name__ + ": invalid " + name + - ": may not contain space ( ), slash (/), escape (\\), " + ": may not contain space ( ), escape (\\), " "or percent (%)") diff --git a/caom2/caom2/checksum.py b/caom2/caom2/checksum.py index 9898278f..0ea7e46d 100644 --- a/caom2/caom2/checksum.py +++ b/caom2/caom2/checksum.py @@ -336,6 +336,8 @@ def update_caom_checksum(checksum, entity, parent=None): # get the id first if isinstance(entity, AbstractCaomEntity): update_checksum(checksum, entity._id) + if entity._meta_producer: + update_checksum(checksum, entity._meta_producer) # determine the excluded fields if necessary checksum_excluded_fields = [] diff --git a/caom2/caom2/common.py b/caom2/caom2/common.py index 678c8617..339a1fbb 100644 --- a/caom2/caom2/common.py +++ b/caom2/caom2/common.py @@ -182,14 +182,14 @@ def __repr__(self): class AbstractCaomEntity(CaomObject): """Class that defines the persistence unique ID and last mod date """ - def __init__(self, fulluuid=True): + def __init__(self, fulluuid=True, meta_producer=None): super(CaomObject, self).__init__() self._id = AbstractCaomEntity._gen_id(fulluuid) self.last_modified = None self.max_last_modified = None self.meta_checksum = None self.acc_meta_checksum = None - self.meta_producer = None + self._meta_producer = meta_producer @classmethod def _gen_id(cls, fulluuid=True): @@ -273,24 +273,14 @@ def acc_meta_checksum(self, value): False) self._acc_meta_checksum = value - @property - def meta_producer(self): - """TBD - + def get_meta_producer(self): + """ + Returns meta producer type: URI """ return self._meta_producer - @meta_producer.setter - def meta_producer(self, value): - if value is None: - self._meta_producer = None - else: - caom_util.type_check(value, ChecksumURI, "meta_producer", - False) - self._meta_producer = value - class VocabularyTerm(object): """ VocabularyTerm """ diff --git a/caom2/caom2/obs_reader_writer.py b/caom2/caom2/obs_reader_writer.py index 50506297..6247fc1d 100644 --- a/caom2/caom2/obs_reader_writer.py +++ b/caom2/caom2/obs_reader_writer.py @@ -166,6 +166,7 @@ def _set_entity_attributes(self, element, ns, caom2_entity): element_max_last_modified = element.get("{" + ns + "}maxLastModified") element_meta_checksum = element.get("{" + ns + "}metaChecksum") element_acc_meta_checksum = element.get("{" + ns + "}accMetaChecksum") + element_meta_producer = element.get("{" + ns + "}metaProducer") caom2_entity._id = uuid.UUID(element_id) @@ -181,6 +182,9 @@ def _set_entity_attributes(self, element, ns, caom2_entity): if element_acc_meta_checksum: caom2_entity._acc_meta_checksum = common.ChecksumURI( element_acc_meta_checksum) + if element_meta_producer: + caom2_entity._meta_producer = common.ChecksumURI( + element_meta_producer) def _get_child_element(self, element_tag, parent, ns, required): for element in list(parent): @@ -1913,6 +1917,9 @@ def _add_entity_attributes(self, entity, element): if entity._acc_meta_checksum is not None: self._add_attribute( "accMetaChecksum", entity._acc_meta_checksum.uri, element) + if entity._meta_producer is not None: + self._add_attribute( + "metaProducer", entity.get_meta_producer().uri, element) def _add_algorithm_element(self, algorithm, parent): if algorithm is None: diff --git a/caom2/caom2/tests/data/SampleDerived-CAOM-2.4.xml b/caom2/caom2/tests/data/SampleDerived-CAOM-2.4.xml index e050ac89..43741dac 100644 --- a/caom2/caom2/tests/data/SampleDerived-CAOM-2.4.xml +++ b/caom2/caom2/tests/data/SampleDerived-CAOM-2.4.xml @@ -1,8 +1,8 @@ - + collection observationID - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?A ivo://cadc.nrc.ca/gms?B @@ -73,15 +73,15 @@ true - + productID0 ivo://example.org/foo?productID0 - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?A ivo://cadc.nrc.ca/gms?B - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -95,7 +95,7 @@ provenanceProducer provenanceRunID http://foo/bar - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 keyword1 keyword2 @@ -247,11 +247,11 @@ 10 - + ad:foo/bar0 science data - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -260,11 +260,11 @@ 12345 md5:d41d8cd98f00b204e9800998ecf8427e - + x0 science - + 5 6 1 @@ -586,7 +586,7 @@ - + 5 6 1 @@ -910,11 +910,11 @@ - + x1 science - + 5 6 1 @@ -1236,7 +1236,7 @@ - + 5 6 1 @@ -1562,11 +1562,11 @@ - + ad:foo/bar1 science data - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -1575,11 +1575,11 @@ 12345 md5:d41d8cd98f00b204e9800998ecf8427e - + x0 science - + 5 6 1 @@ -1901,7 +1901,7 @@ - + 5 6 1 @@ -2225,11 +2225,11 @@ - + x1 science - + 5 6 1 @@ -2551,7 +2551,7 @@ - + 5 6 1 @@ -2879,15 +2879,15 @@ - + productID1 ivo://example.org/foo?productID1 - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?A ivo://cadc.nrc.ca/gms?B - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -2901,7 +2901,7 @@ provenanceProducer provenanceRunID http://foo/bar - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 keyword1 keyword2 @@ -3020,11 +3020,11 @@ 10 - + ad:foo/bar0 science data - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -3033,11 +3033,11 @@ 12345 md5:d41d8cd98f00b204e9800998ecf8427e - + x0 science - + 5 6 1 @@ -3359,7 +3359,7 @@ - + 5 6 1 @@ -3683,11 +3683,11 @@ - + x1 science - + 5 6 1 @@ -4009,7 +4009,7 @@ - + 5 6 1 @@ -4335,11 +4335,11 @@ - + ad:foo/bar1 science data - 2019-07-18T00:24:35.667 + 2019-10-18T20:22:53.979 ivo://cadc.nrc.ca/gms?C ivo://cadc.nrc.ca/gms?D @@ -4348,11 +4348,11 @@ 12345 md5:d41d8cd98f00b204e9800998ecf8427e - + x0 science - + 5 6 1 @@ -4674,7 +4674,7 @@ - + 5 6 1 @@ -4998,11 +4998,11 @@ - + x1 science - + 5 6 1 @@ -5324,7 +5324,7 @@ - + 5 6 1 diff --git a/caom2/caom2/tests/test_caom_util.py b/caom2/caom2/tests/test_caom_util.py index 8b393a57..2aa4f3cc 100644 --- a/caom2/caom2/tests/test_caom_util.py +++ b/caom2/caom2/tests/test_caom_util.py @@ -142,10 +142,6 @@ def test_validate_path_component(self): caom_util.validate_path_component(energy, "energyfield", "some:test path") - with pytest.raises(ValueError): - caom_util.validate_path_component(energy, "energyfield", - "some:test/path") - with pytest.raises(ValueError): caom_util.validate_path_component(energy, "energyfield", "some:test||path") diff --git a/caom2/setup.cfg b/caom2/setup.cfg index 2d827550..55880b85 100644 --- a/caom2/setup.cfg +++ b/caom2/setup.cfg @@ -42,7 +42,7 @@ install_requires = lxml<=4.3.0;python_version=="3.4" lxml>=3.7.0;python_version>="3.5" # version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386) -version = 2.4.0a +version = 2.4.0b [entry_points]