home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_821 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.5 KB  |  172 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.     device_plugins = device_plugins
  68.     import calibre.customize.ui
  69.     DeviceScanner = DeviceScanner
  70.     win_pnp_drives = win_pnp_drives
  71.     import calibre.devices.scanner
  72.     iswindows = iswindows
  73.     isosx = isosx
  74.     __version__ = __version__
  75.     import calibre.constants
  76.     prints = prints
  77.     import calibre
  78.     oldo = sys.stdout
  79.     olde = sys.stderr
  80.     if buf is None:
  81.         buf = StringIO()
  82.     
  83.     sys.stdout = sys.stderr = buf
  84.     
  85.     try:
  86.         out = partial(prints, file = buf)
  87.         out('Version:', __version__)
  88.         s = DeviceScanner()
  89.         s.scan()
  90.         devices = s.devices
  91.         out('USB devices on system:')
  92.         out(pprint.pformat(devices))
  93.         if iswindows:
  94.             drives = win_pnp_drives(debug = True)
  95.             out('Drives detected:')
  96.             for drive in sorted(drives.keys(), key = operator.attrgetter('order')):
  97.                 prints(u'\t(%d)' % drive.order, drive, '~', drives[drive])
  98.             
  99.         
  100.         ioreg = None
  101.         if isosx:
  102.             Device = Device
  103.             import calibre.devices.usbms.device
  104.             mount = repr(Device.osx_run_mount())
  105.             drives = pprint.pformat(Device.osx_get_usb_drives())
  106.             ioreg = 'Output from mount:\n' + mount + '\n\n'
  107.             ioreg += 'Output from osx_get_usb_drives:\n' + drives + '\n\n'
  108.             ioreg += Device.run_ioreg()
  109.         
  110.         connected_devices = []
  111.         for dev in sorted(device_plugins(), cmp = (lambda x, y: cmp(x.__class__.__name__, y.__class__.__name__))):
  112.             out('Looking for', dev.__class__.__name__)
  113.             (connected, det) = s.is_device_connected(dev, debug = True)
  114.             if connected:
  115.                 connected_devices.append((dev, det))
  116.                 continue
  117.         
  118.         errors = { }
  119.         success = False
  120.         out('Devices possibly connected:', end = ' ')
  121.         for dev, det in connected_devices:
  122.             out(dev.name, end = ', ')
  123.         
  124.         if not connected_devices:
  125.             out('None', end = '')
  126.         
  127.         out(' ')
  128.         for dev, det in connected_devices:
  129.             out('Trying to open', dev.name, '...', end = ' ')
  130.             
  131.             try:
  132.                 dev.reset(detected_device = det)
  133.                 dev.open()
  134.                 out('OK')
  135.             except:
  136.                 import traceback
  137.                 errors[dev] = traceback.format_exc()
  138.                 out('failed')
  139.                 continue
  140.  
  141.             success = True
  142.             if hasattr(dev, '_main_prefix'):
  143.                 out('Main memory:', repr(dev._main_prefix))
  144.             
  145.             out('Total space:', dev.total_space())
  146.         
  147.         if not success and errors:
  148.             out('Opening of the following devices failed')
  149.             for dev, msg in errors.items():
  150.                 out(dev)
  151.                 out(msg)
  152.                 out(' ')
  153.             
  154.         
  155.         if ioreg is not None:
  156.             ioreg = 'IOREG Output\n' + ioreg
  157.             out(' ')
  158.             if ioreg_to_tmp:
  159.                 open('/tmp/ioreg.txt', 'wb').write(ioreg)
  160.                 out('Dont forget to send the contents of /tmp/ioreg.txt')
  161.                 out('You can open it with the command: open /tmp/ioreg.txt')
  162.             else:
  163.                 out(ioreg)
  164.         
  165.         if hasattr(buf, 'getvalue'):
  166.             return buf.getvalue().decode('utf-8')
  167.     finally:
  168.         sys.stdout = oldo
  169.         sys.stderr = olde
  170.  
  171.  
  172.