def from_xml(self, xml): self._author = xml.find("Author").text self._date = xml.find("Date").text self._size = int(xml.find("Size").text) self._start_cube = XmlCube.from_xml(xml.find("Cubes/Start"), self._size) self._result_cube = XmlCube.from_xml(xml.find("Cubes/Result"), self._size) for element in list(xml.find("Steps")): step = Step() step.from_xml(element) self._codes.append(step)
def get_xml(self): if self._start_cube is None or \ self._result_cube is None or \ len(self._codes) is 0: raise ValueError("Not all needed values have been set") move = ET.Element('Move') author = ET.Element('Author') author.text = self._author move.append(author) date = ET.Element('Date') date.text = self._date move.append(date) size = ET.Element('Size') size.text = str(self._size) move.append(size) cubes = ET.Element('Cubes') cubes.append(XmlCube.get_xml(self._start_cube, "Start")) if self._start_cube_turn is None: start_cube_turn = ET.Element("Start-Turn") start_cube_turn.text = "False" cubes.append(start_cube_turn) else: cubes.append(self._start_cube_turn("Start-Turn")) cubes.append(XmlCube.get_xml(self._result_cube, "Result")) if self._result_cube_turn is None: start_cube_turn = ET.Element("Result-Turn") start_cube_turn.text = "False" cubes.append(start_cube_turn) else: cubes.append(self._result_cube_turn("Result-Turn")) move.append(cubes) steps = ET.Element("Steps") for i in self._codes: steps.append(i.get_xml()) move.append(steps) return move