home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_711 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  7.7 KB  |  181 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import os
  6. import shutil
  7. from calibre import CurrentDir
  8. from calibre.customize import Plugin
  9.  
  10. class ConversionOption(object):
  11.     
  12.     def __init__(self, name = None, help = None, long_switch = None, short_switch = None, choices = None):
  13.         self.name = name
  14.         self.help = help
  15.         self.long_switch = long_switch
  16.         self.short_switch = short_switch
  17.         self.choices = choices
  18.         if self.long_switch is None:
  19.             self.long_switch = self.name.replace('_', '-')
  20.         
  21.         self.validate_parameters()
  22.  
  23.     
  24.     def validate_parameters(self):
  25.         if re.match('[a-zA-Z_]([a-zA-Z0-9_])*', self.name) is None:
  26.             raise ValueError(self.name + ' is not a valid Python identifier')
  27.         re.match('[a-zA-Z_]([a-zA-Z0-9_])*', self.name) is None
  28.         if not self.help:
  29.             raise ValueError('You must set the help text')
  30.         self.help
  31.  
  32.     
  33.     def __hash__(self):
  34.         return hash(self.name)
  35.  
  36.     
  37.     def __eq__(self, other):
  38.         return hash(self) == hash(other)
  39.  
  40.     
  41.     def clone(self):
  42.         return ConversionOption(name = self.name, help = self.help, long_switch = self.long_switch, short_switch = self.short_switch, choices = self.choices)
  43.  
  44.  
  45.  
  46. class OptionRecommendation(object):
  47.     LOW = 1
  48.     MED = 2
  49.     HIGH = 3
  50.     
  51.     def __init__(self, recommended_value = None, level = LOW, **kwargs):
  52.         self.level = level
  53.         self.recommended_value = recommended_value
  54.         self.option = kwargs.pop('option', None)
  55.         if self.option is None:
  56.             self.option = ConversionOption(**kwargs)
  57.         
  58.         self.validate_parameters()
  59.  
  60.     
  61.     def help(self):
  62.         return self.option.help
  63.  
  64.     help = property(help)
  65.     
  66.     def clone(self):
  67.         return OptionRecommendation(recommended_value = self.recommended_value, level = self.level, option = self.option.clone())
  68.  
  69.     
  70.     def validate_parameters(self):
  71.         if self.option.choices and self.recommended_value not in self.option.choices:
  72.             raise ValueError('OpRec: %s: Recommended value not in choices' % self.option.name)
  73.         self.recommended_value not in self.option.choices
  74.         if not isinstance(self.recommended_value, (int, float, str, unicode)) or self.recommended_value is None:
  75.             raise ValueError('OpRec: %s:' % self.option.name + repr(self.recommended_value) + ' is not a string or a number')
  76.         self.recommended_value is None
  77.  
  78.  
  79.  
  80. class DummyReporter(object):
  81.     
  82.     def __init__(self):
  83.         self.cancel_requested = False
  84.  
  85.     
  86.     def __call__(self, percent, msg = ''):
  87.         pass
  88.  
  89.  
  90.  
  91. class InputFormatPlugin(Plugin):
  92.     type = _('Conversion Input')
  93.     can_be_disabled = False
  94.     supported_platforms = [
  95.         'windows',
  96.         'osx',
  97.         'linux']
  98.     file_types = set([])
  99.     is_image_collection = False
  100.     core_usage = 1
  101.     for_viewer = False
  102.     output_encoding = 'utf-8'
  103.     common_options = set([
  104.         OptionRecommendation(name = 'input_encoding', recommended_value = None, level = OptionRecommendation.LOW, help = _('Specify the character encoding of the input document. If set this option will override any encoding declared by the document itself. Particularly useful for documents that do not declare an encoding or that have erroneous encoding declarations.'))])
  105.     options = set([])
  106.     recommendations = set([])
  107.     
  108.     def __init__(self, *args):
  109.         Plugin.__init__(self, *args)
  110.         self.report_progress = DummyReporter()
  111.  
  112.     
  113.     def get_images(self):
  114.         raise NotImplementedError()
  115.  
  116.     
  117.     def preprocess_html(self, opts, html):
  118.         return html
  119.  
  120.     
  121.     def convert(self, stream, options, file_ext, log, accelerators):
  122.         raise NotImplementedError
  123.  
  124.     
  125.     def __call__(self, stream, options, file_ext, log, accelerators, output_dir):
  126.         log('InputFormatPlugin: %s running' % self.name)
  127.         if hasattr(stream, 'name'):
  128.             log('on', stream.name)
  129.         
  130.         CurrentDir(output_dir).__enter__()
  131.         
  132.         try:
  133.             for x in os.listdir('.'):
  134.                 CurrentDir(output_dir).__exit__ if os.path.isdir(x) else os.remove(x)
  135.             
  136.             ret = self.convert(stream, options, file_ext, log, accelerators)
  137.         finally:
  138.             pass
  139.  
  140.         return ret
  141.  
  142.     
  143.     def postprocess_book(self, oeb, opts, log):
  144.         pass
  145.  
  146.     
  147.     def specialize(self, oeb, opts, log, output_fmt):
  148.         pass
  149.  
  150.  
  151.  
  152. class OutputFormatPlugin(Plugin):
  153.     type = _('Conversion Output')
  154.     can_be_disabled = False
  155.     supported_platforms = [
  156.         'windows',
  157.         'osx',
  158.         'linux']
  159.     file_type = None
  160.     common_options = set([
  161.         OptionRecommendation(name = 'pretty_print', recommended_value = False, level = OptionRecommendation.LOW, help = _('If specified, the output plugin will try to create output that is as human readable as possible. May not have any effect for some output plugins.'))])
  162.     options = set([])
  163.     recommendations = set([])
  164.     
  165.     def __init__(self, *args):
  166.         Plugin.__init__(self, *args)
  167.         self.report_progress = DummyReporter()
  168.  
  169.     
  170.     def convert(self, oeb_book, output, input_plugin, opts, log):
  171.         raise NotImplementedError
  172.  
  173.     
  174.     def is_periodical(self):
  175.         if self.oeb.metadata.publication_type:
  176.             pass
  177.         return unicode(self.oeb.metadata.publication_type[0]).startswith('periodical:')
  178.  
  179.     is_periodical = property(is_periodical)
  180.  
  181.