Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
    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()
Beispiel #5
0
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)
Beispiel #6
0
 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)
Beispiel #7
0
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
Beispiel #8
0
 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)
Beispiel #9
0
 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()
Beispiel #10
0
def cmd_list(settings):
    sa = Node.get_session("default", settings.dbref)
    for t in Node.all():
        print t, t.date_added, t.date_updated
Beispiel #11
0
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)
Beispiel #12
0
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)