solaar/ui: Remove outdated logger enabled checks
Logger enabled checks clutter the code unnecessarily. The checks are now handled in a custom logger class. Eventually they can be completely removed in the future. Related #2664
This commit is contained in:
parent
636f736765
commit
f5d80c30fa
|
@ -56,8 +56,7 @@ class GtkSignal(Enum):
|
|||
|
||||
|
||||
def _startup(app, startup_hook, use_tray, show_window):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("startup registered=%s, remote=%s", app.get_is_registered(), app.get_is_remote())
|
||||
logger.debug("startup registered=%s, remote=%s", app.get_is_registered(), app.get_is_remote())
|
||||
common.start_async()
|
||||
desktop_notifications.init()
|
||||
if use_tray:
|
||||
|
@ -67,8 +66,7 @@ def _startup(app, startup_hook, use_tray, show_window):
|
|||
|
||||
|
||||
def _activate(app):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("activate")
|
||||
logger.debug("activate")
|
||||
if app.get_windows():
|
||||
window.popup()
|
||||
else:
|
||||
|
@ -81,8 +79,7 @@ def _command_line(app, command_line):
|
|||
if not args:
|
||||
_activate(app)
|
||||
elif args[0] == "config": # config call from remote instance
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
logger.info("remote command line %s", args)
|
||||
logger.info("remote command line %s", args)
|
||||
dev = find_device(args[1])
|
||||
if dev:
|
||||
setting = next((s for s in dev.settings if s.name == args[2]), None)
|
||||
|
@ -92,8 +89,7 @@ def _command_line(app, command_line):
|
|||
|
||||
|
||||
def _shutdown(_app, shutdown_hook):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("shutdown")
|
||||
logger.debug("shutdown")
|
||||
shutdown_hook()
|
||||
common.stop_async()
|
||||
tray.destroy()
|
||||
|
@ -127,8 +123,7 @@ def run_loop(
|
|||
|
||||
def _status_changed(device, alert, reason, refresh=False):
|
||||
assert device is not None
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("status changed: %s (%s) %s", device, alert, reason)
|
||||
logger.debug("status changed: %s (%s) %s", device, alert, reason)
|
||||
if alert is None:
|
||||
alert = Alert.NONE
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ def _read_async(setting, force_read, sbox, device_is_online, sensitive):
|
|||
v = s.read(not force)
|
||||
except Exception as e:
|
||||
v = None
|
||||
if logger.isEnabledFor(logging.WARNING):
|
||||
logger.warning("%s: error reading so use None (%s): %s", s.name, s._device, repr(e))
|
||||
logger.warning("%s: error reading so use None (%s): %s", s.name, s._device, repr(e))
|
||||
GLib.idle_add(_update_setting_item, sb, v, online, sensitive, True, priority=99)
|
||||
|
||||
ui_async(_do_read, setting, force_read, sbox, device_is_online, sensitive)
|
||||
|
@ -694,8 +693,7 @@ def _create_sbox(s, _device):
|
|||
elif s.kind == settings.Kind.HETERO:
|
||||
control = HeteroKeyControl(sbox, change)
|
||||
else:
|
||||
if logger.isEnabledFor(logging.WARNING):
|
||||
logger.warning("setting %s display not implemented", s.label)
|
||||
logger.warning("setting %s display not implemented", s.label)
|
||||
return None
|
||||
|
||||
control.set_sensitive(False) # the first read will enable it
|
||||
|
@ -821,10 +819,9 @@ def record_setting(device, setting, values):
|
|||
|
||||
|
||||
def _record_setting(device, setting_class, values):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("on %s changing setting %s to %s", device, setting_class.name, values)
|
||||
logger.debug("on %s changing setting %s to %s", device, setting_class.name, values)
|
||||
setting = next((s for s in device.settings if s.name == setting_class.name), None)
|
||||
if setting is None and logger.isEnabledFor(logging.DEBUG):
|
||||
if setting is None:
|
||||
logger.debug(
|
||||
"No setting for %s found on %s when trying to record a change made elsewhere",
|
||||
setting_class.name,
|
||||
|
|
|
@ -58,8 +58,7 @@ if available:
|
|||
global available
|
||||
if available:
|
||||
if not Notify.is_initted():
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
logger.info("starting desktop notifications")
|
||||
logger.info("starting desktop notifications")
|
||||
try:
|
||||
return Notify.init(NAME.lower())
|
||||
except Exception:
|
||||
|
@ -70,8 +69,7 @@ if available:
|
|||
def uninit():
|
||||
"""Stop desktop notifications."""
|
||||
if available and Notify.is_initted():
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
logger.info("stopping desktop notifications")
|
||||
logger.info("stopping desktop notifications")
|
||||
_notifications.clear()
|
||||
Notify.uninit()
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ def _init_icon_paths():
|
|||
return
|
||||
|
||||
_default_theme = Gtk.IconTheme.get_default()
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("icon theme paths: %s", _default_theme.get_search_path())
|
||||
logger.debug("icon theme paths: %s", _default_theme.get_search_path())
|
||||
|
||||
if gtk.battery_icons_style == "symbolic":
|
||||
global TRAY_OKAY
|
||||
|
@ -57,8 +56,7 @@ def battery(level=None, charging=False):
|
|||
if not _default_theme.has_icon(icon_name):
|
||||
logger.warning("icon %s not found in current theme", icon_name)
|
||||
return TRAY_OKAY # use Solaar icon if battery icon not available
|
||||
elif logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("battery icon for %s:%s = %s", level, charging, icon_name)
|
||||
logger.debug("battery icon for %s:%s = %s", level, charging, icon_name)
|
||||
return icon_name
|
||||
|
||||
|
||||
|
|
|
@ -99,8 +99,7 @@ def prepare(receiver):
|
|||
|
||||
def check_lock_state(assistant, receiver, count=2):
|
||||
if not assistant.is_drawable():
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("assistant %s destroyed, bailing out", assistant)
|
||||
logger.debug("assistant %s destroyed, bailing out", assistant)
|
||||
return False
|
||||
return _check_lock_state(assistant, receiver, count)
|
||||
|
||||
|
@ -136,21 +135,18 @@ def _check_lock_state(assistant, receiver, count):
|
|||
|
||||
def _pairing_failed(assistant, receiver, error):
|
||||
assistant.remove_page(0) # needed to reset the window size
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("%s fail: %s", receiver, error)
|
||||
logger.debug("%s fail: %s", receiver, error)
|
||||
_create_failure_page(assistant, error)
|
||||
|
||||
|
||||
def _pairing_succeeded(assistant, receiver, device):
|
||||
assistant.remove_page(0) # needed to reset the window size
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("%s success: %s", receiver, device)
|
||||
logger.debug("%s success: %s", receiver, device)
|
||||
_create_success_page(assistant, device)
|
||||
|
||||
|
||||
def _finish(assistant, receiver):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("finish %s", assistant)
|
||||
logger.debug("finish %s", assistant)
|
||||
assistant.destroy()
|
||||
receiver.pairing.new_device = None
|
||||
if receiver.pairing.lock_open:
|
||||
|
@ -165,8 +161,7 @@ def _finish(assistant, receiver):
|
|||
|
||||
|
||||
def _show_passcode(assistant, receiver, passkey):
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("%s show passkey: %s", receiver, passkey)
|
||||
logger.debug("%s show passkey: %s", receiver, passkey)
|
||||
name = receiver.pairing.device_name
|
||||
authentication = receiver.pairing.device_authentication
|
||||
intro_text = _("%(receiver_name)s: pair new device") % {"receiver_name": receiver.name}
|
||||
|
|
|
@ -132,8 +132,7 @@ def _scroll(tray_icon, event, direction=None):
|
|||
_picked_device = None
|
||||
|
||||
_picked_device = candidate or _picked_device
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("scroll: picked %s", _picked_device)
|
||||
logger.debug("scroll: picked %s", _picked_device)
|
||||
_update_tray_icon()
|
||||
|
||||
|
||||
|
@ -153,8 +152,7 @@ try:
|
|||
# treat unavailable versions the same as unavailable packages
|
||||
raise ImportError from exc
|
||||
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug(f"using {'Ayatana ' if ayatana_appindicator_found else ''}AppIndicator3")
|
||||
logger.debug(f"using {'Ayatana ' if ayatana_appindicator_found else ''}AppIndicator3")
|
||||
|
||||
# Defense against AppIndicator3 bug that treats files in current directory as icon files
|
||||
# https://bugs.launchpad.net/ubuntu/+source/libappindicator/+bug/1363277
|
||||
|
@ -212,8 +210,7 @@ try:
|
|||
GLib.timeout_add(10 * 1000, _icon.set_status, AppIndicator3.IndicatorStatus.ACTIVE)
|
||||
|
||||
except ImportError:
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("using StatusIcon")
|
||||
logger.debug("using StatusIcon")
|
||||
|
||||
def _create(menu):
|
||||
icon = Gtk.StatusIcon.new_from_icon_name(icons.TRAY_INIT)
|
||||
|
@ -317,8 +314,7 @@ def _pick_device_with_lowest_battery():
|
|||
picked = info
|
||||
picked_level = level or 0
|
||||
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("picked device with lowest battery: %s", picked)
|
||||
logger.debug("picked device with lowest battery: %s", picked)
|
||||
|
||||
return picked
|
||||
|
||||
|
|
|
@ -411,8 +411,7 @@ def _receiver_row(receiver_path, receiver=None):
|
|||
status_icon = None
|
||||
row_data = (receiver_path, 0, True, receiver.name, icon_name, status_text, status_icon, receiver)
|
||||
assert len(row_data) == len(_TREE_SEPATATOR)
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("new receiver row %s", row_data)
|
||||
logger.debug("new receiver row %s", row_data)
|
||||
item = _model.append(None, row_data)
|
||||
if _TREE_SEPATATOR:
|
||||
_model.append(None, _TREE_SEPATATOR)
|
||||
|
@ -465,8 +464,7 @@ def _device_row(receiver_path, device_number, device=None):
|
|||
device,
|
||||
)
|
||||
assert len(row_data) == len(_TREE_SEPATATOR)
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("new device row %s at index %d", row_data, new_child_index)
|
||||
logger.debug("new device row %s at index %d", row_data, new_child_index)
|
||||
item = _model.insert(receiver_row, new_child_index, row_data)
|
||||
|
||||
return item or None
|
||||
|
|
Loading…
Reference in New Issue