コード例 #1
0
ファイル: notebook_speed.py プロジェクト: bdabelow/keepnote
    def test_new_node(self):
        
        clean_dir("test/tmp/notebook_new_node")
        shutil.copytree("test/data/notebook-v6",
                        "test/tmp/notebook_new_node")

        book = notebook.NoteBook()
        book.load("test/tmp/notebook_new_node")
        for n in book.index_all(): pass

        start = time.time()

        n = book.get_node_by_id("76363514-ac2c-4090-a348-58aa1721db68")
        print n
        for i in range(100):
            print i
            notebook.new_page(n, str(i))

        t = time.time() - start
        print "seconds: ", t
        book.close()
コード例 #2
0
    def test_new_node(self):

        clean_dir("test/tmp/notebook_new_node")
        shutil.copytree("test/data/notebook-v6", "test/tmp/notebook_new_node")

        book = notebook.NoteBook()
        book.load("test/tmp/notebook_new_node")
        for n in book.index_all():
            pass

        start = time.time()

        n = book.get_node_by_id("76363514-ac2c-4090-a348-58aa1721db68")
        print(n)
        for i in range(100):
            print(i)
            notebook.new_page(n, str(i))

        t = time.time() - start
        print("seconds: ", t)
        book.close()
コード例 #3
0
    def test_notebook_move_deja_vu(self):
        """Move a unicode titled node."""
        book = notebook.NoteBook()
        book.load(_notebook_file)

        deja = notebook.new_page(book, u'Déjà vu again')
        nodex = book.get_node_by_id(self._pagex_nodeid)
        deja.move(nodex)

        # clean up.
        deja.delete()

        book.close()
コード例 #4
0
    def test_notebook_move_deja_vu(self):
        """Move a unicode titled node."""
        book = notebook.NoteBook()
        book.load(_notebook_file)

        deja = notebook.new_page(book, u'Déjà vu again')
        nodex = book.get_node_by_id(self._pagex_nodeid)
        deja.move(nodex)

        # clean up.
        deja.delete()

        book.close()
コード例 #5
0
    def setUpClass(cls):

        # Create a simple notebook to test against.
        clean_dir(_notebook_file)
        cls._notebook = book = notebook.NoteBook()
        book.create(_notebook_file)

        # create simple nodes
        page1 = notebook.new_page(book, 'Page 1')
        pagea = notebook.new_page(page1, 'Page A')
        write_content(pagea, 'hello world')
        pageb = notebook.new_page(page1, 'Page B')
        write_content(pageb, 'why hello, what is new?')
        pagec = notebook.new_page(page1, 'Page C')
        write_content(pagec, 'brand new world')

        pagex = notebook.new_page(pageb, 'Page X')
        cls._pagex_nodeid = pagex.get_attr('nodeid')

        notebook.new_page(book, 'Page 2')

        notebook.new_page(book, 'Page 3')
        book.close()
コード例 #6
0
    def setUpClass(cls):

        # Create a simple notebook to test against.
        clean_dir(_notebook_file)
        cls._notebook = book = notebook.NoteBook()
        book.create(_notebook_file)

        # create simple nodes
        page1 = notebook.new_page(book, 'Page 1')
        pagea = notebook.new_page(page1, 'Page A')
        write_content(pagea, 'hello world')
        pageb = notebook.new_page(page1, 'Page B')
        write_content(pageb, 'why hello, what is new?')
        pagec = notebook.new_page(page1, 'Page C')
        write_content(pagec, 'brand new world')

        pagex = notebook.new_page(pageb, 'Page X')
        cls._pagex_nodeid = pagex.get_attr('nodeid')

        notebook.new_page(book, 'Page 2')

        notebook.new_page(book, 'Page 3')
        book.close()
コード例 #7
0
ファイル: viewer.py プロジェクト: gemagomez/keepnote
    def new_node(self, kind, pos, parent=None):

        if parent is None:
            parent = self._notebook

        if pos == "sibling" and parent.get_parent() is not None:
            index = parent.get_attr("order") + 1
            parent = parent.get_parent()
        else:
            index = None

        if kind == notebooklib.CONTENT_TYPE_DIR:
            node = parent.new_child(notebooklib.CONTENT_TYPE_DIR,
                                    notebooklib.DEFAULT_DIR_NAME,
                                    index)
        else:
            node = notebooklib.new_page(
                parent, title=notebooklib.DEFAULT_PAGE_NAME, index=index)

        return node
コード例 #8
0
ファイル: viewer.py プロジェクト: uid-root/keepnote
    def new_node(self, kind, pos, parent=None):

        if parent is None:
            parent = self._notebook

        if pos == "sibling" and parent.get_parent() is not None:
            index = parent.get_attr("order") + 1
            parent = parent.get_parent()
        else:
            index = None

        if kind == notebooklib.CONTENT_TYPE_DIR:
            node = parent.new_child(notebooklib.CONTENT_TYPE_DIR,
                                    notebooklib.DEFAULT_DIR_NAME, index)
        else:
            node = notebooklib.new_page(parent,
                                        title=notebooklib.DEFAULT_PAGE_NAME,
                                        index=index)

        return node
コード例 #9
0
 def test_create_unicode_node(self):
     """Create a node with a unicode title."""
     book = notebook.NoteBook()
     book.load(_notebook_file)
     notebook.new_page(book, u'Déjà vu')
     book.close()
コード例 #10
0
def make_notebook(node, children):
    for child in children:
        name = child[0]
        node2 = notebook.new_page(node, name)
        make_notebook(node2, child[1:])
コード例 #11
0
    def _test_notebook(self, conn, filename):

        # initialize a notebook
        book1 = notebook.NoteBook()
        book1.create(filename, conn)
        book1.set_attr("title", "root")

        # populate book
        for i in range(5):
            node = notebook.new_page(book1, "a%d" % i)
            for j in range(2):
                notebook.new_page(node, "b%d-%d" % (i, j))

        expected = """\
root
  a0
    b0-0
    b0-1
  a1
    b1-0
    b1-1
  a2
    b2-0
    b2-1
  a3
    b3-0
    b3-1
  a4
    b4-0
    b4-1
  Trash
"""
        # assert structure is correct.
        out = StringIO()
        display_notebook(book1, out=out)
        self.assertEqual(out.getvalue(), expected)

        # edit book
        nodeid = book1.search_node_titles("a1")[0][0]
        node1 = book1.get_node_by_id(nodeid)

        nodeid = book1.search_node_titles("b3-0")[0][0]
        node2 = book1.get_node_by_id(nodeid)

        node1.move(node2)

        expected = """\
root
  a0
    b0-0
    b0-1
  a2
    b2-0
    b2-1
  a3
    b3-0
      a1
        b1-0
        b1-1
    b3-1
  a4
    b4-0
    b4-1
  Trash
"""

        # Assert new structure.
        out = StringIO()
        display_notebook(book1, out=out)
        self.assertEqual(out.getvalue(), expected)

        # Assert that file contents are provided.
        self.assertEqual(node1.open_file("page.html").read(),
                         notebook.BLANK_NOTE)
コード例 #12
0
 def make_notebook(node, children):
     for child in children:
         name = child[0]
         node2 = notebook.new_page(node, name)
         make_notebook(node2, child[1:])
コード例 #13
0
    def _test_notebook(self, conn, filename):

        # initialize a notebook
        book1 = notebook.NoteBook()
        book1.create(filename, conn)
        book1.set_attr("title", "root")

        # populate book
        for i in range(5):
            node = notebook.new_page(book1, "a%d" % i)
            for j in range(2):
                notebook.new_page(node, "b%d-%d" % (i, j))

        expected = """\
root
  a0
    b0-0
    b0-1
  a1
    b1-0
    b1-1
  a2
    b2-0
    b2-1
  a3
    b3-0
    b3-1
  a4
    b4-0
    b4-1
  Trash
"""
        # assert structure is correct.
        out = StringIO()
        display_notebook(book1, out=out)
        self.assertEqual(out.getvalue(), expected)

        # edit book
        nodeid = book1.search_node_titles("a1")[0][0]
        node1 = book1.get_node_by_id(nodeid)

        nodeid = book1.search_node_titles("b3-0")[0][0]
        node2 = book1.get_node_by_id(nodeid)

        node1.move(node2)

        expected = """\
root
  a0
    b0-0
    b0-1
  a2
    b2-0
    b2-1
  a3
    b3-0
      a1
        b1-0
        b1-1
    b3-1
  a4
    b4-0
    b4-1
  Trash
"""

        # Assert new structure.
        out = StringIO()
        display_notebook(book1, out=out)
        self.assertEqual(out.getvalue(), expected)

        # Assert that file contents are provided.
        self.assertEqual(
            node1.open_file("page.html").read(), notebook.BLANK_NOTE)
コード例 #14
0
 def test_create_unicode_node(self):
     """Create a node with a unicode title."""
     book = notebook.NoteBook()
     book.load(_notebook_file)
     notebook.new_page(book, u'Déjà vu')
     book.close()