Exemplo n.º 1
0
	def runTest(self):
		for creator in self.creators:
			thumbdir = Dir(self.create_tmp_dir(creator.__name__))

			dir = Dir('./data/pixmaps')
			for i, basename in enumerate(dir.list()):
				file = dir.file(basename)
				thumbfile = thumbdir.file('thumb--' + basename)

				self.assertFalse(thumbfile.exists())
				pixbuf = creator(file, thumbfile, THUMB_SIZE_NORMAL)
				self.assertIsInstance(pixbuf, gtk.gdk.Pixbuf)
				self.assertTrue(thumbfile.exists())

				pixbuf = gtk.gdk.pixbuf_new_from_file(thumbfile.encodedpath)
				self.assertEqual(pixbuf.get_option('tEXt::Thumb::URI'), file.uri)
				self.assertTrue(pixbuf.get_option('tEXt::Thumb::URI').startswith('file:///'))
					# Specific requirement of spec to use file:/// and not file://localhost/
				self.assertEqual(int(pixbuf.get_option('tEXt::Thumb::MTime')), int(file.mtime()))

			self.assertTrue(i > 3)

			thumbfile = thumbdir.file('thumb-test.txt')
			self.assertRaises(
				ThumbnailCreatorFailure,
				creator, File('./README.txt'), thumbfile, THUMB_SIZE_NORMAL
			)
Exemplo n.º 2
0
def list_plugins():
	'''List available plugin module names

	@returns: a set of available plugin names that can be loaded
	using L{get_plugin_class()}.
	'''
	# Only listing folders in __path__ because this parameter determines
	# what folders will considered when importing sub-modules of the
	# this package once this module is loaded.

	plugins = set()

	for dir in __path__:
		dir = Dir(dir)
		for candidate in dir.list(): # returns [] if dir does not exist
			if candidate.startswith('_') or candidate == 'base':
				continue
			elif candidate.endswith('.py'):
				#~ print '>> FOUND %s.py in %s' % (candidate, dir.path)
				plugins.add(candidate[:-3])
			elif zim.fs.isdir(dir.path+'/'+candidate) \
			and os.path.exists(dir.path+'/'+candidate+'/__init__.py'):
				#~ print '>> FOUND %s/__init__.py in %s' % (candidate, dir.path)
				plugins.add(candidate)
			else:
				pass

	return sorted(plugins)
Exemplo n.º 3
0
	def runTest(self):
		dir = Dir('./data/pixmaps')
		for i, filename in enumerate(dir.list()):
			file = dir.file(filename)
			icon = get_mime_icon(file, 128)
			self.assertIsInstance(icon, GdkPixbuf.Pixbuf)
			desc = get_mime_description(file.get_mimetype())
			self.assertIsInstance(desc, str)
			self.assertTrue(len(desc) > 5)

		self.assertTrue(i > 3)
Exemplo n.º 4
0
    def runTest(self):
        dir = Dir('./data/pixmaps')
        for i, filename in enumerate(dir.list()):
            file = dir.file(filename)
            icon = get_mime_icon(file, THUMB_SIZE_NORMAL)
            self.assertIsInstance(icon, gtk.gdk.Pixbuf)
            desc = get_mime_description(file.get_mimetype())
            self.assertIsInstance(desc, basestring)
            self.assertTrue(len(desc) > 5)

        self.assertTrue(i > 3)
Exemplo n.º 5
0
	def get_folder(self):
		dir = Dir(self.uistate['output_folder'])
		if dir.exists() and len(dir.list()) > 0:
			ok = QuestionDialog(self, (
				_('Folder exists: %s') % dir.path, # T: message heading
				_('Folder already exists and has content, '
				  'exporting to this folder may overwrite '
				  'existing files. '
				  'Do you want to continue?' ) # T: detailed message, answers are Yes and No
			) ).run()
			if not ok:
				return None
		return dir
Exemplo n.º 6
0
	def get_folder(self):
		dir = Dir(self.uistate['output_folder'])
		if dir.exists() and len(dir.list()) > 0:
			ok = QuestionDialog(self, (
				_('Folder exists: %s') % dir.path, # T: message heading
				_('Folder already exists and has content, '
				  'exporting to this folder may overwrite '
				  'existing files. '
				  'Do you want to continue?') # T: detailed message, answers are Yes and No
			)).run()
			if not ok:
				return None
		return dir
Exemplo n.º 7
0
	def testQueue(self):
		queue = ThumbnailQueue()
		self.assertTrue(queue.queue_empty())

		# Test input / output
		queue.queue_thumbnail_request(File('./README.txt'), 64)
			# put an error in the queue

		dir = Dir('./data/pixmaps')
		pixmaps = set()
		for basename in dir.list():
			file = dir.file(basename)
			pixmaps.add(file)
			queue.queue_thumbnail_request(file, 64)

		self.assertFalse(queue.queue_empty())

		with tests.LoggingFilter('zim.plugins.attachmentbrowser', 'Exception'):
			queue.start()

			seen = set()
			i = len(pixmaps)
			while i > 0:
				i -= 1
				file, size, thumbfile, pixbuf, mtime = queue.get_ready_thumbnail(block=True)
				seen.add(file)
				self.assertEqual(size, 64)
				self.assertTrue(thumbfile.exists())
				self.assertIsInstance(pixbuf, gtk.gdk.Pixbuf)
				self.assertEqual(mtime, file.mtime())

		self.assertEqual(seen, pixmaps)

		# Test clear
		self.assertTrue(queue.queue_empty())
		for file in pixmaps:
			queue.queue_thumbnail_request(file, 64)
		self.assertFalse(queue.queue_empty())
		queue.start()
		time.sleep(0.1)
		queue.clear_queue()
		self.assertTrue(queue.queue_empty())
Exemplo n.º 8
0
def list_plugins():
	'''Returns a set of available plugin names'''
	# FIXME how should this work for e.g. for python eggs ??
	plugins = set()
	for dir in sys.path:
		dir = Dir((dir, 'zim', 'plugins'))
		if not dir.exists():
			continue
		for candidate in dir.list():
			if candidate.startswith('_'):
				continue
			elif candidate.endswith('.py'):
				plugins.add(candidate[:-3])
			elif os.path.isdir(dir.path+'/'+candidate) \
			and os.path.exists(dir.path+'/'+candidate+'/__init__.py'):
				plugins.add(candidate)
			else:
				pass

	return plugins
Exemplo n.º 9
0
    def list_installed_plugins(klass):
        '''Lists plugin names for all installed plugins
		@returns: a set of plugin names
		'''
        # List "zim.plugins" sub modules based on __path__ because this
        # parameter determines what folders will considered when importing
        # sub-modules of the this package once this module is loaded.
        plugins = set()
        for dir in __path__:
            dir = Dir(dir)
            for candidate in dir.list():  # returns [] if dir does not exist
                if candidate.startswith('_') or candidate == 'base':
                    continue
                elif candidate.endswith('.py'):
                    plugins.add(candidate[:-3])
                elif zim.fs.isdir(dir.path+'/'+candidate) \
                and os.path.exists(dir.path+'/'+candidate+'/__init__.py'):
                    plugins.add(candidate)
                else:
                    pass

        return plugins
Exemplo n.º 10
0
    def get_exporter(self, page):
        from zim.fs import File, Dir
        from zim.export import \
         build_mhtml_file_exporter, \
         build_single_file_exporter, \
         build_page_exporter, \
         build_notebook_exporter

        format = self.opts.get('format', 'html')
        if not 'output' in self.opts:
            raise UsageError(_('Output location needed for export')
                             )  # T: error in export command
        output = Dir(self.opts['output'])
        if not output.isdir():
            output = File(self.opts.get('output'))
        template = self.opts.get('template', 'Default')

        if output.exists() and not self.opts.get('overwrite'):
            if output.isdir():
                if len(output.list()) > 0:
                    raise Error(
                        _('Output folder exists and not empty, specify "--overwrite" to force export'
                          ))  # T: error message for export
                else:
                    pass
            else:
                raise Error(
                    _('Output file exists, specify "--overwrite" to force export'
                      ))  # T: error message for export

        if format == 'mhtml':
            self.ignore_options('index-page')
            if output.isdir():
                raise UsageError(_('Need output file to export MHTML')
                                 )  # T: error message for export

            exporter = build_mhtml_file_exporter(
                output,
                template,
                document_root_url=self.opts.get('root-url'),
            )
        elif page:
            self.ignore_options('index-page')
            if output.exists() and output.isdir():
                ext = 'html'
                output = output.file(page.basename) + '.' + ext

            if self.opts.get('singlefile'):
                exporter = build_single_file_exporter(
                    output,
                    format,
                    template,
                    namespace=page,
                    document_root_url=self.opts.get('root-url'),
                )
            else:
                exporter = build_page_exporter(
                    output,
                    format,
                    template,
                    page,
                    document_root_url=self.opts.get('root-url'),
                )
        else:
            if not output.exists():
                output = Dir(output.path)
            elif not output.isdir():
                raise UsageError(
                    _('Need output folder to export full notebook')
                )  # T: error message for export

            exporter = build_notebook_exporter(
                output,
                format,
                template,
                index_page=self.opts.get('index-page'),
                document_root_url=self.opts.get('root-url'),
            )

        return exporter
Exemplo n.º 11
0
	def get_exporter(self, page):
		from zim.fs import File, Dir
		from zim.export import \
			build_mhtml_file_exporter, \
			build_single_file_exporter, \
			build_page_exporter, \
			build_notebook_exporter

		format = self.opts.get('format', 'html')
		if not 'output' in self.opts:
			raise UsageError, _('Output location needed for export') # T: error in export command
		output = Dir(self.opts['output'])
		if not output.isdir():
			output = File(self.opts.get('output'))
		template = self.opts.get('template', 'Default')

		if output.exists() and not self.opts.get('overwrite'):
			if output.isdir():
				if len(output.list()) > 0:
					raise Error, _('Output folder exists and not empty, specify "--overwrite" to force export')  # T: error message for export
				else:
					pass
			else:
				raise Error, _('Output file exists, specify "--overwrite" to force export')  # T: error message for export

		if format == 'mhtml':
			self.ignore_options('index-page')
			if output.isdir():
				raise UsageError, _('Need output file to export MHTML') # T: error message for export

			exporter = build_mhtml_file_exporter(
				output, template,
				document_root_url=self.opts.get('root-url'),
			)
		elif page:
			self.ignore_options('index-page')
			if output.exists() and output.isdir():
				ext = 'html'
				output = output.file(page.basename) + '.' + ext

			if self.opts.get('singlefile'):
				exporter = build_single_file_exporter(
					output, format, template, namespace=page,
					document_root_url=self.opts.get('root-url'),
				)
			else:
				exporter = build_page_exporter(
					output, format, template, page,
					document_root_url=self.opts.get('root-url'),
				)
		else:
			if not output.exists():
				output = Dir(output.path)
			elif not output.isdir():
				raise UsageError, _('Need output folder to export full notebook') # T: error message for export

			exporter = build_notebook_exporter(
				output, format, template,
				index_page=self.opts.get('index-page'),
				document_root_url=self.opts.get('root-url'),
			)

		return exporter