#!/usr/bin/python -tt import gconf import sys import os def recurse_gconf(client, path, thisdict): stuff = client.all_dirs(path) + client.all_entries(path) for item in stuff: if type(item) == gconf.Entry: thisdict[item.key] = item.value else: thisdict = recurse_gconf(client, item, thisdict) return thisdict def human_entry(value): if value == None: return None else: return value.to_string() def check_skip(k): # FIXME - provide a way of excluding certain paths from being modified # /system/networking, for example exclude_paths = ['/system/networking'] for path in exclude_paths: if k.startswith(path): return True return False def main(newgconfpath): new_source = 'xml:readwrite:%s' % newgconfpath old_path = '%s/.gconf' % os.path.expanduser('~') old_source = 'xml:readwrite:%s' % old_path old_engine = gconf.engine_get_for_address(old_source) new_engine = gconf.engine_get_for_address(new_source) old_gconf = gconf.client_get_for_engine(old_engine) new_gconf = gconf.client_get_for_engine(new_engine) old_entry_dict = recurse_gconf(old_gconf, '/', {}) new_entry_dict = recurse_gconf(new_gconf, '/', {}) del_dict = {} add_dict = {} # if there are things in the old_dict not in the new dict, kill them for k in old_entry_dict.keys(): if check_skip(k): continue if not new_entry_dict.has_key(k): del_dict[k] = 1 continue for (k,v) in new_entry_dict.items(): if check_skip(k): continue # if there are things in the new dict not in the old dict, add them if not old_entry_dict.has_key(k): add_dict[k] = v continue # if the old and new don't match add the new ones old_val = old_entry_dict[k] if old_val == None: old_tup = (type(None), None) else: old_tup = (old_val.type, old_val.to_string()) new_val = new_entry_dict[k] if new_val == None: new_tup = (type(None), None) else: new_tup = (new_val.type, new_val.to_string()) if old_tup != new_tup: add_dict[k] = v mygconf = gconf.client_get_default() # setting this in the running instance for k in del_dict.keys(): mygconf.unset(k) print '- %s' % k for (k,v) in add_dict.items(): if v == None: # nuking these to clean up the paths mygconf.unset(k) continue mygconf.set(k, v) val = human_entry(v) print '! %s = %s' % (k, val) if __name__ == "__main__": if len(sys.argv) < 2: print "usage: diff-gconf.py gconf_dir_to_merge" sys.exit(1) main(sys.argv[1]) sys.exit(0)