Exemplo n.º 1
0
 def unhandled_exception(self, type, value, tb):
     if type is KeyboardInterrupt:
         return
     try:
         sio = BytesIO()
         try:
             from calibre.debug import print_basic_debug_info
             print_basic_debug_info(out=sio)
         except:
             pass
         traceback.print_exception(type, value, tb, file=sio)
         if getattr(value, 'locking_debug_msg', None):
             prints(value.locking_debug_msg, file=sio)
         fe = sio.getvalue()
         prints(fe, file=sys.stderr)
         fe = force_unicode(fe)
         msg = '<b>%s</b>:' % type.__name__ + force_unicode(value)
         error_dialog(self,
                      _('Unhandled exception'),
                      msg,
                      det_msg=fe,
                      show=True)
     except BaseException:
         pass
     except:
         pass
Exemplo n.º 2
0
 def unhandled_exception(self, type, value, tb):
     if type == KeyboardInterrupt:
         self.keyboard_interrupt.emit()
         return
     try:
         sio = StringIO.StringIO()
         try:
             from calibre.debug import print_basic_debug_info
             print_basic_debug_info(out=sio)
         except:
             pass
         traceback.print_exception(type, value, tb, file=sio)
         if getattr(value, 'locking_debug_msg', None):
             prints(value.locking_debug_msg, file=sio)
         fe = sio.getvalue()
         prints(fe, file=sys.stderr)
         msg = '<b>%s</b>:' % type.__name__ + unicode(
             str(value), 'utf8', 'replace')
         error_dialog(self,
                      _('Unhandled exception'),
                      msg,
                      det_msg=fe,
                      show=True)
     except BaseException:
         pass
     except:
         pass
Exemplo n.º 3
0
 def unhandled_exception(self, exc_type, value, tb):
     if exc_type is KeyboardInterrupt:
         return
     import traceback
     try:
         sio = PolyglotStringIO(errors='replace')
         try:
             from calibre.debug import print_basic_debug_info
             print_basic_debug_info(out=sio)
         except:
             pass
         traceback.print_exception(exc_type, value, tb, file=sio)
         if getattr(value, 'locking_debug_msg', None):
             prints(value.locking_debug_msg, file=sio)
         fe = sio.getvalue()
         msg = '<b>%s</b>:' % exc_type.__name__ + as_unicode(value)
         error_dialog(self,
                      _('Unhandled exception'),
                      msg,
                      det_msg=fe,
                      show=True)
         prints(fe, file=sys.stderr)
     except BaseException:
         pass
     except:
         pass
Exemplo n.º 4
0
def calibre(args=sys.argv):
    from calibre.constants import DEBUG
    if DEBUG:
        from calibre.debug import print_basic_debug_info
        print_basic_debug_info()
    detach_gui()
    with register_with_default_programs():
        from calibre.gui2.main import main
        main(args)
Exemplo n.º 5
0
def calibre(args=sys.argv):
    from calibre.constants import DEBUG
    if DEBUG:
        from calibre.debug import print_basic_debug_info
        print_basic_debug_info()
    detach_gui()
    init_dbus()
    with register_with_default_programs():
        from calibre.gui2.main import main
        main(args)
Exemplo n.º 6
0
 def unhandled_exception(self, type, value, tb):
     if type is KeyboardInterrupt:
         return
     try:
         sio = StringIO.StringIO()
         try:
             from calibre.debug import print_basic_debug_info
             print_basic_debug_info(out=sio)
         except:
             pass
         traceback.print_exception(type, value, tb, file=sio)
         if getattr(value, 'locking_debug_msg', None):
             prints(value.locking_debug_msg, file=sio)
         fe = sio.getvalue()
         prints(fe, file=sys.stderr)
         msg = '<b>%s</b>:'%type.__name__ + unicode(str(value), 'utf8', 'replace')
         error_dialog(self, _('Unhandled exception'), msg, det_msg=fe,
                 show=True)
     except BaseException:
         pass
     except:
         pass
Exemplo n.º 7
0
    def unhandled_exception(self, type, value, tb):
        if type == KeyboardInterrupt:
            self.keyboard_interrupt.emit()
            return
        try:
            sio = StringIO.StringIO()
            try:
                from calibre.debug import print_basic_debug_info

                print_basic_debug_info(out=sio)
            except:
                pass
            traceback.print_exception(type, value, tb, file=sio)
            if getattr(value, "locking_debug_msg", None):
                prints(value.locking_debug_msg, file=sio)
            fe = sio.getvalue()
            prints(fe, file=sys.stderr)
            msg = "<b>%s</b>:" % type.__name__ + unicode(str(value), "utf8", "replace")
            error_dialog(self, _("Unhandled exception"), msg, det_msg=fe, show=True)
        except BaseException:
            pass
        except:
            pass
Exemplo n.º 8
0
 def unhandled_exception(self, exc_type, value, tb):
     if exc_type is KeyboardInterrupt:
         return
     import traceback
     try:
         sio = PolyglotBytesIO(errors='replace')
         try:
             from calibre.debug import print_basic_debug_info
             print_basic_debug_info(out=sio)
         except:
             pass
         traceback.print_exception(exc_type, value, tb, file=sio)
         if getattr(value, 'locking_debug_msg', None):
             prints(value.locking_debug_msg, file=sio)
         fe = sio.getvalue()
         prints(fe, file=sys.stderr)
         fe = force_unicode(fe)
         msg = '<b>%s</b>:'%exc_type.__name__ + as_unicode(value)
         error_dialog(self, _('Unhandled exception'), msg, det_msg=fe,
                 show=True)
     except BaseException:
         pass
     except:
         pass
Exemplo n.º 9
0
def debug(ioreg_to_tmp=False, buf=None, plugins=None, disabled_plugins=None):
    '''
    If plugins is None, then this method calls startup and shutdown on the
    device plugins. So if you are using it in a context where startup could
    already have been called (for example in the main GUI), pass in the list of
    device plugins as the plugins parameter.
    '''
    import textwrap
    from calibre.customize.ui import device_plugins, disabled_device_plugins
    from calibre.debug import print_basic_debug_info
    from calibre.devices.scanner import DeviceScanner
    from calibre.constants import iswindows, ismacos
    from calibre import prints
    from polyglot.io import PolyglotStringIO
    oldo, olde = sys.stdout, sys.stderr

    if buf is None:
        buf = PolyglotStringIO()
    sys.stdout = sys.stderr = buf
    out = partial(prints, file=buf)

    devplugins = device_plugins() if plugins is None else plugins
    devplugins = list(sorted(devplugins, key=lambda x: x.__class__.__name__))
    if plugins is None:
        for d in devplugins:
            try:
                d.startup()
            except:
                out('Startup failed for device plugin: %s' % d)

    if disabled_plugins is None:
        disabled_plugins = list(disabled_device_plugins())

    try:
        print_basic_debug_info(out=buf)
        s = DeviceScanner()
        s.scan()
        devices = (s.devices)
        if not iswindows:
            devices = [list(x) for x in devices]
            for d in devices:
                for i in range(3):
                    d[i] = hex(d[i])
        out('USB devices on system:')
        out(pprint.pformat(devices))

        ioreg = None
        if ismacos:
            from calibre.devices.usbms.device import Device
            mount = '\n'.join(
                repr(x) for x in Device.osx_run_mount().splitlines())
            drives = pprint.pformat(Device.osx_get_usb_drives())
            ioreg = 'Output from mount:\n' + mount + '\n\n'
            ioreg += 'Output from osx_get_usb_drives:\n' + drives + '\n\n'
            ioreg += Device.run_ioreg().decode('utf-8')
        connected_devices = []
        if disabled_plugins:
            out(
                '\nDisabled plugins:',
                textwrap.fill(' '.join(
                    [x.__class__.__name__ for x in disabled_plugins])))
            out(' ')
        else:
            out('\nNo disabled plugins')
        found_dev = False
        for dev in devplugins:
            if not dev.MANAGES_DEVICE_PRESENCE:
                continue
            out('Looking for devices of type:', dev.__class__.__name__)
            if dev.debug_managed_device_detection(s.devices, buf):
                found_dev = True
                break
            out(' ')

        if not found_dev:
            out('Looking for devices...')
            for dev in devplugins:
                if dev.MANAGES_DEVICE_PRESENCE:
                    continue
                connected, det = s.is_device_connected(dev, debug=True)
                if connected:
                    out('\t\tDetected possible device', dev.__class__.__name__)
                    connected_devices.append((dev, det))

            out(' ')
            errors = {}
            success = False
            out('Devices possibly connected:', end=' ')
            for dev, det in connected_devices:
                out(dev.name, end=', ')
            if not connected_devices:
                out('None', end='')
            out(' ')
            for dev, det in connected_devices:
                out('Trying to open', dev.name, '...', end=' ')
                dev.do_device_debug = True
                try:
                    dev.reset(detected_device=det)
                    dev.open(det, None)
                    out('OK')
                except:
                    import traceback
                    errors[dev] = traceback.format_exc()
                    out('failed')
                    continue
                dev.do_device_debug = False
                success = True
                if hasattr(dev, '_main_prefix'):
                    out('Main memory:', repr(dev._main_prefix))
                out('Total space:', dev.total_space())
                break
            if not success and errors:
                out('Opening of the following devices failed')
                for dev, msg in errors.items():
                    out(dev)
                    out(msg)
                    out(' ')

            if ioreg is not None:
                ioreg = 'IOREG Output\n' + ioreg
                out(' ')
                if ioreg_to_tmp:
                    lopen('/tmp/ioreg.txt', 'w').write(ioreg)
                    out('Dont forget to send the contents of /tmp/ioreg.txt')
                    out('You can open it with the command: open /tmp/ioreg.txt'
                        )
                else:
                    out(ioreg)

        if hasattr(buf, 'getvalue'):
            return buf.getvalue()
    finally:
        sys.stdout = oldo
        sys.stderr = olde
        if plugins is None:
            for d in devplugins:
                try:
                    d.shutdown()
                except:
                    pass
Exemplo n.º 10
0
def debug(ioreg_to_tmp=False, buf=None, plugins=None,
        disabled_plugins=None):
    '''
    If plugins is None, then this method calls startup and shutdown on the
    device plugins. So if you are using it in a context where startup could
    already have been called (for example in the main GUI), pass in the list of
    device plugins as the plugins parameter.
    '''
    import textwrap
    from calibre.customize.ui import device_plugins, disabled_device_plugins
    from calibre.debug import print_basic_debug_info
    from calibre.devices.scanner import DeviceScanner
    from calibre.constants import iswindows, isosx
    from calibre import prints
    from polyglot.io import PolyglotBytesIO
    oldo, olde = sys.stdout, sys.stderr

    if buf is None:
        buf = PolyglotBytesIO()
    sys.stdout = sys.stderr = buf
    out = partial(prints, file=buf)

    devplugins = device_plugins() if plugins is None else plugins
    devplugins = list(sorted(devplugins, key=lambda x: x.__class__.__name__))
    if plugins is None:
        for d in devplugins:
            try:
                d.startup()
            except:
                out('Startup failed for device plugin: %s'%d)

    if disabled_plugins is None:
        disabled_plugins = list(disabled_device_plugins())

    try:
        print_basic_debug_info(out=buf)
        s = DeviceScanner()
        s.scan()
        devices = (s.devices)
        if not iswindows:
            devices = [list(x) for x in devices]
            for d in devices:
                for i in range(3):
                    d[i] = hex(d[i])
        out('USB devices on system:')
        out(pprint.pformat(devices))

        ioreg = None
        if isosx:
            from calibre.devices.usbms.device import Device
            mount = '\n'.join(repr(x) for x in Device.osx_run_mount().splitlines())
            drives = pprint.pformat(Device.osx_get_usb_drives())
            ioreg = 'Output from mount:\n'+mount+'\n\n'
            ioreg += 'Output from osx_get_usb_drives:\n'+drives+'\n\n'
            ioreg += Device.run_ioreg()
        connected_devices = []
        if disabled_plugins:
            out('\nDisabled plugins:', textwrap.fill(' '.join([x.__class__.__name__ for x in
                disabled_plugins])))
            out(' ')
        else:
            out('\nNo disabled plugins')
        found_dev = False
        for dev in devplugins:
            if not dev.MANAGES_DEVICE_PRESENCE:
                continue
            out('Looking for devices of type:', dev.__class__.__name__)
            if dev.debug_managed_device_detection(s.devices, buf):
                found_dev = True
                break
            out(' ')

        if not found_dev:
            out('Looking for devices...')
            for dev in devplugins:
                if dev.MANAGES_DEVICE_PRESENCE:
                    continue
                connected, det = s.is_device_connected(dev, debug=True)
                if connected:
                    out('\t\tDetected possible device', dev.__class__.__name__)
                    connected_devices.append((dev, det))

            out(' ')
            errors = {}
            success = False
            out('Devices possibly connected:', end=' ')
            for dev, det in connected_devices:
                out(dev.name, end=', ')
            if not connected_devices:
                out('None', end='')
            out(' ')
            for dev, det in connected_devices:
                out('Trying to open', dev.name, '...', end=' ')
                dev.do_device_debug = True
                try:
                    dev.reset(detected_device=det)
                    dev.open(det, None)
                    out('OK')
                except:
                    import traceback
                    errors[dev] = traceback.format_exc()
                    out('failed')
                    continue
                dev.do_device_debug = False
                success = True
                if hasattr(dev, '_main_prefix'):
                    out('Main memory:', repr(dev._main_prefix))
                out('Total space:', dev.total_space())
                break
            if not success and errors:
                out('Opening of the following devices failed')
                for dev,msg in errors.items():
                    out(dev)
                    out(msg)
                    out(' ')

            if ioreg is not None:
                ioreg = 'IOREG Output\n'+ioreg
                out(' ')
                if ioreg_to_tmp:
                    lopen('/tmp/ioreg.txt', 'wb').write(ioreg)
                    out('Dont forget to send the contents of /tmp/ioreg.txt')
                    out('You can open it with the command: open /tmp/ioreg.txt')
                else:
                    out(ioreg)

        if hasattr(buf, 'getvalue'):
            return buf.getvalue().decode('utf-8', 'replace')
    finally:
        sys.stdout = oldo
        sys.stderr = olde
        if plugins is None:
            for d in devplugins:
                try:
                    d.shutdown()
                except:
                    pass