def markChanged(self,cat,path,alts,counter): global config if path == str(path): path = [path] # prevents string from being processed as a long list self.modify_base(gtk.STATE_NORMAL,gtk.gdk.color_parse(config['altcolor'])) # change background for edited if self not in alts: alts.append(self) setRuletext(counter,len(alts)) end = len(path) value = ["",False] value[1] = True value[0] = self.get_text() root = None goforit = False if cat == 'p': global people root = people elif cat == 'l': global places root = places elif cat == 'c': global cities root = cities elif cat == 's': global states root = states elif cat == 'o': global orgs root = orgs elif cat == 'i': global items root = items else: print "ERR: Invalid category %s passed to markChanged." % cat if root: if config['debug'] > 6: printPretty(root) goforit = preRead(True,cat,path[:-1],end) if goforit: if end == 3: try: root[path[0]][path[1]][path[2]] = value except KeyError: print changeFail(path[2]) return elif end == 4: try: root[path[0]][path[1]][path[2]][path[3]] = value except KeyError: print changeFail(path[3]) return elif end == 5: try: root[path[0]][path[1]][path[2]][path[3]][path[4]] = value except KeyError: print changeFail(path[4]) return elif end == 6: try: root[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]] = value except KeyError: print changeFail(path[5]) return elif end == 7: try: root[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]][path[6]] = value except KeyError: print changeFail(path[6]) return else: say("Path too long: %s" % path) return root[path[0]]['changed'] = True if config['debug'] > 2: print "Value set: %s" % getInf(root.get(path[0]),path[1:]) else: printPretty("markChanged: Invalid path (%s)" % path) debugPath(root,path) return
def preRead(force,cat,path,depth = 0,retries = 0): """Using the global dict for the given category, and given a list of keys 'path' and an integer 'depth', checks a path in the target dict for reading, to a depth of 'depth'. If 'force' is True, the function will build missing tree branches, to allow you to write to the endpoint. Do not call force with a path/depth ending in a list, tuple, or something other than a dict, which this function produces. Call force on one path higher. """ limit = 6 # Lower limit for printing debug messages in this function root = None if cat == 'p': global people root = people elif cat == 'l': global places root = places elif cat == 'c': global cities root = cities elif cat == 's': global states root = states elif cat == 'o': global orgs root = orgs elif cat == 'i': global items root = items else: print "ERR: Invalid category %s passed to markChanged." % cat if not root: print "preRead: Invalid category %s?" % cat return False if depth > len(path): depth = len(path) if depth > 7: depth = 7 if path[0] in root.keys(): if depth <= 1: return True if path[1] in root[path[0]].keys(): if depth <= 2: return True if path[2] in root[path[0]][path[1]].keys(): if depth <= 3: return True if path[3] in root[path[0]][path[1]][path[2]].keys(): if depth <= 4: return True if path[4] in root[path[0]][path[1]][path[2]][path[3]].keys(): if depth <= 5: return True if path[5] in root[path[0]][path[1]][path[2]][path[3]][path[4]].keys(): if depth <= 6: return True if path[6] in root[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]].keys(): return True # Maximum depth reached elif force: root[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]][path[6]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False elif force: root[path[0]][path[1]][path[2]][path[3]][path[4]][path[5]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False elif force: root[path[0]][path[1]][path[2]][path[3]][path[4]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False elif force: root[path[0]][path[1]][path[2]][path[3]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False elif force: root[path[0]][path[1]][path[2]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False elif force: root[path[0]][path[1]] = {} if retries >= depth: force = False return preRead(force,cat,path,depth,retries + 1) else: # Not found, and not forcing it to be found if config['debug'] > limit: debugPath(root,path) return False else: # First level (fileid) can't be generated. if config['debug'] > limit: debugPath(root,path) return False