예제 #1
0
    def _run_task(self):
        # Check that path exists
        if not os.path.isdir(self.options["path"]):
            raise TaskOptionsError(
                "The path {} does not exist or is not a directory".format(
                    self.options["path"]))

        # Check that revert_path does not exist
        if os.path.exists(self.options["revert_path"]):
            raise TaskOptionsError(
                "The revert_path {} already exists.  Delete it and try again".
                format(self.options["revert_path"]))

        # Copy path to revert_path
        copy_tree(self.options["path"], self.options["revert_path"])

        # Edit metadata in path
        self.logger.info(
            "Preparing metadata in {0} for unmanaged EE deployment".format(
                self.options["path"]))

        for element in self.elements:
            fname_match, element_name = element.split(":")
            removeXmlElement(element_name, os.path.join(self.options["path"]),
                             fname_match)

        self.logger.info(
            "Metadata in {} is now prepared for unmanaged EE deployment".
            format(self.options["path"]))
예제 #2
0
    def test_removeXmlElement(self):
        with utils.temporary_dir() as d:
            path = os.path.join(d, "test.xml")
            with open(path, "w") as f:
                f.write(
                    '<?xml version="1.0" ?>'
                    '<root xmlns="http://soap.sforce.com/2006/04/metadata">'
                    "<tag>text</tag></root>")

            utils.removeXmlElement("tag", d, "*")

            with open(path, "r") as f:
                result = f.read()
            expected = """<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://soap.sforce.com/2006/04/metadata" />"""
            self.assertEqual(expected, result)
예제 #3
0
    def test_removeXmlElement(self):
        with temporary_dir() as d:
            path = os.path.join(d, 'test.xml')
            with open(path, 'w') as f:
                f.write(
                    '<?xml version="1.0" ?>'
                    '<root xmlns="http://soap.sforce.com/2006/04/metadata">'
                    '<tag>text</tag></root>')

            utils.removeXmlElement('tag', d, '*')

            with open(path, 'r') as f:
                result = f.read()
            expected = ('''<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://soap.sforce.com/2006/04/metadata" />''')
            self.assertEqual(expected, result)
예제 #4
0
    def test_removeXmlElement(self):
        with utils.temporary_dir() as d:
            path = os.path.join(d, "test.xml")
            with open(path, "w") as f:
                f.write(
                    '<?xml version="1.0" ?>'
                    '<root xmlns="http://soap.sforce.com/2006/04/metadata">'
                    "<tag>text</tag></root>"
                )

            utils.removeXmlElement("tag", d, "*")

            with open(path, "r") as f:
                result = f.read()
            expected = """<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://soap.sforce.com/2006/04/metadata" />"""
            self.assertEqual(expected, result)
예제 #5
0
 def test_remove_xml_element_parse_error(self, mock_parse):
     err = ET.ParseError()
     err.msg = "it broke"
     err.lineno = 1
     mock_parse.side_effect = err
     with utils.temporary_dir() as d:
         path = os.path.join(d, "test.xml")
         with open(path, "w") as f:
             f.write(
                 '<?xml version="1.0" ?>'
                 '<root xmlns="http://soap.sforce.com/2006/04/metadata">'
                 "<tag>text</tag></root>")
         try:
             utils.removeXmlElement("tag", d, "*")
         except ET.ParseError as err:
             self.assertEqual(str(err), "it broke (test.xml, line 1)")
         else:
             self.fail("Expected ParseError")
예제 #6
0
 def test_remove_xml_element_parse_error(self, mock_parse):
     err = ET.ParseError()
     err.msg = "it broke"
     err.lineno = 1
     mock_parse.side_effect = err
     with utils.temporary_dir() as d:
         path = os.path.join(d, "test.xml")
         with open(path, "w") as f:
             f.write(
                 '<?xml version="1.0" ?>'
                 '<root xmlns="http://soap.sforce.com/2006/04/metadata">'
                 "<tag>text</tag></root>"
             )
         try:
             utils.removeXmlElement("tag", d, "*")
         except ET.ParseError as err:
             self.assertEqual(str(err), "it broke (test.xml, line 1)")
         else:
             self.fail("Expected ParseError")
예제 #7
0
    def _run_task(self):
        # Check that path exists
        if not os.path.isdir(self.options["path"]):
            raise TaskOptionsError(
                "The path {} does not exist or is not a directory".format(
                    self.options["path"]
                )
            )

        # Check that revert_path does not exist
        if os.path.exists(self.options["revert_path"]):
            raise TaskOptionsError(
                "The revert_path {} already exists.  Delete it and try again".format(
                    self.options["revert_path"]
                )
            )

        # Copy path to revert_path
        copy_tree(self.options["path"], self.options["revert_path"])

        # Edit metadata in path
        self.logger.info(
            "Preparing metadata in {0} for unmanaged EE deployment".format(
                self.options["path"]
            )
        )

        for element in self.elements:
            fname_match, element_name = element.split(":")
            removeXmlElement(
                element_name, os.path.join(self.options["path"]), fname_match
            )

        self.logger.info(
            "Metadata in {} is now prepared for unmanaged EE deployment".format(
                self.options["path"]
            )
        )