home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_814 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  5.8 KB  |  179 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 sys
  7. import time
  8. import pprint
  9. import operator
  10. from functools import partial
  11. from StringIO import StringIO
  12. DAY_MAP = dict(Sun = 0, Mon = 1, Tue = 2, Wed = 3, Thu = 4, Fri = 5, Sat = 6)
  13. MONTH_MAP = dict(Jan = 1, Feb = 2, Mar = 3, Apr = 4, May = 5, Jun = 6, Jul = 7, Aug = 8, Sep = 9, Oct = 10, Nov = 11, Dec = 12)
  14. INVERSE_DAY_MAP = dict(zip(DAY_MAP.values(), DAY_MAP.keys()))
  15. INVERSE_MONTH_MAP = dict(zip(MONTH_MAP.values(), MONTH_MAP.keys()))
  16.  
  17. def strptime(src):
  18.     src = src.strip()
  19.     src = src.split()
  20.     src[0] = str(DAY_MAP[src[0][:-1]]) + ','
  21.     src[2] = str(MONTH_MAP[src[2]])
  22.     return time.strptime(' '.join(src), '%w, %d %m %Y %H:%M:%S %Z')
  23.  
  24.  
  25. def strftime(epoch, zone = time.gmtime):
  26.     src = time.strftime('%w, %d %m %Y %H:%M:%S GMT', zone(epoch)).split()
  27.     src[0] = INVERSE_DAY_MAP[int(src[0][:-1])] + ','
  28.     src[2] = INVERSE_MONTH_MAP[int(src[2])]
  29.     return ' '.join(src)
  30.  
  31.  
  32. def get_connected_device():
  33.     device_plugins = device_plugins
  34.     import calibre.customize.ui
  35.     DeviceScanner = DeviceScanner
  36.     import calibre.devices.scanner
  37.     dev = None
  38.     scanner = DeviceScanner()
  39.     scanner.scan()
  40.     connected_devices = []
  41.     for d in device_plugins():
  42.         (ok, det) = scanner.is_device_connected(d)
  43.         if ok:
  44.             dev = d
  45.             dev.reset(log_packets = False, detected_device = det)
  46.             connected_devices.append(dev)
  47.             continue
  48.     
  49.     if dev is None:
  50.         print >>sys.stderr, 'Unable to find a connected ebook reader.'
  51.         return None
  52.     for d in connected_devices:
  53.         
  54.         try:
  55.             d.open()
  56.         except:
  57.             dev is None
  58.             continue
  59.             continue
  60.  
  61.         dev = d
  62.     
  63.     return dev
  64.  
  65.  
  66. def debug(ioreg_to_tmp = False, buf = None):
  67.     import textwrap
  68.     device_plugins = device_plugins
  69.     import calibre.customize.ui
  70.     DeviceScanner = DeviceScanner
  71.     win_pnp_drives = win_pnp_drives
  72.     import calibre.devices.scanner
  73.     iswindows = iswindows
  74.     isosx = isosx
  75.     __version__ = __version__
  76.     import calibre.constants
  77.     prints = prints
  78.     import calibre
  79.     oldo = sys.stdout
  80.     olde = sys.stderr
  81.     if buf is None:
  82.         buf = StringIO()
  83.     
  84.     sys.stdout = sys.stderr = buf
  85.     
  86.     try:
  87.         out = partial(prints, file = buf)
  88.         out('Version:', __version__)
  89.         s = DeviceScanner()
  90.         s.scan()
  91.         devices = s.devices
  92.         out('USB devices on system:')
  93.         out(pprint.pformat(devices))
  94.         if iswindows:
  95.             drives = win_pnp_drives(debug = True)
  96.             out('Drives detected:')
  97.             for drive in sorted(drives.keys(), key = operator.attrgetter('order')):
  98.                 prints(u'\t(%d)' % drive.order, drive, '~', drives[drive])
  99.             
  100.         
  101.         ioreg = None
  102.         if isosx:
  103.             Device = Device
  104.             import calibre.devices.usbms.device
  105.             mount = repr(Device.osx_run_mount())
  106.             drives = pprint.pformat(Device.osx_get_usb_drives())
  107.             ioreg = 'Output from mount:\n' + mount + '\n\n'
  108.             ioreg += 'Output from osx_get_usb_drives:\n' + drives + '\n\n'
  109.             ioreg += Device.run_ioreg()
  110.         
  111.         connected_devices = []
  112.         devplugins = list(sorted(device_plugins(), cmp = (lambda x, y: cmp(x.__class__.__name__, y.__class__.__name__))))
  113.         textwrap.fill(' '.join, []([]([ x.__class__.__name__ for x in devplugins ])))
  114.         out(' ')
  115.         out('Looking for devices...')
  116.         for dev in devplugins:
  117.             (connected, det) = s.is_device_connected(dev, debug = True)
  118.             if connected:
  119.                 out('\t\tDetected possible device', dev.__class__.__name__)
  120.                 connected_devices.append((dev, det))
  121.                 continue
  122.             'Available plugins:'
  123.         
  124.         out(' ')
  125.         errors = { }
  126.         success = False
  127.         out('Devices possibly connected:', end = ' ')
  128.         for dev, det in connected_devices:
  129.             out(dev.name, end = ', ')
  130.         
  131.         if not connected_devices:
  132.             out('None', end = '')
  133.         
  134.         out(' ')
  135.         for dev, det in connected_devices:
  136.             out('Trying to open', dev.name, '...', end = ' ')
  137.             
  138.             try:
  139.                 dev.reset(detected_device = det)
  140.                 dev.open()
  141.                 out('OK')
  142.             except:
  143.                 import traceback
  144.                 errors[dev] = traceback.format_exc()
  145.                 out('failed')
  146.                 continue
  147.  
  148.             success = True
  149.             if hasattr(dev, '_main_prefix'):
  150.                 out('Main memory:', repr(dev._main_prefix))
  151.             
  152.             out('Total space:', dev.total_space())
  153.         
  154.         if not success and errors:
  155.             out('Opening of the following devices failed')
  156.             for dev, msg in errors.items():
  157.                 out(dev)
  158.                 out(msg)
  159.                 out(' ')
  160.             
  161.         
  162.         if ioreg is not None:
  163.             ioreg = 'IOREG Output\n' + ioreg
  164.             out(' ')
  165.             if ioreg_to_tmp:
  166.                 open('/tmp/ioreg.txt', 'wb').write(ioreg)
  167.                 out('Dont forget to send the contents of /tmp/ioreg.txt')
  168.                 out('You can open it with the command: open /tmp/ioreg.txt')
  169.             else:
  170.                 out(ioreg)
  171.         
  172.         if hasattr(buf, 'getvalue'):
  173.             return buf.getvalue().decode('utf-8')
  174.     finally:
  175.         sys.stdout = oldo
  176.         sys.stderr = olde
  177.  
  178.  
  179.