home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_874 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.4 KB  |  133 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. from calibre.utils.config import config_dir
  10. from calibre.utils.lock import ExclusiveFile
  11. from calibre import sanitize_file_name
  12. from calibre.customize.conversion import OptionRecommendation
  13. config_dir = os.path.join(config_dir, 'conversion')
  14. if not os.path.exists(config_dir):
  15.     os.makedirs(config_dir)
  16.  
  17.  
  18. def name_to_path(name):
  19.     return os.path.join(config_dir, sanitize_file_name(name) + '.py')
  20.  
  21.  
  22. def save_defaults(name, recs):
  23.     path = name_to_path(name)
  24.     raw = str(recs)
  25.     open(path, 'wb').__enter__()
  26.     
  27.     try:
  28.         pass
  29.     finally:
  30.         pass
  31.  
  32.     
  33.     try:
  34.         f = _[1]
  35.         f.write(raw)
  36.     finally:
  37.         pass
  38.  
  39.  
  40.  
  41. def load_defaults(name):
  42.     path = name_to_path(name)
  43.     if not os.path.exists(path):
  44.         open(path, 'wb').close()
  45.     
  46.     
  47.     try:
  48.         f = _[1]
  49.         raw = f.read()
  50.     finally:
  51.         pass
  52.  
  53.     r = GuiRecommendations()
  54.     return r
  55.  
  56.  
  57. def save_specifics(db, book_id, recs):
  58.     raw = str(recs)
  59.     db.set_conversion_options(book_id, 'PIPE', raw)
  60.  
  61.  
  62. def load_specifics(db, book_id):
  63.     raw = db.conversion_options(book_id, 'PIPE')
  64.     r = GuiRecommendations()
  65.     if raw:
  66.         r.from_string(raw)
  67.     
  68.     return r
  69.  
  70.  
  71. def delete_specifics(db, book_id):
  72.     db.delete_conversion_options(book_id, 'PIPE')
  73.  
  74.  
  75. class GuiRecommendations(dict):
  76.     
  77.     def __new__(cls, *args):
  78.         dict.__new__(cls)
  79.         obj = super(GuiRecommendations, cls).__new__(cls, *args)
  80.         obj.disabled_options = set([])
  81.         return obj
  82.  
  83.     
  84.     def to_recommendations(self, level = OptionRecommendation.LOW):
  85.         ans = []
  86.         for key, val in self.items():
  87.             ans.append((key, val, level))
  88.         
  89.         return ans
  90.  
  91.     
  92.     def __str__(self):
  93.         ans = [
  94.             '{']
  95.         for key, val in self.items():
  96.             ans.append('\t' + repr(key) + ' : ' + repr(val) + ',')
  97.         
  98.         ans.append('}')
  99.         return '\n'.join(ans)
  100.  
  101.     
  102.     def from_string(self, raw):
  103.         
  104.         try:
  105.             d = eval(raw)
  106.         except SyntaxError:
  107.             d = None
  108.  
  109.         if d:
  110.             self.update(d)
  111.         
  112.  
  113.     
  114.     def merge_recommendations(self, get_option, level, options, only_existing = False):
  115.         for name in options:
  116.             if only_existing and name not in self:
  117.                 continue
  118.             
  119.             opt = get_option(name)
  120.             if opt is None:
  121.                 continue
  122.             
  123.             if opt.level == OptionRecommendation.HIGH:
  124.                 self[name] = opt.recommended_value
  125.                 self.disabled_options.add(name)
  126.                 continue
  127.             if opt.level > level or name not in self:
  128.                 self[name] = opt.recommended_value
  129.                 continue
  130.         
  131.  
  132.  
  133.