# coding=utf-8 from BTrees.OOBTree import OOBTree from persistent import Persistent class MBase(Persistent): """ BASE Class for all classes of Playground System ----------------------------------------------- """ def __init__(self): self.name = None # main folder name (this can change after folder creation) self.path = None # main folder path self.children = OOBTree() # children list self.data = OOBTree() # data list # Maybe some global methods here # for example: # getting all children or all data # with index vs vs. (list comprehensions here) class MContainer(MBase): """ BASE MContainer CLASS --------------------- MContainer class represents folders that has same base-typed children and children grouping attributes ... a MContainer based object can have MAsset based objects only for parenting. ... a MContainer object have children data and methods to access them ... EXAMPLE 1: - Episode(s) is a MContainer class object (it's plural) - an Episode(s) class object can contain only Episode(MAsset) class objects - an MContainer has grouping attributes - so, we can group its children. (episode 1-13, episode 14-26 etc...) EXAMPLE 2: - Asset(s) is a MContainer object - it can only have Asset objects - so, we can group them like CHARACTERS, VEHICLES and so on... """ def __init__(self): super(MContainer, self).__init__() self.group_data = OOBTree() # data needed for grouping (keys: Group names, values def append(self, asset): """Adds MAsset object to self.children""" if isinstance(asset, MAsset): if self.children.insert(asset.name, asset): return True else: # if already have a same named child don't contain it # and return false. this is the default behaviour of BTrees # it simply ignores it, so i need to raise exception raise KeyError('{} is already exists. Try different name.'.format(asset.name)) else: # asset object is not MAsset object raise TypeError('Passed object is not a object.') # maybe we need grouping methods here class MAsset(MBase): """ BASE MAsset CLASS ----------------- MAsset class represents folders that has same base-typed children but unlike MContainer class has no children grouping attributes. ... MAsset class can only have MContainer class objects or some special type. (maya scene files, textures, organization etc.) ... EXAMPLE 1: - Shot (no plural) is a MAsset base-typed object - it has some special attributes This class is almost identical with MContainer class it's a seperate class because both have methods for allowed children control. so this class can only allow MContainer object, a MContainer object can only have this type... """ def __init__(self): super(MAsset, self).__init__() def append(self, container): """Adds MContainer object to self.children""" if isinstance(container, MContainer): if self.children.insert(container.name, container): return True else: # if already have a same named child don't contain it # and return false. this is the default behaviour of BTrees # it simply ignores it, so i need to raise exception raise KeyError('{} is already exists. Try different name.'.format(container.name)) else: # container object is not MContainer object raise TypeError('Passed object is not a object.')