# Path: dpa/app/entity.py
# class EntityRegistry(Singleton):
# 
#     # -------------------------------------------------------------------------
#     def init(self):
#         self._registry = defaultdict(list)
# 
#     # -------------------------------------------------------------------------
#     def get_entity_classes(self, app_name):
# 
#         # XXX should be filtered based on current ptask. 
#         # for example, anim stages may want to expose different entity types
#         # than modeling or lighting
# 
#         return self._registry.get(app_name, [])
# 
#     # -------------------------------------------------------------------------
#     def register(self, app_name, cls):
#         self._registry[app_name].append(cls)
# 
# class EntityError(Exception):
#     pass
# 
# Path: dpa/maya/entity/base.py
# class SetBasedEntity(MayaEntity):
# 
#     category = None
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def set_regex(cls):
# 
#         return re.compile(
#             "^export_{cat}_([\w]+)_?(\d+)?$".format(cat=cls.category),
#             re.IGNORECASE
#         )
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get_set_name(cls, name, inst=None):
# 
#         if inst is not None:
#             set_name = "export_{cat}_{name}_{inst}".format(
#                 cat=cls.category,
#                 name=name,
#                 inst=inst,
#             )
#         else:
#             set_name = "export_{cat}_{name}".format(
#                 cat=cls.category,
#                 name=name,
#             )
# 
#         return set_name
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get(cls, name, session, instance=None):
#         """Retrieve an entity instance from the supplied session."""
# 
#         # make sure the name exists. 
#         set_names = cls.get_export_sets(session)
# 
#         fullname = name
#         if instance:
#             fullname += "_" + str(instance)
# 
#         matches = [s for s in set_names if s.endswith(fullname)]
# 
#         if not matches and len(matches) != 1:
#             raise EntityError(
#                 "Could not find unique {cat} {name} instance in session.".\
#                     format(cat=cls.category, name=fullname)
#             )
# 
#         return cls(name, session, instance)
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def list(cls, session):
#         """Retrieve all entities of this type from the supplied session."""
# 
#         entities = []
# 
#         set_names = cls.get_export_sets(session)
# 
#         for set_name in set_names:
# 
#             name_parts = cls.set_regex().match(set_name)
#             if not name_parts:
#                 continue
# 
#             (name, instance) = name_parts.groups()
# 
#             if not instance:
#                 instance=None
#         
#             entities.append(cls(name, session, instance))
# 
#         return entities
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get_export_sets(cls, session):
# 
#         export_sets = []
#         maya_sets = session.cmds.ls(sets=True)
#         for maya_set in maya_sets:
#             match = cls.set_regex().match(maya_set)
#             if match:
#                 export_sets.append(maya_set)
# 
#         return export_sets
# 
#     # -------------------------------------------------------------------------
#     def get_export_objects(self):
#         
#         export_set = self._get_export_set()
#         return self.session.cmds.sets(export_set, query=True)
# 
#     # -----------------------------------------------------------------------------
#     def _get_export_set(self):
# 
#         # make sure the name exists. 
#         set_names = self.__class__.get_export_sets(self.session)
#         matches = [s for s in set_names if s.endswith(self.display_name)]
# 
#         if not matches and len(matches) != 1:
#             raise EntityError("Unable to identify export set for entity!")
# 
#         return matches[0]


import os.path
import re
from dpa.app.entity import EntityRegistry, EntityError
from dpa.maya.entity.base import SetBasedEntity



# -----------------------------------------------------------------------------
class GeomcacheEntity(SetBasedEntity):

    category = "geomcache"

    # -------------------------------------------------------------------------
    @classmethod
    def import_product_representation(cls, session, representation, *args,
        **kwargs):

        if representation.type == 'fbx':
            cls._fbx_import(session, representation, *args, **kwargs)
        elif representation.type == 'abc':
            cls._abc_import(session, representation, *args, **kwargs)
        else:

# Path: dpa/app/entity.py
# class EntityRegistry(Singleton):
# 
#     # -------------------------------------------------------------------------
#     def init(self):
#         self._registry = defaultdict(list)
# 
#     # -------------------------------------------------------------------------
#     def get_entity_classes(self, app_name):
# 
#         # XXX should be filtered based on current ptask. 
#         # for example, anim stages may want to expose different entity types
#         # than modeling or lighting
# 
#         return self._registry.get(app_name, [])
# 
#     # -------------------------------------------------------------------------
#     def register(self, app_name, cls):
#         self._registry[app_name].append(cls)
# 
# class EntityError(Exception):
#     pass
# 
# Path: dpa/maya/entity/base.py
# class SetBasedEntity(MayaEntity):
# 
#     category = None
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def set_regex(cls):
# 
#         return re.compile(
#             "^export_{cat}_([\w]+)_?(\d+)?$".format(cat=cls.category),
#             re.IGNORECASE
#         )
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get_set_name(cls, name, inst=None):
# 
#         if inst is not None:
#             set_name = "export_{cat}_{name}_{inst}".format(
#                 cat=cls.category,
#                 name=name,
#                 inst=inst,
#             )
#         else:
#             set_name = "export_{cat}_{name}".format(
#                 cat=cls.category,
#                 name=name,
#             )
# 
#         return set_name
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get(cls, name, session, instance=None):
#         """Retrieve an entity instance from the supplied session."""
# 
#         # make sure the name exists. 
#         set_names = cls.get_export_sets(session)
# 
#         fullname = name
#         if instance:
#             fullname += "_" + str(instance)
# 
#         matches = [s for s in set_names if s.endswith(fullname)]
# 
#         if not matches and len(matches) != 1:
#             raise EntityError(
#                 "Could not find unique {cat} {name} instance in session.".\
#                     format(cat=cls.category, name=fullname)
#             )
# 
#         return cls(name, session, instance)
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def list(cls, session):
#         """Retrieve all entities of this type from the supplied session."""
# 
#         entities = []
# 
#         set_names = cls.get_export_sets(session)
# 
#         for set_name in set_names:
# 
#             name_parts = cls.set_regex().match(set_name)
#             if not name_parts:
#                 continue
# 
#             (name, instance) = name_parts.groups()
# 
#             if not instance:
#                 instance=None
#         
#             entities.append(cls(name, session, instance))
# 
#         return entities
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def get_export_sets(cls, session):
# 
#         export_sets = []
#         maya_sets = session.cmds.ls(sets=True)
#         for maya_set in maya_sets:
#             match = cls.set_regex().match(maya_set)
#             if match:
#                 export_sets.append(maya_set)
# 
#         return export_sets
# 
#     # -------------------------------------------------------------------------
#     def get_export_objects(self):
#         
#         export_set = self._get_export_set()
#         return self.session.cmds.sets(export_set, query=True)
# 
#     # -----------------------------------------------------------------------------
#     def _get_export_set(self):
# 
#         # make sure the name exists. 
#         set_names = self.__class__.get_export_sets(self.session)
#         matches = [s for s in set_names if s.endswith(self.display_name)]
# 
#         if not matches and len(matches) != 1:
#             raise EntityError("Unable to identify export set for entity!")
# 
#         return matches[0]


# Path: dpa/maya/entity/geomcache.py
import os.path
import re
from dpa.app.entity import EntityRegistry, EntityError
from dpa.maya.entity.base import SetBasedEntity




# -----------------------------------------------------------------------------
class GeomcacheEntity(SetBasedEntity):

    category = "geomcache"

    # -------------------------------------------------------------------------
    @classmethod
    def import_product_representation(cls, session, representation, *args,
        **kwargs):

        if representation.type == 'fbx':
            cls._fbx_import(session, representation, *args, **kwargs)
        elif representation.type == 'abc':
            cls._abc_import(session, representation, *args, **kwargs)
        else:

            raise EntityError(