def add_objects_not_on_local(self, obj_type): """ Add objects locally which are not present on the slave but on the master. :param obj_type: """ locals = utils.lod_to_dod(self.local_data[obj_type], "uid") remotes = utils.lod_sort_by_key(self.remote_data[obj_type], "depth") for rdata in remotes: # do not add the system if it is not on the transfer list if not rdata["name"] in self.must_include[obj_type]: continue if not rdata["uid"] in locals: creator = getattr(self.api, "new_%s" % obj_type) newobj = creator() newobj.from_dict(utils.revert_strip_none(rdata)) try: self.logger.info("adding %s %s" % (obj_type, rdata["name"])) if not self.api.add_item(obj_type, newobj): self.logger.error("failed to add %s %s" % (obj_type, rdata["name"])) except Exception: utils.log_exc()
def test_lod_sort_by_key(): # Arrange list_of_dicts = [{"a": 3}, {"a": 5}, {"a": 2}] expected_result = [{"a": 2}, {"a": 3}, {"a": 5}] # Act result = utils.lod_sort_by_key(list_of_dicts, "a") # Assert assert expected_result == result
def add_objects_not_on_local(self, obj_type): locals = utils.lod_to_dod(self.local_data[obj_type], "uid") remotes = utils.lod_sort_by_key(self.remote_data[obj_type], "depth") for rdata in remotes: # do not add the system if it is not on the transfer list if not rdata["name"] in self.must_include[obj_type]: continue if not rdata["uid"] in locals: creator = getattr(self.api, "new_%s" % obj_type) newobj = creator() newobj.from_dict(rdata) try: self.logger.info("adding %s %s" % (obj_type, rdata["name"])) if not self.api.add_item( obj_type, newobj, logger=self.logger): self.logger.error("failed to add %s %s" % (obj_type, rdata["name"])) except Exception: utils.log_exc(self.logger)