Ejemplo n.º 1
0
	def __init__(self, path, haschildren=False, source=None, format=None):
		assert source and format
		Page.__init__(self, path, haschildren)
		self.source = source
		self.format = format
		self.source.checkoverwrite = True
		self.readonly = not self.source.iswritable()
Ejemplo n.º 2
0
def new_page_from_text(text, format='wiki'):
    from zim.notebook import Path, Page
    from zim.newfs.mock import MockFile, MockFolder
    file = MockFile('/mock/test/page.txt')
    folder = MockFile('/mock/test/page/')
    page = Page(Path('Test'), False, file, folder)
    page.set_parsetree(new_parsetree_from_text(text, format))
    return page
Ejemplo n.º 3
0
 def __init__(self, path, source=None, folder=None, format=None):
     assert source and format
     Page.__init__(self, path, haschildren=folder.exists())
     self.source = source
     self.folder = folder
     self.format = format
     self.readonly = not self.source.iswritable()
     self.properties = None
Ejemplo n.º 4
0
def new_page():
	from zim.notebook import Path, Page
	from zim.newfs.mock import MockFile, MockFolder
	file = MockFile('/mock/test/page.txt')
	folder = MockFile('/mock/test/page/')
	page = Page(Path('roundtrip'), False, file, folder)
	page.set_parsetree(new_parsetree())
	return page
Ejemplo n.º 5
0
	def get_links(self):
		# Optimised version of get_links, just check if we contain
		# links at all - if not don't bother parsing the content,
		# but if we do only trust the parse to get it right
		# (e.g. taking care of verbatim, escapes etc.)
		if not (self._parsetree or self._ui_object) \
		and hasattr(self.format, 'contains_links'):
			#~ print '!! FileStorePage.get_links() Optimisation used'
			if self.source.exists():
				lines = self.source.readlines()
				if self.format.contains_links(lines):
					self._parsetree = self._fetch_parsetree(lines)
					for link in Page.get_links(self):
						yield link
		else:
			for link in Page.get_links(self):
				yield link
Ejemplo n.º 6
0
    def testRenamePageDialogWithHeadingChanges(self):
        '''Test RenamePageDialog's heading auto-change option depending on
		whether we have a changed heading or not.
		'''
        from zim.newfs.mock import MockFile, MockFolder
        file = MockFile('/mock/test/page.txt')
        folder = MockFile('/mock/test/page/')
        page = Page(Path("Test:foo:bar"), False, file, folder)

        tree = ParseTree().fromstring('<zim-tree></zim-tree>')
        tree.set_heading("bar")
        page.set_parsetree(tree)

        self.ui.page = page
        self.ui.notebook.get_page = lambda path: self.ui.page
        dialog = zim.gui.RenamePageDialog(self.ui, path=Path("Test:foo:bar"))
        self.assertTrue(dialog.form['head'])
        tree.set_heading("different")
        dialog = zim.gui.RenamePageDialog(self.ui, path=Path("Test:foo:bar"))
        self.assertFalse(dialog.form['head'])
Ejemplo n.º 7
0
    def testRenamePageDialogWithHeadingChanges(self):
        '''Test RenamePageDialog's heading auto-change option depending on
		whether we have a changed heading or not.
		'''
        tree = ParseTree().fromstring('<zim-tree></zim-tree>')
        tree.set_heading("bar")
        self.ui.page = Page(Path("Test:foo:bar"), parsetree=tree)
        self.ui.notebook.get_page = lambda path: self.ui.page
        dialog = zim.gui.RenamePageDialog(self.ui, path=Path("Test:foo:bar"))
        self.assertTrue(dialog.form['head'])
        tree.set_heading("different")
        dialog = zim.gui.RenamePageDialog(self.ui, path=Path("Test:foo:bar"))
        self.assertFalse(dialog.form['head'])
Ejemplo n.º 8
0
	def export_index(self, index_page, pages):
		# TODO remove hack here, and get rid of IndexPage in current shape from Notebook

		if pages.prefix:
			indexpage = Page(pages.prefix + index_page)
		else:
			indexpage = Page(Path(index_page))

		# Bit of a HACK here - need better support for these index pages
		_page = IndexPage(pages.notebook, pages.prefix) # TODO make more flexible - use pages iter itself
		indexpage.readonly = False
		indexpage.set_parsetree(_page.get_parsetree())
		indexpage.readonly = True

		self.export_page(pages.notebook, indexpage, pages)
Ejemplo n.º 9
0
    def _build_page(self, path, node):
        if node is None:
            text = None
            haschildren = False
        else:
            text = node.text
            haschildren = bool(node.children)

        page = Page(path, haschildren)
        if text:
            page.readonly = False
            page.set_parsetree(self.format.Parser().parse(text))
            page.modified = False
        page.readonly = self.readonly
        return page
Ejemplo n.º 10
0
	def _build_page(self, path, node):
		if node is None:
			text = None
			haschildren = False
		else:
			text = node.text
			haschildren = bool(node.children)

		page = Page(path, haschildren)
		if text:
			page.readonly = False
			page.set_parsetree(self.format.Parser().parse(text))
			page.modified = False
		page.readonly = self.readonly
		return page
Ejemplo n.º 11
0
def new_page():
    from zim.notebook import Path, Page
    page = Page(Path('roundtrip'))
    page.readonly = False
    page.set_parsetree(new_parsetree())
    return page
Ejemplo n.º 12
0
    def runTest(self):
        # Test setting up the server
        start_server_if_not_running()
        server = ServerProxy()
        ack = server.ping()
        self.assertEqual(ack[0], 'ACK')
        start_server_if_not_running()  # Should do nothing..
        server = ServerProxy()
        self.assertEqual(
            server.ping(),
            ack)  # ack has pid, so we know still same server process

        # Test adding a child and interact with it
        child = server.get_proxy(
            RemoteObject('tests.ipc.ChildClass', 'file:///foo'))
        ack = child.ping()
        self.assertEqual(ack[0], 'CHILD')

        child = server.get_proxy(
            RemoteObject('tests.ipc.ChildClass', 'file:///foo'))
        # should not vivicate again, verify by pid in ack
        self.assertEqual(child.ping(), ack)

        # Error handling
        self.assertRaises(ValueError, child.error)

        # Add a second child
        child2 = server.get_proxy(
            RemoteObject('tests.ipc.ChildClass', 'file:///bar'))
        # should not vivicate again, verify by pid in ack
        self.assertNotEqual(child2.ping(), ack)

        children = server.list_objects()
        children.sort(key=lambda c: c.id)
        self.assertEqual(children, [
            RemoteObject('tests.ipc.ChildClass', 'file:///bar'),
            RemoteObject('tests.ipc.ChildClass', 'file:///foo')
        ])

        # Test API for notebooks
        server._notebookklass = 'tests.ipc.ChildClass'  # HACK to test convenience methods
        self.assertEqual(server.list_notebooks(),
                         ['file:///bar', 'file:///foo'])
        proxy = server.get_notebook('file:///foo')
        self.assertEqual(child.ping(), ack)

        # Test these are serializable
        for obj in (
                File('file:///test'),
                NotebookInfo('file:///test'),
                Path('foo'),
                Page(Path('foo')),
                FileStorePage(Path('foo'),
                              File('file:///test'),
                              File('file:///test'),
                              format='wiki'),
        ):
            #~ print ">>> %r" % obj
            re = proxy.echo(obj)
            self.assertEqual(re, obj)

        # send a signal
        n = child.get_n_signals()
        server.emit('notebook-list-changed')
        self.assertEqual(child.get_n_signals(), n + 1)

        # Wrap up
        server.quit()
Ejemplo n.º 13
0
    def export_all(self, dir, callback=None):
        '''Export all pages in the notebook

        Will also copy all attachments and created a folder with icons
        for checkboxes etc. So the resulting folder should contain all
        the notebook information.

        @param dir: a L{Dir} object for the target folder
        @param callback: a callback function that will be called after
        each page being exported with the page object as single argument.
        If the function returns C{False} the export is canceled.

        @returns: C{False} if the action was cancelled, C{True} otherwise
        '''
        logger.info('Exporting notebook to %s', dir)
        self.linker.target_dir = dir # Needed to resolve icons

        # Copy icons
        for name in ('checked-box', 'unchecked-box', 'xchecked-box'):
            icon = data_file('pixmaps/%s.png' % name)
            file = dir.file('_resources/' + name + '.png')
            icon.copyto(file)

        # Copy template resources (can overwrite icons)
        if self.template and self.template.resources_dir \
        and self.template.resources_dir.exists():
            resources = dir.subdir('_resources')
            self.template.resources_dir.copyto(resources)

        # Set special pages
        if self.index_page:
            indexpage = Page(Path(self.index_page))
        else:
            indexpage = None

        pages = {
            'index': indexpage,
            'home': self.notebook.get_home_page(),
        }

        # Export the pages
        prev, current, next = None, None, None
        for page in self.notebook.walk():
            if page.hascontent:
                prev, current, next = current, next, page # shift
                if current:
                    pages['previous'] = prev
                    pages['next'] = next
                    self.export_page(dir, current, pages, use_namespace=True)
                    if callback and not callback(current):
                        logger.warn('Export canceled')
                        return False

        prev, current, next = current, next, None # shift once more
        if current:
            pages['previous'] = prev
            pages['next'] = next
            self.export_page(dir, current, pages, use_namespace=True)
            if callback and not callback(current):
                logger.warn('Export canceled')
                return False

        # Generate index page
        if indexpage:
            _page = IndexPage(self.notebook, Path(':'))
            # Bit of a HACK here - need better support for these index pages
            indexpage.readonly = False
            indexpage.set_parsetree(_page.get_parsetree())
            indexpage.readonly = True
            self.export_page(dir, indexpage, use_namespace=True)

        self.linker.target_dir = None # reset
        logger.info('Export done')
        return True
Ejemplo n.º 14
0
def new_page_from_text(text, format='wiki'):
	from zim.notebook import Path, Page
	page = Page(Path('Test'))
	page.readonly = False
	page.set_parsetree(new_parsetree_from_text(text, format))
	return page
Ejemplo n.º 15
0
def new_page():
	from zim.notebook import Path, Page
	page = Page(Path('roundtrip'))
	page.readonly = False
	page.set_parsetree(new_parsetree())
	return page
Ejemplo n.º 16
0
def new_page_from_text(text, format='wiki'):
    from zim.notebook import Path, Page
    page = Page(Path('Test'))
    page.readonly = False
    page.set_parsetree(new_parsetree_from_text(text, format))
    return page
Ejemplo n.º 17
0
    def export_all(self, dir, callback=None):
        '''Export all pages in the notebook

		Will also copy all attachments and created a folder with icons
		for checkboxes etc. So the resulting folder should contain all
		the notebook information.

		@param dir: a L{Dir} object for the target folder
		@param callback: a callback function that will be called after
		each page being exported with the page object as single argument.
		If the function returns C{False} the export is canceled.

		@returns: C{False} if the action was cancelled, C{True} otherwise
		'''
        logger.info('Exporting notebook to %s', dir)
        self.linker.target_dir = dir  # Needed to resolve icons

        # Copy icons
        for name in ('checked-box', 'unchecked-box', 'xchecked-box'):
            icon = data_file('pixmaps/%s.png' % name)
            file = dir.file('_resources/' + name + '.png')
            icon.copyto(file)

        # Copy template resources (can overwrite icons)
        if self.template and self.template.resources_dir \
        and self.template.resources_dir.exists():
            resources = dir.subdir('_resources')
            self.template.resources_dir.copyto(resources)

        # Set special pages
        if self.index_page:
            indexpage = Page(Path(self.index_page))
        else:
            indexpage = None

        pages = {
            'index': indexpage,
            'home': self.notebook.get_home_page(),
        }

        # Export the pages
        prev, current, next = None, None, None
        for page in self.notebook.walk():
            if page.hascontent:
                prev, current, next = current, next, page  # shift
                if current:
                    pages['previous'] = prev
                    pages['next'] = next
                    self.export_page(dir, current, pages, use_namespace=True)
                    if callback and not callback(current):
                        logger.warn('Export canceled')
                        return False

        prev, current, next = current, next, None  # shift once more
        if current:
            pages['previous'] = prev
            pages['next'] = next
            self.export_page(dir, current, pages, use_namespace=True)
            if callback and not callback(current):
                logger.warn('Export canceled')
                return False

        # Generate index page
        if indexpage:
            _page = IndexPage(self.notebook, Path(':'))
            # Bit of a HACK here - need better support for these index pages
            indexpage.readonly = False
            indexpage.set_parsetree(_page.get_parsetree())
            indexpage.readonly = True
            self.export_page(dir, indexpage, use_namespace=True)

        self.linker.target_dir = None  # reset
        logger.info('Export done')
        return True