Exemple #1
0
class ParseSchema(object):
    """ Super class that parses all necessary content that can be parsed on a global level """
    def __init__(self, filePath='', team='', mobu=0, **kwargs):
        super(ParseSchema, self).__init__()
        self.filePath = filePath

        if not filePath:
            if mobu:
                # get sceneName
                from pyfbsdk import FBApplication  # @UnresolvedImport

                self.filePath = Path(FBApplication().FBXFileName.replace(
                    '\\', '/'))
                if not self.filePath:
                    self.filePath = None
                elif self.filePath.basename() == '':
                    self.filePath = None
            else:
                try:
                    from pymel.core import sceneName
                except ImportError:
                    sceneName = None
                    logger.errorDialog(
                        "ParseSchema thinks it is in Maya mode, forgot to pass 'mobu=1' arg?"
                    )
                self.filePath = Path(sceneName())
                if not self.filePath:
                    self.filePath = None
                elif self.filePath.basename() == 'untitled.ma':
                    self.filePath = None

        # if no team passed, use first team listed in globalVariables.py
        if not team:
            team = gv.teamA

        #Parse the schema file
        relPath = (os.path.dirname(__file__).replace('\\', '/').replace(
            'python/common/fileIO', 'schemas/'))
        self.xmlContent = ET.parse(relPath + team + '.xml')

        #Gather all global headers
        self.coreList = self.xmlContent.getiterator('Core')[0]
        self.characterList = self.xmlContent.getiterator('Character')[0]
        self.environmentList = self.xmlContent.getiterator('Environment')[0]
        self.exportList = self.xmlContent.getiterator('Export')[0]
        self.areaList = self.xmlContent.getiterator('Areas')[0]
        self.mayaList = self.xmlContent.getiterator('Maya')[0]
        self.mobuList = self.xmlContent.getiterator('MoBu')[0]
        self.team = team

        # Read in the asset hub xml section
        if self.team == gv.teamA:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]
            self.assetHubList = self.xmlContent.getiterator('AssetHubUi')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(
                self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(
                self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

        if self.team == gv.teamB:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(
                self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(
                self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

        if self.team == gv.teamC:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(
                self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(
                self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

    def getMayaDir(self, attr):
        return eval(self.mayaList.get(attr))

    def getMoBuDir(self, attr):
        return eval(self.mobuList.get(attr))

    @property
    def artRoot(self):
        return self.getMayaDir('artRoot')

    @property
    def animationsRoot(self):
        return self.getMoBuDir('animationsRoot')

    @property
    def environmentRoot(self):
        return self.getMayaDir('environmentRoot')

    @property
    def characterRoot(self):
        return self.getMayaDir('characterRoot')

    def getUnitTestSource(self):
        return '%s/python/tests/source/' % gv.toolsLocation

    def getWellFormed(self, varName='', listName='Rigging'):

        if not listName.__class__ == str and listName.__module__ == 'xml.etree.ElementTree':
            self.list = listName
        else:
            self.list = self.xmlContent.getiterator(listName)
            if not self.list:
                logger.error(
                    'Failed to find list named "%s" in xml file: %s, wrong team? "%s"'
                    % (listName, self.xmlContent, self.team))
                return
            #assert(len(self.list) > 0), logger.error('Failed to find list named "%s" in xml file: %s, wrong team? "%s"' % (listName, self.xmlContent, self.team))
            self.list = self.list[0]

        for under in self.list.getiterator():
            if under.get('name') == varName:
                result = under.get('value')
                if re.search('\.', result):
                    result = float(result)
                return result

    def setFilePath(self, filePath):
        self.filePath = Path(filePath)

    def setTeam(self, team):
        self.team = team

    def findAnimationFolder(self, team):
        self.replace(self.characterList.get("AnimationFolderKey"), '')
class ParseSchema(object):
    """ Super class that parses all necessary content that can be parsed on a global level """

    def __init__(self, filePath='', team='', mobu=0, **kwargs):
        super(ParseSchema, self).__init__()
        self.filePath = filePath

        if not filePath:
            if mobu:
                # get sceneName
                from pyfbsdk import FBApplication  # @UnresolvedImport

                self.filePath = Path(FBApplication().FBXFileName.replace('\\', '/'))
                if not self.filePath:
                    self.filePath = None
                elif self.filePath.basename() == '':
                    self.filePath = None
            else:
                try:
                    from pymel.core import sceneName
                except ImportError:
                    sceneName = None
                    logger.errorDialog("ParseSchema thinks it is in Maya mode, forgot to pass 'mobu=1' arg?")
                self.filePath = Path(sceneName())
                if not self.filePath:
                    self.filePath = None
                elif self.filePath.basename() == 'untitled.ma':
                    self.filePath = None

        # if no team passed, use first team listed in globalVariables.py
        if not team:
            team = gv.teamA

        #Parse the schema file
        relPath = (os.path.dirname(__file__)
                   .replace('\\', '/')
                   .replace('python/common/fileIO', 'schemas/'))
        self.xmlContent = ET.parse(relPath + team + '.xml')

        #Gather all global headers
        self.coreList = self.xmlContent.getiterator('Core')[0]
        self.characterList = self.xmlContent.getiterator('Character')[0]
        self.environmentList = self.xmlContent.getiterator('Environment')[0]
        self.exportList = self.xmlContent.getiterator('Export')[0]
        self.areaList = self.xmlContent.getiterator('Areas')[0]
        self.mayaList = self.xmlContent.getiterator('Maya')[0]
        self.mobuList = self.xmlContent.getiterator('MoBu')[0]
        self.team = team


        # Read in the asset hub xml section
        if self.team == gv.teamA:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]
            self.assetHubList = self.xmlContent.getiterator('AssetHubUi')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

        if self.team == gv.teamB:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

        if self.team == gv.teamC:
            # Added headers
            self.riggingList = self.xmlContent.getiterator('Rigging')[0]

            # Self attributes
            self.fbxModels = eval(self.mobuList.get("FBXmodels"))
            self.retargetProcessing = eval(self.mobuList.get("retargetProcessing"))
            self.targetChar = eval(self.mobuList.get("targetCharacter"))
            self.sourceRetargetChar = eval(self.mobuList.get("sourceRetargetCharacters"))
            self.targetCharNode = self.mobuList.get("targetCharacterNode")

    def getMayaDir(self, attr):
        return eval(self.mayaList.get(attr))

    def getMoBuDir(self, attr):
        return eval(self.mobuList.get(attr))

    @property
    def artRoot(self):
        return self.getMayaDir('artRoot')

    @property
    def animationsRoot(self):
        return self.getMoBuDir('animationsRoot')

    @property
    def environmentRoot(self):
        return self.getMayaDir('environmentRoot')

    @property
    def characterRoot(self):
        return self.getMayaDir('characterRoot')

    def getUnitTestSource(self):
        return '%s/python/tests/source/' % gv.toolsLocation

    def getWellFormed(self, varName='', listName='Rigging'):

        if not listName.__class__ == str and listName.__module__ == 'xml.etree.ElementTree':
            self.list = listName
        else:
            self.list = self.xmlContent.getiterator(listName)
            if not self.list:
                logger.error('Failed to find list named "%s" in xml file: %s, wrong team? "%s"' % (
                    listName, self.xmlContent, self.team))
                return
            #assert(len(self.list) > 0), logger.error('Failed to find list named "%s" in xml file: %s, wrong team? "%s"' % (listName, self.xmlContent, self.team))
            self.list = self.list[0]

        for under in self.list.getiterator():
            if under.get('name') == varName:
                result = under.get('value')
                if re.search('\.', result):
                    result = float(result)
                return result

    def setFilePath(self, filePath):
        self.filePath = Path(filePath)

    def setTeam(self, team):
        self.team = team

    def findAnimationFolder(self, team):
        self.replace(self.characterList.get("AnimationFolderKey"), '')