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')
|
||||
|
||||
|
||||
def debug():
|
||||
def debug(val=True):
|
||||
global DEBUG
|
||||
DEBUG = True
|
||||
DEBUG = bool(val)
|
||||
|
||||
|
||||
def is_debugging():
|
||||
return DEBUG
|
||||
|
||||
|
||||
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.debug import print_basic_debug_info
|
||||
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 polyglot.io import PolyglotStringIO
|
||||
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:
|
||||
disabled_plugins = list(disabled_device_plugins())
|
||||
|
||||
orig_debug = is_debugging()
|
||||
debug(True)
|
||||
try:
|
||||
print_basic_debug_info(out=buf)
|
||||
s = DeviceScanner()
|
||||
@ -187,6 +189,7 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None,
|
||||
if hasattr(buf, 'getvalue'):
|
||||
return buf.getvalue()
|
||||
finally:
|
||||
debug(orig_debug)
|
||||
sys.stdout = oldo
|
||||
sys.stderr = olde
|
||||
if plugins is None:
|
||||
|
@ -19,7 +19,7 @@ from collections import namedtuple
|
||||
from itertools import repeat
|
||||
|
||||
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.interface import DevicePlugin
|
||||
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.winusb import get_drive_letters_for_device
|
||||
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:
|
||||
dlmap = get_drive_letters_for_device(usbdev, debug=debug)
|
||||
except Exception:
|
||||
@ -394,7 +394,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
drives = self.osx_sort_names(bsd_drives.copy())
|
||||
mount_map = get_mounted_filesystems()
|
||||
drives = {k: mount_map.get(v) for k, v in iteritems(drives)}
|
||||
if DEBUG:
|
||||
if is_debugging():
|
||||
print()
|
||||
from pprint import pprint
|
||||
pprint({'bsd_drives': bsd_drives, 'mount_map': mount_map, 'drives': drives})
|
||||
@ -501,7 +501,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
ok[node] = False
|
||||
except:
|
||||
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}')
|
||||
|
||||
devnodes.append(node)
|
||||
@ -568,7 +568,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
'the device has already been ejected, or your '
|
||||
'kernel is exporting a deprecated version of SYSFS.')
|
||||
%self.__class__.__name__)
|
||||
if DEBUG:
|
||||
if is_debugging():
|
||||
print('\nFound device nodes:', main, carda, cardb)
|
||||
|
||||
self._linux_mount_map = {}
|
||||
@ -614,7 +614,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
os.remove(path)
|
||||
except:
|
||||
pass
|
||||
if DEBUG and ro:
|
||||
if is_debugging() and ro:
|
||||
print('\nThe mountpoint', mp, 'is readonly, ignoring it')
|
||||
return ro
|
||||
|
||||
|
@ -13,7 +13,7 @@ from itertools import cycle
|
||||
|
||||
from calibre.constants import numeric_version, ismacos
|
||||
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.device import Device
|
||||
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)
|
||||
if base_time is None:
|
||||
debug_print.base_time = base_time = time.monotonic()
|
||||
if DEBUG:
|
||||
if is_debugging():
|
||||
prints('DEBUG: %6.1f'%(time.monotonic()-base_time), *args, **kw)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user