def do_work(self, work_list): "Process the work units and return their status." # Setup result = [] pref_mrx = MRXpath("/status/worker[@id='fetcher']") for wu in work_list: if len(wu) != 0: if wu[0].tag not in ["bundle", "config"]: msg = "Work unit of type: " + wu[0].tag msg += " not understood by fetcher. Failing." l.emsg(msg) res = etree.Element("wu", id=wu.attrib["id"], status="error", message=msg) continue wu_mrx = MRXpath(wu.attrib["id"]) if wu_mrx.name() == "config": res = etree.Element("wu", id=wu.attrib["id"], status="success") else: operator = "_{}".format(wu.attrib["op"]) res = getattr(self, operator)(wu) msg = "Bundle processed: " + wu.attrib["id"] msg += " result: " + res.attrib["status"] l.dmsg(msg) result.append(res) # Finished all work. Write config file if changed return result
def do_work(self, wus): results = [] for wu in wus: wumrx = MRXpath(wu.get("id")) if wumrx.name() == "installedVersion": if wu.get("op") == "add" or wu.get("op") == "deepmod": # Ignore ordering differences if self.generated_iv is None: self.generate_status() topleft = etree.Element("top") topright = etree.Element("top") topleft.append(copy.deepcopy(wu[0])) topright.append(copy.deepcopy(self.generated_iv)) comp = xmltools.XMLCompare(topleft, topright) if comp.bystate["left"] | comp.bystate["right"]: # Something material changed self.self_update(wu) else: # Just an order change - pretend success results.append(etree.Element("wu", id=wu.get("id"), status="success")) elif wu.get("op") == "remove": # pretend success results.append(etree.Element("wu", id=wu.get("id"), status="success")) else: raise Exception("shouldn't get {} wu for installedVersion".format(wu.get("op"))) else: # Nothing to do: report success results.append(etree.Element("wu", id=wu.get("id"), status="success")) return results
def test_name_id(self): mrx = MRXpath('/a/b/c[\'/d/e[@id="1"]\']') self.assertEqual(mrx.name(), "c") self.assertEqual(mrx.id(), '/d/e[@id="1"]')