home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import with_statement
- __license__ = 'GPL v3'
- __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
- import os
- import sys
- import zipfile
- from calibre.constants import numeric_version
- from calibre.ptempfile import PersistentTemporaryFile
-
- class Plugin(object):
- supported_platforms = []
- name = 'Trivial Plugin'
- version = (1, 0, 0)
- description = _('Does absolutely nothing')
- author = _('Unknown')
- priority = 1
- minimum_calibre_version = (0, 4, 118)
- can_be_disabled = True
- type = _('Base')
-
- def __init__(self, plugin_path):
- self.plugin_path = plugin_path
- self.site_customization = None
-
-
- def initialize(self):
- pass
-
-
- def customization_help(self, gui = False):
- raise NotImplementedError
-
-
- def temporary_file(self, suffix):
- return PersistentTemporaryFile(suffix)
-
-
- def is_customizable(self):
-
- try:
- self.customization_help()
- return True
- except NotImplementedError:
- return False
-
-
-
- def __enter__(self, *args):
- if self.plugin_path is not None:
- ZipFile = ZipFile
- import calibre.utils.zipfile
- zf = ZipFile(self.plugin_path)
- extensions = []([ x.rpartition('.')[-1].lower() for x in zf.namelist() ])
- zip_safe = True
- for ext in ('pyd', 'so', 'dll', 'dylib'):
- if ext in extensions:
- zip_safe = False
- continue
- []
-
- if zip_safe:
- sys.path.insert(0, self.plugin_path)
- self.sys_insertion_path = self.plugin_path
- else:
- TemporaryDirectory = TemporaryDirectory
- import calibre.ptempfile
- self._sys_insertion_tdir = TemporaryDirectory('plugin_unzip')
- self.sys_insertion_path = self._sys_insertion_tdir.__enter__(*args)
- zf.extractall(self.sys_insertion_path)
- sys.path.insert(0, self.sys_insertion_path)
- zf.close()
-
-
-
- def __exit__(self, *args):
- ip = getattr(self, 'sys_insertion_path', None)
- it = getattr(self, '_sys_insertion_tdir', None)
- if ip in sys.path:
- sys.path.remove(ip)
-
- if hasattr(it, '__exit__'):
- it.__exit__(*args)
-
-
-
-
- class FileTypePlugin(Plugin):
- file_types = set([])
- on_import = False
- on_preprocess = False
- on_postprocess = False
- type = _('File type')
-
- def run(self, path_to_ebook):
- return path_to_ebook
-
-
-
- class MetadataReaderPlugin(Plugin):
- file_types = set([])
- supported_platforms = [
- 'windows',
- 'osx',
- 'linux']
- version = numeric_version
- author = 'Kovid Goyal'
- type = _('Metadata reader')
-
- def __init__(self, *args, **kwargs):
- Plugin.__init__(self, *args, **kwargs)
- self.quick = False
-
-
- def get_metadata(self, stream, type):
- pass
-
-
-
- class MetadataWriterPlugin(Plugin):
- file_types = set([])
- supported_platforms = [
- 'windows',
- 'osx',
- 'linux']
- version = numeric_version
- author = 'Kovid Goyal'
- type = _('Metadata writer')
-
- def __init__(self, *args, **kwargs):
- Plugin.__init__(self, *args, **kwargs)
- self.apply_null = False
-
-
- def set_metadata(self, stream, mi, type):
- pass
-
-
-
- class CatalogPlugin(Plugin):
- resources_path = None
- file_types = set([])
- type = _('Catalog generator')
- cli_options = []
-
- def search_sort_db(self, db, opts):
- db.search(opts.search_text)
- if opts.sort_by:
- db.sort(opts.sort_by, True)
-
- return db.get_data_as_dict(ids = opts.ids)
-
-
- def get_output_fields(self, opts):
- all_fields = set([
- 'author_sort',
- 'authors',
- 'comments',
- 'cover',
- 'formats',
- 'id',
- 'isbn',
- 'pubdate',
- 'publisher',
- 'rating',
- 'series_index',
- 'series',
- 'size',
- 'tags',
- 'timestamp',
- 'title',
- 'uuid'])
- fields = all_fields
- if opts.fields != 'all':
- requested_fields = set(opts.fields.split(','))
- fields = list(all_fields & requested_fields)
- else:
- fields = list(all_fields)
- fields.sort()
- if opts.sort_by and opts.sort_by in fields:
- fields.insert(0, fields.pop(int(fields.index(opts.sort_by))))
-
- return fields
-
-
- def initialize(self):
- builtin_plugins = plugins
- import calibre.customize.builtins
- config = config
- import calibre.customize.ui
- PersistentTemporaryDirectory = PersistentTemporaryDirectory
- import calibre.ptempfile
- if type(self) not in builtin_plugins and self.name not in config['disabled_plugins']:
- files_to_copy = [ '%s.%s' % (self.name.lower(), ext) for ext in [
- 'ui',
- 'py'] ]
- resources = zipfile.ZipFile(self.plugin_path, 'r')
- for file in files_to_copy:
-
- try:
- resources.extract(file, self.resources_path)
- continue
- print ' customize:__init__.initialize(): %s not found in %s' % (file, os.path.basename(self.plugin_path))
- continue
- continue
-
-
- resources.close()
-
-
-
- def run(self, path_to_output, opts, db, ids, notification = None):
- raise NotImplementedError('CatalogPlugin.generate_catalog() default method, should be overridden in subclass')
-
-
-