home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_763 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  9.1 KB  |  268 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. import os
  7. from collections import namedtuple
  8. from calibre.customize import Plugin
  9. from calibre.constants import iswindows
  10.  
  11. class DevicePlugin(Plugin):
  12.     type = _('Device Interface')
  13.     FORMATS = [
  14.         'lrf',
  15.         'rtf',
  16.         'pdf',
  17.         'txt']
  18.     VENDOR_ID = 0
  19.     PRODUCT_ID = 0
  20.     BCD = None
  21.     THUMBNAIL_HEIGHT = 68
  22.     CAN_SET_METADATA = True
  23.     path_sep = os.sep
  24.     icon = I('reader.svg')
  25.     UserAnnotation = namedtuple('Annotation', 'type, value')
  26.     OPEN_FEEDBACK_MESSAGE = None
  27.     VIRTUAL_BOOK_EXTENSIONS = frozenset([])
  28.     
  29.     def get_gui_name(cls):
  30.         if hasattr(cls, 'gui_name'):
  31.             return cls.gui_name
  32.         if hasattr(cls, '__name__'):
  33.             return cls.__name__
  34.         return cls.name
  35.  
  36.     get_gui_name = classmethod(get_gui_name)
  37.     
  38.     def test_bcd_windows(self, device_id, bcd):
  39.         if bcd is None or len(bcd) == 0:
  40.             return True
  41.         for c in bcd:
  42.             rev = ('rev_%4.4x' % c).replace('a', ':')
  43.             if rev in device_id:
  44.                 return True
  45.         
  46.         return False
  47.  
  48.     
  49.     def print_usb_device_info(self, info):
  50.         
  51.         try:
  52.             print '\t', repr(info)
  53.         except:
  54.             import traceback
  55.             traceback.print_exc()
  56.  
  57.  
  58.     
  59.     def is_usb_connected_windows(self, devices_on_system, debug = False, only_presence = False):
  60.         
  61.         def id_iterator():
  62.             if hasattr(self.VENDOR_ID, 'keys'):
  63.                 for vid in self.VENDOR_ID:
  64.                     vend = self.VENDOR_ID[vid]
  65.                     for pid in vend:
  66.                         bcd = vend[pid]
  67.                         yield (vid, pid, bcd)
  68.                     
  69.                 
  70.             elif hasattr(self.VENDOR_ID, '__len__'):
  71.                 pass
  72.             
  73.             vendors = [
  74.                 self.VENDOR_ID]
  75.             products = None if hasattr(self.PRODUCT_ID, '__len__') else [
  76.                 self.PRODUCT_ID]
  77.             for vid in vendors:
  78.                 for pid in products:
  79.                     yield (vid, pid, self.BCD)
  80.                 
  81.             
  82.  
  83.         for vendor_id, product_id, bcd in id_iterator():
  84.             vid = 'vid_%4.4x' % vendor_id
  85.             pid = 'pid_%4.4x' % product_id
  86.             vidd = 'vid_%i' % vendor_id
  87.             pidd = 'pid_%i' % product_id
  88.             for device_id in devices_on_system:
  89.                 if vid in device_id or vidd in device_id:
  90.                     if (pid in device_id or pidd in device_id) and self.test_bcd_windows(device_id, bcd):
  91.                         if debug:
  92.                             self.print_usb_device_info(device_id)
  93.                         
  94.                         if only_presence or self.can_handle_windows(device_id, debug = debug):
  95.                             return True
  96.                         continue
  97.                 self.can_handle_windows(device_id, debug = debug)
  98.             
  99.         
  100.         return False
  101.  
  102.     
  103.     def test_bcd(self, bcdDevice, bcd):
  104.         if bcd is None or len(bcd) == 0:
  105.             return True
  106.         for c in bcd:
  107.             if c == bcdDevice:
  108.                 return True
  109.         
  110.         return False
  111.  
  112.     
  113.     def is_usb_connected(self, devices_on_system, debug = False, only_presence = False):
  114.         if iswindows:
  115.             return (self.is_usb_connected_windows(devices_on_system, debug = debug, only_presence = only_presence), None)
  116.         vendors_on_system = []([ x[0] for x in devices_on_system ])
  117.         vendors = [] if hasattr(self.VENDOR_ID, '__len__') else [
  118.             self.VENDOR_ID]
  119.         if hasattr(self.VENDOR_ID, 'keys'):
  120.             products = []
  121.             for ven in self.VENDOR_ID:
  122.                 products.extend(self.VENDOR_ID[ven].keys())
  123.             
  124.         elif hasattr(self.PRODUCT_ID, '__len__'):
  125.             pass
  126.         
  127.         products = [
  128.             self.PRODUCT_ID]
  129.         for vid in vendors:
  130.             if vid in vendors_on_system:
  131.                 for dev in devices_on_system:
  132.                     (cvid, pid, bcd) = dev[:3]
  133.                     if cvid == vid:
  134.                         if pid in products:
  135.                             if hasattr(self.VENDOR_ID, 'keys'):
  136.                                 cbcd = self.VENDOR_ID[vid][pid]
  137.                             else:
  138.                                 cbcd = self.BCD
  139.                             if self.test_bcd(bcd, cbcd):
  140.                                 if debug:
  141.                                     self.print_usb_device_info(dev)
  142.                                 
  143.                                 if self.can_handle(dev, debug = debug):
  144.                                     return (True, dev)
  145.                             
  146.                         
  147.                     pid in products
  148.                 
  149.             iswindows
  150.         
  151.         return (False, None)
  152.  
  153.     
  154.     def reset(self, key = '-1', log_packets = False, report_progress = None, detected_device = None):
  155.         raise NotImplementedError()
  156.  
  157.     
  158.     def can_handle_windows(self, device_id, debug = False):
  159.         return True
  160.  
  161.     
  162.     def can_handle(self, device_info, debug = False):
  163.         return True
  164.  
  165.     
  166.     def open(self):
  167.         raise NotImplementedError()
  168.  
  169.     
  170.     def eject(self):
  171.         raise NotImplementedError()
  172.  
  173.     
  174.     def post_yank_cleanup(self):
  175.         raise NotImplementedError()
  176.  
  177.     
  178.     def set_progress_reporter(self, report_progress):
  179.         raise NotImplementedError()
  180.  
  181.     
  182.     def get_device_information(self, end_session = True):
  183.         raise NotImplementedError()
  184.  
  185.     
  186.     def card_prefix(self, end_session = True):
  187.         raise NotImplementedError()
  188.  
  189.     
  190.     def total_space(self, end_session = True):
  191.         raise NotImplementedError()
  192.  
  193.     
  194.     def free_space(self, end_session = True):
  195.         raise NotImplementedError()
  196.  
  197.     
  198.     def books(self, oncard = None, end_session = True):
  199.         raise NotImplementedError()
  200.  
  201.     
  202.     def upload_books(self, files, names, on_card = None, end_session = True, metadata = None):
  203.         raise NotImplementedError()
  204.  
  205.     
  206.     def add_books_to_metadata(cls, locations, metadata, booklists):
  207.         raise NotImplementedError
  208.  
  209.     add_books_to_metadata = classmethod(add_books_to_metadata)
  210.     
  211.     def delete_books(self, paths, end_session = True):
  212.         raise NotImplementedError()
  213.  
  214.     
  215.     def remove_books_from_metadata(cls, paths, booklists):
  216.         raise NotImplementedError()
  217.  
  218.     remove_books_from_metadata = classmethod(remove_books_from_metadata)
  219.     
  220.     def sync_booklists(self, booklists, end_session = True):
  221.         raise NotImplementedError()
  222.  
  223.     
  224.     def get_file(self, path, outfile, end_session = True):
  225.         raise NotImplementedError()
  226.  
  227.     
  228.     def config_widget(cls):
  229.         raise NotImplementedError()
  230.  
  231.     config_widget = classmethod(config_widget)
  232.     
  233.     def save_settings(cls, settings_widget):
  234.         raise NotImplementedError()
  235.  
  236.     save_settings = classmethod(save_settings)
  237.     
  238.     def settings(cls):
  239.         raise NotImplementedError()
  240.  
  241.     settings = classmethod(settings)
  242.  
  243.  
  244. class BookList(list):
  245.     __getslice__ = None
  246.     __setslice__ = None
  247.     
  248.     def __init__(self, oncard, prefix, settings):
  249.         pass
  250.  
  251.     
  252.     def supports_collections(self):
  253.         raise NotImplementedError()
  254.  
  255.     
  256.     def add_book(self, book, replace_metadata):
  257.         raise NotImplementedError()
  258.  
  259.     
  260.     def remove_book(self, book):
  261.         raise NotImplementedError()
  262.  
  263.     
  264.     def get_collections(self, collection_attributes):
  265.         raise NotImplementedError()
  266.  
  267.  
  268.