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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. import time
  9. import re
  10. from calibre.devices.usbms.driver import USBMS, debug_print
  11. from calibre.devices.prs505 import MEDIA_XML, MEDIA_EXT, CACHE_XML, CACHE_EXT, MEDIA_THUMBNAIL, CACHE_THUMBNAIL
  12. from calibre.devices.prs505.sony_cache import XMLCache
  13. from calibre import __appname__, prints
  14. from calibre.devices.usbms.books import CollectionsBookList
  15.  
  16. class PRS505(USBMS):
  17.     name = 'SONY Device Interface'
  18.     gui_name = 'SONY Reader'
  19.     description = _('Communicate with all the Sony eBook readers.')
  20.     author = 'Kovid Goyal'
  21.     supported_platforms = [
  22.         'windows',
  23.         'osx',
  24.         'linux']
  25.     path_sep = '/'
  26.     booklist_class = CollectionsBookList
  27.     FORMATS = [
  28.         'epub',
  29.         'lrf',
  30.         'lrx',
  31.         'rtf',
  32.         'pdf',
  33.         'txt']
  34.     CAN_SET_METADATA = [
  35.         'title',
  36.         'authors',
  37.         'collections']
  38.     VENDOR_ID = [
  39.         1356]
  40.     PRODUCT_ID = [
  41.         798]
  42.     BCD = [
  43.         553,
  44.         4096,
  45.         554,
  46.         794]
  47.     VENDOR_NAME = 'SONY'
  48.     WINDOWS_MAIN_MEM = re.compile('(PRS-(505|500|300))|(PRS-((700[#/])|((6|9|3)(0|5)0&)))')
  49.     WINDOWS_CARD_A_MEM = re.compile('(PRS-(505|500)[#/]\\S+:MS)|(PRS-((700[/#]\\S+:)|((6|9)(0|5)0[#_]))MS)')
  50.     WINDOWS_CARD_B_MEM = re.compile('(PRS-(505|500)[#/]\\S+:SD)|(PRS-((700[/#]\\S+:)|((6|9)(0|5)0[#_]))SD)')
  51.     MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory'
  52.     STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card'
  53.     CARD_PATH_PREFIX = __appname__
  54.     SUPPORTS_SUB_DIRS = True
  55.     MUST_READ_METADATA = True
  56.     SUPPORTS_USE_AUTHOR_SORT = True
  57.     EBOOK_DIR_MAIN = 'database/media/books'
  58.     EXTRA_CUSTOMIZATION_MESSAGE = _('Comma separated list of metadata fields to turn into collections on the device. Possibilities include: ') + 'series, tags, authors'
  59.     EXTRA_CUSTOMIZATION_DEFAULT = ', '.join([
  60.         'series',
  61.         'tags'])
  62.     plugboard = None
  63.     plugboard_func = None
  64.     THUMBNAIL_HEIGHT = 200
  65.     
  66.     def windows_filter_pnp_id(self, pnp_id):
  67.         return '_LAUNCHER' in pnp_id
  68.  
  69.     
  70.     def post_open_callback(self):
  71.         
  72.         def write_cache(prefix):
  73.             
  74.             try:
  75.                 cachep = os.path.join(prefix, *CACHE_XML.split('/'))
  76.                 return True
  77.             except:
  78.                 import traceback
  79.                 traceback.print_exc()
  80.  
  81.             return False
  82.  
  83.         if self._card_a_prefix is not None:
  84.             if not write_cache(self._card_a_prefix):
  85.                 self._card_a_prefix = None
  86.             
  87.         
  88.         if self._card_b_prefix is not None:
  89.             if not write_cache(self._card_b_prefix):
  90.                 self._card_b_prefix = None
  91.             
  92.         
  93.         self.booklist_class.rebuild_collections = self.rebuild_collections
  94.  
  95.     
  96.     def get_device_information(self, end_session = True):
  97.         return (self.gui_name, '', '', '')
  98.  
  99.     
  100.     def filename_callback(self, fname, mi):
  101.         if getattr(mi, 'application_id', None) is not None:
  102.             base = fname.rpartition('.')[0]
  103.             suffix = '_%s' % mi.application_id
  104.             if not base.endswith(suffix):
  105.                 fname = base + suffix + '.' + fname.rpartition('.')[-1]
  106.             
  107.         
  108.         return fname
  109.  
  110.     
  111.     def initialize_XML_cache(self):
  112.         paths = { }
  113.         prefixes = { }
  114.         ext_paths = { }
  115.         for prefix, path, ext_path, source_id in [
  116.             ('main', MEDIA_XML, MEDIA_EXT, 0),
  117.             ('card_a', CACHE_XML, CACHE_EXT, 1),
  118.             ('card_b', CACHE_XML, CACHE_EXT, 2)]:
  119.             prefix = getattr(self, '_%s_prefix' % prefix)
  120.             if prefix is not None and os.path.exists(prefix):
  121.                 paths[source_id] = os.path.join(prefix, *path.split('/'))
  122.                 ext_paths[source_id] = os.path.join(prefix, *ext_path.split('/'))
  123.                 prefixes[source_id] = prefix
  124.                 d = os.path.dirname(paths[source_id])
  125.                 if not os.path.exists(d):
  126.                     os.makedirs(d)
  127.                 
  128.             os.path.exists(d)
  129.         
  130.         return XMLCache(paths, ext_paths, prefixes, self.settings().use_author_sort)
  131.  
  132.     
  133.     def books(self, oncard = None, end_session = True):
  134.         debug_print('PRS505: starting fetching books for card', oncard)
  135.         bl = USBMS.books(self, oncard = oncard, end_session = end_session)
  136.         c = self.initialize_XML_cache()
  137.         c.update_booklist(bl, {
  138.             'carda': 1,
  139.             'cardb': 2 }.get(oncard, 0))
  140.         debug_print('PRS505: finished fetching books for card', oncard)
  141.         return bl
  142.  
  143.     
  144.     def sync_booklists(self, booklists, end_session = True):
  145.         debug_print('PRS505: started sync_booklists')
  146.         c = self.initialize_XML_cache()
  147.         blists = { }
  148.         for i in c.paths:
  149.             if booklists[i] is not None:
  150.                 blists[i] = booklists[i]
  151.                 continue
  152.         
  153.         opts = self.settings()
  154.         debug_print('PRS505: collection fields:', collections)
  155.         pb = None
  156.         if self.plugboard_func:
  157.             pb = self.plugboard_func(self.__class__.__name__, 'device_db', self.plugboards)
  158.         
  159.         debug_print('PRS505: use plugboards', pb)
  160.         c.update(blists, collections, pb)
  161.         c.write()
  162.         USBMS.sync_booklists(self, booklists, end_session = end_session)
  163.         debug_print('PRS505: finished sync_booklists')
  164.  
  165.     
  166.     def rebuild_collections(self, booklist, oncard):
  167.         debug_print('PRS505: started rebuild_collections on card', oncard)
  168.         c = self.initialize_XML_cache()
  169.         c.rebuild_collections(booklist, {
  170.             'carda': 1,
  171.             'cardb': 2 }.get(oncard, 0))
  172.         c.write()
  173.         debug_print('PRS505: finished rebuild_collections')
  174.  
  175.     
  176.     def set_plugboards(self, plugboards, pb_func):
  177.         self.plugboards = plugboards
  178.         self.plugboard_func = pb_func
  179.  
  180.     
  181.     def upload_cover(self, path, filename, metadata, filepath):
  182.         pass
  183.  
  184.  
  185.