mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Print debug info from USBMS driver when running in normal GUI as well
This commit is contained in:
parent
609b431c91
commit
89d26dade1
@ -108,9 +108,13 @@ else:
|
|||||||
DEBUG = hasenv('CALIBRE_DEBUG')
|
DEBUG = hasenv('CALIBRE_DEBUG')
|
||||||
|
|
||||||
|
|
||||||
def debug():
|
def debug(val=True):
|
||||||
global DEBUG
|
global DEBUG
|
||||||
DEBUG = True
|
DEBUG = bool(val)
|
||||||
|
|
||||||
|
|
||||||
|
def is_debugging():
|
||||||
|
return DEBUG
|
||||||
|
|
||||||
|
|
||||||
def _get_cache_dir():
|
def _get_cache_dir():
|
||||||
|
@ -70,7 +70,7 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None,
|
|||||||
from calibre.customize.ui import device_plugins, disabled_device_plugins
|
from calibre.customize.ui import device_plugins, disabled_device_plugins
|
||||||
from calibre.debug import print_basic_debug_info
|
from calibre.debug import print_basic_debug_info
|
||||||
from calibre.devices.scanner import DeviceScanner
|
from calibre.devices.scanner import DeviceScanner
|
||||||
from calibre.constants import iswindows, ismacos
|
from calibre.constants import iswindows, ismacos, debug, is_debugging
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from polyglot.io import PolyglotStringIO
|
from polyglot.io import PolyglotStringIO
|
||||||
oldo, olde = sys.stdout, sys.stderr
|
oldo, olde = sys.stdout, sys.stderr
|
||||||
@ -92,6 +92,8 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None,
|
|||||||
if disabled_plugins is None:
|
if disabled_plugins is None:
|
||||||
disabled_plugins = list(disabled_device_plugins())
|
disabled_plugins = list(disabled_device_plugins())
|
||||||
|
|
||||||
|
orig_debug = is_debugging()
|
||||||
|
debug(True)
|
||||||
try:
|
try:
|
||||||
print_basic_debug_info(out=buf)
|
print_basic_debug_info(out=buf)
|
||||||
s = DeviceScanner()
|
s = DeviceScanner()
|
||||||
@ -187,6 +189,7 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None,
|
|||||||
if hasattr(buf, 'getvalue'):
|
if hasattr(buf, 'getvalue'):
|
||||||
return buf.getvalue()
|
return buf.getvalue()
|
||||||
finally:
|
finally:
|
||||||
|
debug(orig_debug)
|
||||||
sys.stdout = oldo
|
sys.stdout = oldo
|
||||||
sys.stderr = olde
|
sys.stderr = olde
|
||||||
if plugins is None:
|
if plugins is None:
|
||||||
|
@ -19,7 +19,7 @@ from collections import namedtuple
|
|||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import DEBUG, isfreebsd, islinux, ismacos, iswindows
|
from calibre.constants import is_debugging, isfreebsd, islinux, ismacos, iswindows
|
||||||
from calibre.devices.errors import DeviceError
|
from calibre.devices.errors import DeviceError
|
||||||
from calibre.devices.interface import DevicePlugin
|
from calibre.devices.interface import DevicePlugin
|
||||||
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
||||||
@ -236,7 +236,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
from calibre.devices.scanner import drive_is_ok
|
from calibre.devices.scanner import drive_is_ok
|
||||||
from calibre.devices.winusb import get_drive_letters_for_device
|
from calibre.devices.winusb import get_drive_letters_for_device
|
||||||
usbdev = self.device_being_opened
|
usbdev = self.device_being_opened
|
||||||
debug = DEBUG or getattr(self, 'do_device_debug', False)
|
debug = is_debugging() or getattr(self, 'do_device_debug', False)
|
||||||
try:
|
try:
|
||||||
dlmap = get_drive_letters_for_device(usbdev, debug=debug)
|
dlmap = get_drive_letters_for_device(usbdev, debug=debug)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -394,7 +394,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
drives = self.osx_sort_names(bsd_drives.copy())
|
drives = self.osx_sort_names(bsd_drives.copy())
|
||||||
mount_map = get_mounted_filesystems()
|
mount_map = get_mounted_filesystems()
|
||||||
drives = {k: mount_map.get(v) for k, v in iteritems(drives)}
|
drives = {k: mount_map.get(v) for k, v in iteritems(drives)}
|
||||||
if DEBUG:
|
if is_debugging():
|
||||||
print()
|
print()
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
pprint({'bsd_drives': bsd_drives, 'mount_map': mount_map, 'drives': drives})
|
pprint({'bsd_drives': bsd_drives, 'mount_map': mount_map, 'drives': drives})
|
||||||
@ -501,7 +501,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
ok[node] = False
|
ok[node] = False
|
||||||
except:
|
except:
|
||||||
ok[node] = False
|
ok[node] = False
|
||||||
if DEBUG and not ok[node]:
|
if is_debugging() and not ok[node]:
|
||||||
print(f'\nIgnoring the node: {node} as could not read size from: {sz}')
|
print(f'\nIgnoring the node: {node} as could not read size from: {sz}')
|
||||||
|
|
||||||
devnodes.append(node)
|
devnodes.append(node)
|
||||||
@ -568,7 +568,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
'the device has already been ejected, or your '
|
'the device has already been ejected, or your '
|
||||||
'kernel is exporting a deprecated version of SYSFS.')
|
'kernel is exporting a deprecated version of SYSFS.')
|
||||||
%self.__class__.__name__)
|
%self.__class__.__name__)
|
||||||
if DEBUG:
|
if is_debugging():
|
||||||
print('\nFound device nodes:', main, carda, cardb)
|
print('\nFound device nodes:', main, carda, cardb)
|
||||||
|
|
||||||
self._linux_mount_map = {}
|
self._linux_mount_map = {}
|
||||||
@ -614,7 +614,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
os.remove(path)
|
os.remove(path)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if DEBUG and ro:
|
if is_debugging() and ro:
|
||||||
print('\nThe mountpoint', mp, 'is readonly, ignoring it')
|
print('\nThe mountpoint', mp, 'is readonly, ignoring it')
|
||||||
return ro
|
return ro
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from itertools import cycle
|
|||||||
|
|
||||||
from calibre.constants import numeric_version, ismacos
|
from calibre.constants import numeric_version, ismacos
|
||||||
from calibre import prints, isbytestring, fsync
|
from calibre import prints, isbytestring, fsync
|
||||||
from calibre.constants import filesystem_encoding, DEBUG
|
from calibre.constants import filesystem_encoding, is_debugging
|
||||||
from calibre.devices.usbms.cli import CLI
|
from calibre.devices.usbms.cli import CLI
|
||||||
from calibre.devices.usbms.device import Device
|
from calibre.devices.usbms.device import Device
|
||||||
from calibre.devices.usbms.books import BookList, Book
|
from calibre.devices.usbms.books import BookList, Book
|
||||||
@ -25,7 +25,7 @@ def debug_print(*args, **kw):
|
|||||||
base_time = getattr(debug_print, 'base_time', None)
|
base_time = getattr(debug_print, 'base_time', None)
|
||||||
if base_time is None:
|
if base_time is None:
|
||||||
debug_print.base_time = base_time = time.monotonic()
|
debug_print.base_time = base_time = time.monotonic()
|
||||||
if DEBUG:
|
if is_debugging():
|
||||||
prints('DEBUG: %6.1f'%(time.monotonic()-base_time), *args, **kw)
|
prints('DEBUG: %6.1f'%(time.monotonic()-base_time), *args, **kw)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user