def undeploy_package(self, zipped_package): working_dir, working_dir_path, undeploy_package_path = self._setup_working_dir() try: unzipped_package_path = Files.createDirectory(working_dir.resolve("undeploy_root")) self._extract_package(zipped_package, str(unzipped_package_path.toAbsolutePath())) package_xml_file = unzipped_package_path.resolve("package.xml") root = ET.parse(str(package_xml_file.toAbsolutePath())).getroot() ns = {'sf': 'http://soap.sforce.com/2006/04/metadata'} version = root.find('sf:version', ns).text Files.copy(package_xml_file, undeploy_package_path.resolve('destructiveChanges.xml')) Files.write(undeploy_package_path.resolve("package.xml"), bytearray(self.empty_package_template(version))) for output in self._execute(working_dir): print output finally: FileUtils.deleteDirectory(working_dir.toFile())
def _setup_working_dir(self): working_dir = Files.createTempDirectory("sfdc_tempdir") working_dir_path = str(working_dir.toAbsolutePath()) package_path = Files.createDirectory(working_dir.resolve("deploy_root")) return working_dir, working_dir_path, package_path