def cmd_rename(SRC, DEST): """ folder rename SRC DST Accepts (greedy) globs and relative paths. """ store = Node.start_master_session() src = Node.lookup(SRC) for d in DEST: d = Node.lookup(d)
def cmd_get(REF, settings): """ Retrieve and format node. TODO: full type-specific representation may depend on sub-database. """ sa = Node.get_session("default", settings.dbref) Root, nid = Node.init_ref(REF) node = Root.fetch_instance(nid, sa=sa) reporter.stdout.Node(node)
def cmd_new(NAME, settings): """ """ sa = Node.get_session("default", settings.dbref) node = Node(name=NAME) node.init_defaults() sa.add(node) sa.commit() reporter.stdout.Node(node)
def rsr_assert_path(self, path, sa, opts): """ Put each subnode in a container:: <group>/<group>/<node> """ assert path if sep in path: nodes = [] elems = path.split(sep) # resolve elements to nodes while elems: elem = elems.pop(0) node = Node.fetch(( Node.name == elem, ), sa=sa) nodes += [ node ] # XXX assert GroupNode? # assert path yield dict(path_nodes = nodes) root = nodes.pop(0) while nodes: node = nodes.pop(0) root.subnodes.append( node ) sa.add(root) root = node if opts.rsr_auto_commit: opts.commit()
def cmd_info(settings): for l, v in (("DBRef", settings.dbref), ("Tables in schema", ", ".join(metadata.tables.keys()))): log.std("{green}%s{default}: {bwhite}%s{default}", l, v) # try to connect try: sa = Node.get_session("default", settings.dbref) log.std("{magenta} * {bwhite}DB Connection {default}[{green}OK{default}]") except Exception, e: log.std("{magenta} * {bwhite}DB Connection {default}[{red}Error{default}]: %s", e)
def rsr_nodes(self, sa, *args): "Print existing nodes. " nodes = [] for arg in args: typehint, nodeid = self.deref(arg, sa) # do something with typehint? node = Node.find(( Node.name == nodeid, )) if not node: log.warn("No entry for %s:%s", typehint, nodeid) continue print(node.ntype, node.name) nodes.append(node) yield dict(nodes=nodes)
def cmd_status(SCHEMA, settings): """ Get new nodes from databases, and update subdatabase increment. Possibly this should be in db_sa and work for any master database. Work on Node-subtrees first. """ store = Node.start_master_session() if SCHEMA.endswith('.py'): SCHEMA = SCHEMA[:-3] schema = __import__(SCHEMA) store.init() for session in Node.sessions: print session for model in schema.models: try: print model, model.date_id(None, session) except Exception, e: print e
def rsr_show(self, ref_or_node, sa ): "Print a single node from name or path reference. " if isinstance( ref_or_node, str ): nodetype, localpart = self.deref(ref_or_node, sa) node = Node.find(( Node.name == localpart, )) print(node)
def rsr_remove(self, ref, sa, opts): "Remove a node" node = Node.find(( Node.name == ref, )) sa.delete( node ) if opts.rsr_auto_commit: sa.commit()
def cmd_list(settings): sa = Node.get_session("default", settings.dbref) for t in Node.all(): print t, t.date_added, t.date_updated
def cmd_new(NAME, settings): sa = Node.get_session('default', settings.dbref) cllct = Node(name=NAME) sa.add(cllct) sa.commit() reporter.stdout.Node(cllct)
def cmd_get(REF, settings): sa = Node.get_session('default', settings.dbref) #print Node.byKey(dict(cllct_id=REF)) #print Node.byName(REF) Root, nid = Node.init_ref(REF) print Root.fetch_instance(nid, sa=sa)