Beispiel #1
0
    def __init__(self, layer_uri, xml_uri=None, json_uri=None):
        """
        Constructor.

        :param layer_uri: uri of the layer for which the metadata ae
        :type layer_uri: str
        :param xml_uri: uri of an xml file to use
        :type xml_uri: str
        :param json_uri: uri of a json file to use
        :type json_uri: str
        """
        # private members
        self._layer_uri = layer_uri
        # TODO (MB): maybe use MetadataDbIO.are_metadata_file_based instead
        self._layer_is_file_based = os.path.isfile(layer_uri)

        instantiate_metadata_db = False

        path = os.path.splitext(layer_uri)[0]

        if xml_uri is None:
            if self.layer_is_file_based:
                self._xml_uri = '%s.xml' % path
            else:
                # xml should be stored in cacheDB
                self._xml_uri = None
                instantiate_metadata_db = True
        else:
            self._xml_uri = xml_uri

        if json_uri is None:
            if self.layer_is_file_based:
                self._json_uri = '%s.json' % path
            else:
                # json should be stored in cacheDB
                self._json_uri = None
                instantiate_metadata_db = True

        else:
            self._json_uri = json_uri

        if instantiate_metadata_db:
            self.db_io = MetadataDbIO()

        self.reading_ancillary_files = False
        self._properties = {}

        # initialise the properties
        for name, path in self._standard_properties.iteritems():
            self.set(name, None, path)

        self._last_update = datetime.now()

        try:
            self.read_from_ancillary_file(xml_uri)
        except IOError:
            pass