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