Beispiel #1
0
    def _update_attributes(self, parent_node: etree.ElementBase) -> None:
        """Updates attributes of element tree with missing attributes and default values"""
        ppj_bool_keys = [
            'Optimize', 'Release', 'Final', 'Anonymize', 'Package', 'Zip'
        ]
        other_bool_keys = ['NoRecurse', 'UseInBuild']

        for node in parent_node.getiterator():
            if node.text:
                node.text = self.parse(node.text.strip())

            if not node.attrib:
                continue

            tag = node.tag.replace('{%s}' % self.ppj_root.ns, '')

            if tag == 'PapyrusProject':
                if 'Game' not in node.attrib:
                    node.set('Game', '')
                if 'Flags' not in node.attrib:
                    node.set('Flags', self.options.flags_path)
                if 'Output' not in node.attrib:
                    node.set('Output', self.options.output_path)
                for key in ppj_bool_keys:
                    if key not in node.attrib:
                        node.set(key, 'False')

            elif tag == 'Packages':
                if 'Output' not in node.attrib:
                    node.set('Output', self.options.package_path)

            elif tag == 'Package':
                if 'Name' not in node.attrib:
                    node.set('Name', self.project_name)
                if 'RootDir' not in node.attrib:
                    node.set('RootDir', self.project_path)

            elif tag in ('Folder', 'Include'):
                if 'NoRecurse' not in node.attrib:
                    node.set('NoRecurse', 'False')

            elif tag == 'ZipFiles':
                if 'Output' not in node.attrib:
                    node.set('Output', self.options.zip_output_path)

            elif tag == 'ZipFile':
                if 'Name' not in node.attrib:
                    node.set('Name', self.project_name)
                if 'RootDir' not in node.attrib:
                    node.set('RootDir', self.project_path)
                if 'Compression' not in node.attrib:
                    node.set('Compression', 'deflate')
                else:
                    node.set('Compression', node.get('Compression').casefold())

            elif tag == 'PreBuildEvent' or tag == 'PostBuildEvent':
                if 'Description' not in node.attrib:
                    node.set('Description', '')
                if 'UseInBuild' not in node.attrib:
                    node.set('UseInBuild', 'True')

            # parse values
            for key, value in node.attrib.items():
                value = value.casefold() in (
                    'true', '1'
                ) if key in ppj_bool_keys + other_bool_keys else self.parse(
                    value)
                node.set(key, str(value))
Beispiel #2
0
    def _update_attributes(self, parent_node: etree.ElementBase) -> None:
        """Updates attributes of element tree with missing attributes and default values"""
        ppj_bool_keys = [
            XmlAttributeName.OPTIMIZE, XmlAttributeName.RELEASE,
            XmlAttributeName.FINAL, XmlAttributeName.ANONYMIZE,
            XmlAttributeName.PACKAGE, XmlAttributeName.ZIP
        ]

        other_bool_keys = [
            XmlAttributeName.NO_RECURSE, XmlAttributeName.USE_IN_BUILD
        ]

        for node in parent_node.getiterator():
            if node.text:
                node.text = self.parse(node.text.strip())

            tag = node.tag.replace('{%s}' % self.ppj_root.ns, '')

            if tag == XmlTagName.PAPYRUS_PROJECT:
                if XmlAttributeName.GAME not in node.attrib:
                    node.set(XmlAttributeName.GAME, '')
                if XmlAttributeName.FLAGS not in node.attrib:
                    node.set(XmlAttributeName.FLAGS, self.options.flags_path)
                if XmlAttributeName.OUTPUT not in node.attrib:
                    node.set(XmlAttributeName.OUTPUT, self.options.output_path)
                for key in ppj_bool_keys:
                    if key not in node.attrib:
                        node.set(key, 'False')

            elif tag == XmlTagName.PACKAGES:
                if XmlAttributeName.OUTPUT not in node.attrib:
                    node.set(XmlAttributeName.OUTPUT,
                             self.options.package_path)

            elif tag == XmlTagName.PACKAGE:
                if XmlAttributeName.NAME not in node.attrib:
                    node.set(XmlAttributeName.NAME, self.project_name)
                if XmlAttributeName.ROOT_DIR not in node.attrib:
                    node.set(XmlAttributeName.ROOT_DIR, self.project_path)

            elif tag in (XmlTagName.FOLDER, XmlTagName.INCLUDE,
                         XmlTagName.MATCH):
                if XmlAttributeName.NO_RECURSE not in node.attrib:
                    node.set(XmlAttributeName.NO_RECURSE, 'False')
                if tag in (XmlTagName.INCLUDE, XmlTagName.MATCH):
                    if XmlAttributeName.PATH not in node.attrib:
                        node.set(XmlAttributeName.PATH, '')
                if tag == XmlTagName.MATCH:
                    if XmlAttributeName.IN not in node.attrib:
                        node.set(XmlAttributeName.IN, os.curdir)
                    if XmlAttributeName.EXCLUDE not in node.attrib:
                        node.set(XmlAttributeName.EXCLUDE, '')

            elif tag == XmlTagName.ZIP_FILES:
                if XmlAttributeName.OUTPUT not in node.attrib:
                    node.set(XmlAttributeName.OUTPUT,
                             self.options.zip_output_path)

            elif tag == XmlTagName.ZIP_FILE:
                if XmlAttributeName.NAME not in node.attrib:
                    node.set(XmlAttributeName.NAME, self.project_name)
                if XmlAttributeName.ROOT_DIR not in node.attrib:
                    node.set(XmlAttributeName.ROOT_DIR, self.project_path)
                if XmlAttributeName.COMPRESSION not in node.attrib:
                    node.set(XmlAttributeName.COMPRESSION, 'deflate')
                else:
                    node.set(XmlAttributeName.COMPRESSION,
                             node.get(XmlAttributeName.COMPRESSION).casefold())

            elif tag in (XmlTagName.PRE_BUILD_EVENT,
                         XmlTagName.POST_BUILD_EVENT,
                         XmlTagName.PRE_IMPORT_EVENT,
                         XmlTagName.POST_IMPORT_EVENT):
                if XmlAttributeName.DESCRIPTION not in node.attrib:
                    node.set(XmlAttributeName.DESCRIPTION, '')
                if XmlAttributeName.USE_IN_BUILD not in node.attrib:
                    node.set(XmlAttributeName.USE_IN_BUILD, 'True')

            # parse values
            for key, value in node.attrib.items():
                value = value.casefold() in (
                    'true', '1'
                ) if key in ppj_bool_keys + other_bool_keys else self.parse(
                    value)
                node.set(key, str(value))