def find_missing_children(args,db): children = db.keys("*.children") for widget_with_kids in children: list_of_children = full_list(db, widget_with_kids) for kid in list_of_children: if not db.exists(kid): print("%s is referred to by %s but does not exist" % (kid, widget_with_kids))
def export_session(db, session): pattern = Pattern.Session(session) output = empty_dict_entry_line("sessions", pattern.name) _session_nodes = db.keys("%s.*" % pattern.node) session_nodes = [] for n in _session_nodes: innernode = n.split(".")[2:] session_nodes.append(".".join(innernode)) for node in session_nodes: body = "" name = "%s.%s" % (pattern.node, node) t = db.type(name) title = dbl_dict_entry_line("sessions", pattern.name, node) if t == "hash": d = db.hgetall(name) body = dict_str(d) elif t == "list": l = full_list(db, name) body = list_str(l) elif t == "set": s = db.smembers(name) body = set_str(s) else: body = ' \t"%s"\n' % clean_str(db.get(name)) output += "%s%s" % (title, body) return output
def get_node_data(db, node): nodetype = db.type(node) if nodetype == "hash": return db.hgetall(node) elif nodetype == "set": return Set(db.smembers(node)) elif nodetype == "list": return full_list(db, node) else: return db.get(node)
def export_widget_children(db, widget): pattern = Pattern.Widget(widget) output = "" if db.exists("%s.children" % widget): title = dict_entry_line("tree", pattern.name) children = full_list(db, "%s.children" % pattern.node) strlst = [] for child in children: ptrn = Pattern.Widget(child) strlst.append(ptrn.name) body = list_str(strlst) output = "%s" * 2 % (title, body) return output
def get_node_data(db, node): """ Based on the Redis type of a node, populates a Python container with the requisite data """ nodetype = db.type(node) if nodetype == "hash": return db.hgetall(node) elif nodetype == "set": return Set(db.smembers(node)) elif nodetype == "list": return full_list(db, node) else: return db.get(node)
def export_data(db, data_node): pattern = Pattern.Data(data_node) output = dict_entry_line("data", pattern.name) dtype = db.type(pattern.node) if dtype == "hash": val = db.hgetall(pattern.node) body = dict_str(val) elif dtype == "list": val = full_list(db, pattern.node) body = list_str(val) elif dtype == "set": val = db.smembers(pattern.node) body = set_str(val) else: body = ' \t"%s"\n' % clean_str(db.get(pattern.node)) output += "%s" % (body) return output
def import_list(db, node, data, flags): testing = b.is_set(flags, b.ListStorage.is_test) if testing: b.set_bit(flags, b.ListStorage.assume_yes) if isinstance(data[0], (str,int)): new_list = [] merging = b.is_set(flags, b.ListStorage.is_merge) if merging: no_repeat = b.is_set(flags, b.ListStorage.merge_no_repeat) current_list = r.full_list(db, node) new_list.extend(current_list) for entry in data: if entry in new_list and no_repeat: while entry in new_list: new_list.remove(entry) new_list.append(entry) else: new_list.extend(data) for entry in new_list: if not testing: db.rpush(node, entry) elif isinstance(data[0], dict): if not merging: dictset = db.keys(node+".*") for n in dictset: db.delete(n) dictset = db.keys(node+".*") num = len(dictset) for entry in data: nn = "%s.%d" % (node,num) fl =0 if testing: b.set_bit(fl, b.DictStorage.is_test) if merging: set_bit(fl, b.DictStorage.is_merge) if b.is_set(flags, b.ListStorage.assume_yes): set_bit(fl, b.DictStorage.assume_yes) import_dict(db, nn, data[num], fl) num += 1