def check_hash(self, path): """ We saved off a hash of our configuration data the last time we did some package maintenance. Now we're going to load that saved value and compare it with our current config. That will tell us what values have changed. path -- the place to find the configuration hash that was used the last time this package was configured or installed """ old_config = {} difference = {} try: load_string = open(path, "r").read() old_config = yaml_load(load_string) new_config = hash_dictionary(self.data) difference = diff_dicts(old_config, new_config, check_values=True) except IOError: msg = "Could not load saved configuration data in %s" % path Logger.debug(msg) except IndexError: msg = "Could not compare configuration data in %s" % path Logger.debug(msg) except: Logger.warning("Bad json/yaml in file %s" % path) return difference
def save_hash(self, path): """ Save off a hash of our config data for future reference path -- the place to find the configuration hash that was used the last time this package was configured or installed """ try: file_handle = open(path, "w") hash_dict = hash_dictionary(self.data) dump_str = yaml_dump(hash_dict) file_handle.write(dump_str) file_handle.close() except IOError: return FAIL return OK
def test_hash_dictionary(self): d = {"1": "2", 3: ["a", "b", "c"], "hello": 2, "joe": {1:2}} h = mini_utility.hash_dictionary(d) assert h["1"] == 'c81e728d9d4c2f636f067f89cc14862c', "Improper hash value" assert h[3][0] == '0cc175b9c0f1b6a831c399e269772661', "Improper hash value"