Example #1
0
	def runTest(self):
		'''Test if included notebooks are up to date'''
		from zim.fs import Dir
		from zim.notebook import get_notebook
		for path in ('data/manual', 'HACKING'):
			notebook = get_notebook(Dir(path))
			self.assertTrue(not notebook.needs_upgrade)
Example #2
0
	def open_notebook(self, notebook):
		'''Open a notebook if no notebook was set already.
		'notebook' can be either a string, a File or Dir object or a
		Notebook object.

		If the notebook is a string which also specifies a page the page
		path is returned so it can be handled in a sub-class.
		'''
		from zim.notebook import resolve_notebook, get_notebook, Notebook
		assert self.notebook is None, 'BUG: other notebook opened already'
		assert not notebook is None, 'BUG: no notebook specified'

		logger.debug('Opening notebook: %s', notebook)
		if isinstance(notebook, (basestring, File, Dir)):
			if isinstance(notebook, basestring):
				nb, path = resolve_notebook(notebook)
			else:
				nb, path = notebook, None

			if not nb is None:
				nb = get_notebook(nb)

			if nb is None:
				raise NotebookLookupError, _('Could not find notebook: %s') % notebook
					# T: Error when looking up a notebook

			self.emit('open-notebook', nb)
			return path
		else:
			assert isinstance(notebook, Notebook)
			self.emit('open-notebook', notebook)
			return None
Example #3
0
	def _set_autocomplete(self, notebook):
		if notebook:
			obj = get_notebook(notebook)
			self.form.widgets['namespace'].notebook = obj
			self.form.widgets['page'].notebook = obj
			# Could still be None, e.g. if the notebook folder is not mounted
			logger.debug('Notebook for autocomplete: %s (%s)', obj, notebook)
		else:
			self.form.widgets['namespace'].notebook = None
			self.form.widgets['page'].notebook = None
			logger.debug('Notebook for autocomplete unset')
Example #4
0
    def open_notebook(self, notebook):
        """Open the notebook object

        Open the notebook object for this interface if no notebook was
        set already.

        @param notebook: either a string, a L{File} or L{Dir} object,
        or a L{Notebook} object.

        When the notebook is not given as a Notebook object,
        L{zim.notebook.resolve_notebook()} is used to resolve it.
        If this method returns a page as well it is returned here
        so it can be handled in a sub-class.

        The reason that we call C{resolve_notebook()} from here (instead
        of resolving it first and than calling this method only with a
        notebook object) is that we want to allow active plugins to
        handle the notebook uri before loading the Notebook object
        (e.g. to auto-mount the notebook folder).

        @emits: open-notebook

        @returns: a L{Path} if any was specified in the notebook spec
        """
        from zim.notebook import resolve_notebook, get_notebook, Notebook

        assert self.notebook is None, "BUG: other notebook opened already"
        assert not notebook is None, "BUG: no notebook specified"

        logger.debug("Opening notebook: %s", notebook)
        if isinstance(notebook, (basestring, File, Dir)):
            if isinstance(notebook, basestring):
                nb, path = resolve_notebook(notebook)
            else:
                nb, path = notebook, None

            if not nb is None:
                self.emit("initialize-notebook", nb.uri)
                nb = get_notebook(nb)

            if nb is None:
                raise NotebookLookupError, _("Could not find notebook: %s") % notebook
                # T: Error when looking up a notebook

            self.emit("open-notebook", nb)
            return path
        else:
            assert isinstance(notebook, Notebook)
            self.emit("open-notebook", notebook)
            return None
Example #5
0
	def runTest(self):
		'''Test synchronization'''
		# Test if zim detects pages, that where created with another
		# zim instance and transfered to this instance with
		# dropbox or another file synchronization tool.
		#
		# The scenario is as follow:
		# 1) Page.txt is created in this instance
		# 2) Page/Subpage.txt is created in another instance
		#    and copied into the notebook by the synchronization tool
		# 3) Zim runs a standard index update
		# Outcome should be that Page:Subpage shows up in the index

		# create notebook
		dir = Dir(self.create_tmp_dir())

		init_notebook(dir, name='foo')
		notebook = get_notebook(dir)
		index = notebook.index
		index.update()

		# add page in this instance
		path = Path('Page')
		page =  notebook.get_page(path)
		page.parse('wiki', 'nothing important')
		notebook.store_page(page)

		# check file exists
		self.assertTrue(dir.file('Page.txt').exists())

		# check file is indexed
		self.assertTrue(page in list(index.list_all_pages()))

		# check attachment dir does not exist
		subdir = dir.subdir('Page')
		self.assertEqual(notebook.get_attachments_dir(page), subdir)
		self.assertFalse(subdir.exists())

		for newfile, newpath in (
			(subdir.file('NewSubpage.txt').path, Path('Page:NewSubpage')),
			(dir.file('Newtoplevel.txt').path, Path('Newtoplevel')),
			(dir.file('SomeDir/Dir/Newpage.txt').path, Path('SomeDir:Dir:Newpage')),
		):
			# make sure ctime changed since last index
			import time
			time.sleep(2)

			# create new page without using zim classes
			self.assertFalse(os.path.isfile(newfile))

			mydir = os.path.dirname(newfile)
			if not os.path.isdir(mydir):
				os.makedirs(mydir)

			fh = open(newfile, 'w')
			fh.write('Test 123\n')
			fh.close()

			self.assertTrue(os.path.isfile(newfile))

			# simple index reload
			index.update()

			# check if the new page is found in the index
			self.assertTrue(newpath in list(index.list_all_pages()))
Example #6
0
def get_ctnotebook(path):
    return NotebookWrapper(get_notebook(path))