コード例 #1
0
ファイル: foreground.py プロジェクト: scope3/lca-tools
    def _key_to_id(self, key):
        """
        Fragments should be permitted to have any desired external_ref -- which means key_to_id needs to store a
        mapping of non-standard external refs to uuids.  This is only because (at the moment) every entity is stored
        in the archive using a uuid as its internal key.

        Open question: should this be a general feature?  currently only NsUuidArchives allow arbitrary external_refs.
        Answer: no. uuids are still king (for now)

        This function is a little different from other EntityStore subclasses because it (uniquely) needs to handle
        entities from a variety of origins. Therefore we use the link and not the uuid as an identifer.  However, we
        still need to support retrieval by UUID.  **WE WANT TO DO THIS WITHOUT HAVING TO OVERRIDE __getitem__**.
        So the operation is as follows:

         * _key_to_id transmits the user's heterogeneous input into a valid key to self._entities, or None
           - if the key is already a known link, it's easy
           - if the key is a custom name, it's almost as easy
           - if the key CONTAINS a uuid known to the db, then a link for an entity with that UUID is
              NONDETERMINISTICALLY returned
         * __getitem__ uses _key_to_id to translate the users input into a key

        For the thorns around renaming fragments, see self.name_fragment() below

        :param key:
        :return:
        """
        if key in self._entities:
            return key
        elif key in self._ext_ref_mapping:
            return self._ext_ref_mapping[key]
        else:
            uid = to_uuid(key)
            if uid in self._uuid_map:
                return next(k for k in self._uuid_map[uid])
        return None
コード例 #2
0
ファイル: base.py プロジェクト: bkuczenski/lca-tools
    def __init__(self, ref, ns_uuid=None, **kwargs):
        super(NsUuidArchive, self).__init__(ref, **kwargs)

        # internal namespace UUID for generating keys

        if ns_uuid is None:
            if self._upstream is not None:
                if isinstance(self._upstream, NsUuidArchive):
                    ns_uuid = self._upstream._ns_uuid

        ns_uuid = to_uuid(ns_uuid)  # if it's already a uuid, keep it; if it's a string, find it; else None

        self._ns_uuid = uuid.uuid4() if ns_uuid is None else ns_uuid
        self._serialize_dict['nsUuid'] = str(self._ns_uuid)
コード例 #3
0
ファイル: base.py プロジェクト: bkuczenski/lca-tools
 def _key_to_id(self, key):
     """
     Converts Ecospold01 "number" attributes to UUIDs using the internal UUID namespace.
     :param key:
     :return:
     """
     if isinstance(key, int):
         key = str(key)
     u = to_uuid(key)
     if u is not None:
         return u
     if six.PY2:
         return uuid.uuid3(self._ns_uuid, key.encode('utf-8'))
     else:
         return uuid.uuid3(self._ns_uuid, key)
コード例 #4
0
ファイル: lcia_results.py プロジェクト: bkuczenski/lca-tools
def get_entity_uuid(item):
    if to_uuid(item) is not None:
        return item
    if hasattr(item, "get_uuid"):
        return item.get_uuid()
    raise TypeError("Don't know how to get ID from %s" % type(item))
コード例 #5
0
ファイル: catalog.py プロジェクト: bkuczenski/lca-tools
def get_entity_uuid(item):
    if to_uuid(item) is not None:
        return item
    if hasattr(item, 'get_uuid'):
        return item.get_uuid()
    raise TypeError('Don\'t know how to get ID from %s' % type(item))