home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_802 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  6.7 KB  |  164 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
  12. from calibre.devices.prs505 import CACHE_XML
  13. from calibre.devices.prs505.sony_cache import XMLCache
  14. from calibre import __appname__
  15. from calibre.devices.usbms.books import CollectionsBookList
  16.  
  17. class PRS505(USBMS):
  18.     name = 'SONY Device Interface'
  19.     gui_name = 'SONY Reader'
  20.     description = _('Communicate with all the Sony eBook readers.')
  21.     author = 'Kovid Goyal'
  22.     supported_platforms = [
  23.         'windows',
  24.         'osx',
  25.         'linux']
  26.     path_sep = '/'
  27.     booklist_class = CollectionsBookList
  28.     FORMATS = [
  29.         'epub',
  30.         'lrf',
  31.         'lrx',
  32.         'rtf',
  33.         'pdf',
  34.         'txt']
  35.     CAN_SET_METADATA = True
  36.     VENDOR_ID = [
  37.         1356]
  38.     PRODUCT_ID = [
  39.         798]
  40.     BCD = [
  41.         553,
  42.         4096,
  43.         554,
  44.         794]
  45.     VENDOR_NAME = 'SONY'
  46.     WINDOWS_MAIN_MEM = re.compile('(PRS-(505|300|500))|(PRS-((700[#/])|((6|9)00&)))')
  47.     WINDOWS_CARD_A_MEM = re.compile('(PRS-(505|500)[#/]\\S+:MS)|(PRS-((700[/#]\\S+:)|((6|9)00[#_]))MS)')
  48.     WINDOWS_CARD_B_MEM = re.compile('(PRS-(505|500)[#/]\\S+:SD)|(PRS-((700[/#]\\S+:)|((6|9)00[#_]))SD)')
  49.     MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory'
  50.     STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card'
  51.     CARD_PATH_PREFIX = __appname__
  52.     SUPPORTS_SUB_DIRS = True
  53.     MUST_READ_METADATA = True
  54.     SUPPORTS_USE_AUTHOR_SORT = True
  55.     EBOOK_DIR_MAIN = 'database/media/books'
  56.     EXTRA_CUSTOMIZATION_MESSAGE = _('Comma separated list of metadata fields to turn into collections on the device. Possibilities include: ') + 'series, tags, authors'
  57.     EXTRA_CUSTOMIZATION_DEFAULT = ', '.join([
  58.         'series',
  59.         'tags'])
  60.     
  61.     def windows_filter_pnp_id(self, pnp_id):
  62.         return '_LAUNCHER' in pnp_id
  63.  
  64.     
  65.     def post_open_callback(self):
  66.         
  67.         def write_cache(prefix):
  68.             
  69.             try:
  70.                 cachep = os.path.join(prefix, *CACHE_XML.split('/'))
  71.                 return True
  72.             except:
  73.                 import traceback
  74.                 traceback.print_exc()
  75.  
  76.             return False
  77.  
  78.         if self._card_a_prefix is not None:
  79.             if not write_cache(self._card_a_prefix):
  80.                 self._card_a_prefix = None
  81.             
  82.         
  83.         if self._card_b_prefix is not None:
  84.             if not write_cache(self._card_b_prefix):
  85.                 self._card_b_prefix = None
  86.             
  87.         
  88.         self.booklist_class.rebuild_collections = self.rebuild_collections
  89.  
  90.     
  91.     def get_device_information(self, end_session = True):
  92.         return (self.gui_name, '', '', '')
  93.  
  94.     
  95.     def filename_callback(self, fname, mi):
  96.         if getattr(mi, 'application_id', None) is not None:
  97.             base = fname.rpartition('.')[0]
  98.             suffix = '_%s' % mi.application_id
  99.             if not base.endswith(suffix):
  100.                 fname = base + suffix + '.' + fname.rpartition('.')[-1]
  101.             
  102.         
  103.         return fname
  104.  
  105.     
  106.     def initialize_XML_cache(self):
  107.         paths = { }
  108.         prefixes = { }
  109.         for prefix, path, source_id in [
  110.             ('main', MEDIA_XML, 0),
  111.             ('card_a', CACHE_XML, 1),
  112.             ('card_b', CACHE_XML, 2)]:
  113.             prefix = getattr(self, '_%s_prefix' % prefix)
  114.             if prefix is not None and os.path.exists(prefix):
  115.                 paths[source_id] = os.path.join(prefix, *path.split('/'))
  116.                 prefixes[source_id] = prefix
  117.                 d = os.path.dirname(paths[source_id])
  118.                 if not os.path.exists(d):
  119.                     os.makedirs(d)
  120.                 
  121.             os.path.exists(d)
  122.         
  123.         return XMLCache(paths, prefixes, self.settings().use_author_sort)
  124.  
  125.     
  126.     def books(self, oncard = None, end_session = True):
  127.         debug_print('PRS505: starting fetching books for card', oncard)
  128.         bl = USBMS.books(self, oncard = oncard, end_session = end_session)
  129.         c = self.initialize_XML_cache()
  130.         c.update_booklist(bl, {
  131.             'carda': 1,
  132.             'cardb': 2 }.get(oncard, 0))
  133.         debug_print('PRS505: finished fetching books for card', oncard)
  134.         return bl
  135.  
  136.     
  137.     def sync_booklists(self, booklists, end_session = True):
  138.         debug_print('PRS505: started sync_booklists')
  139.         c = self.initialize_XML_cache()
  140.         blists = { }
  141.         for i in c.paths:
  142.             if booklists[i] is not None:
  143.                 blists[i] = booklists[i]
  144.                 continue
  145.         
  146.         opts = self.settings()
  147.         debug_print('PRS505: collection fields:', collections)
  148.         c.update(blists, collections)
  149.         c.write()
  150.         USBMS.sync_booklists(self, booklists, end_session = end_session)
  151.         debug_print('PRS505: finished sync_booklists')
  152.  
  153.     
  154.     def rebuild_collections(self, booklist, oncard):
  155.         debug_print('PRS505: started rebuild_collections on card', oncard)
  156.         c = self.initialize_XML_cache()
  157.         c.rebuild_collections(booklist, {
  158.             'carda': 1,
  159.             'cardb': 2 }.get(oncard, 0))
  160.         c.write()
  161.         debug_print('PRS505: finished rebuild_collections')
  162.  
  163.  
  164.