Preferring string interpolation to format operator

parent 766a4ae0
......@@ -93,35 +93,35 @@ class Application(Gtk.Application):
logging.getLogger().setLevel(logging.DEBUG)
for handler in logging.getLogger().handlers:
handler.formatter = logging.Formatter(LOG_DEBUG_FORMAT)
LOG.debug("Option %s selected", _Options.DEBUG.value)
LOG.debug(f"Option {_Options.DEBUG.value} selected")
if _Options.VERSION.value in options:
LOG.debug("Option %s selected", _Options.VERSION.value)
LOG.debug(f"Option {_Options.VERSION.value} selected")
print(APP_VERSION)
start_app = False
if _Options.HIDE_WINDOW.value in options:
LOG.debug("Option %s selected", _Options.HIDE_WINDOW.value)
LOG.debug(f"Option {_Options.HIDE_WINDOW.value} selected")
self._start_hidden = True
if _Options.APPLICATION_ENTRY.value in options:
LOG.debug("Option %s selected", _Options.APPLICATION_ENTRY.value)
LOG.debug(f"Option {_Options.APPLICATION_ENTRY.value} selected")
add_application_entry()
start_app = False
if _Options.AUTOSTART_ON.value in options:
LOG.debug("Option %s selected", _Options.AUTOSTART_ON.value)
LOG.debug(f"Option {_Options.AUTOSTART_ON.value} selected")
set_autostart_entry(True)
start_app = False
if _Options.AUTOSTART_OFF.value in options:
LOG.debug("Option %s selected", _Options.AUTOSTART_OFF.value)
LOG.debug(f"Option {_Options.AUTOSTART_OFF.value} selected")
set_autostart_entry(True)
start_app = False
if _Options.CTRL_DISPLAY.value in options:
param = options[_Options.CTRL_DISPLAY.value]
LOG.debug("Option %s selected: %s", _Options.CTRL_DISPLAY.value, param)
LOG.debug(f"Option {_Options.CTRL_DISPLAY.value} selected: {param}")
self._nvidia_repository.set_ctrl_display(param)
if start_app:
......
......@@ -38,6 +38,8 @@ EditOverclockProfileBuilder = Key(APP_EDIT_OC_PROFILE_UI_NAME)
HistoricalDataBuilder = Key(APP_HISTORICAL_DATA_UI_NAME)
PreferencesBuilder = Key(APP_PREFERENCES_UI_NAME)
_UI_RESOURCE_PATH = "/com/leinardi/gwe/ui/{}"
# pylint: disable=no-self-use
class ProviderModule(Module):
......@@ -47,7 +49,7 @@ class ProviderModule(Module):
LOG.debug("provide Gtk.Builder")
builder = Gtk.Builder()
builder.set_translation_domain(APP_PACKAGE_NAME)
builder.add_from_resource("/com/leinardi/gwe/ui/{}".format(APP_MAIN_UI_NAME))
builder.add_from_resource(_UI_RESOURCE_PATH.format(APP_MAIN_UI_NAME))
return builder
@singleton
......@@ -56,7 +58,7 @@ class ProviderModule(Module):
LOG.debug("provide Gtk.Builder")
builder = Gtk.Builder()
builder.set_translation_domain(APP_PACKAGE_NAME)
builder.add_from_resource("/com/leinardi/gwe/ui/{}".format(APP_EDIT_FAN_PROFILE_UI_NAME))
builder.add_from_resource(_UI_RESOURCE_PATH.format(APP_EDIT_FAN_PROFILE_UI_NAME))
return builder
@singleton
......@@ -65,7 +67,7 @@ class ProviderModule(Module):
LOG.debug("provide Gtk.Builder")
builder = Gtk.Builder()
builder.set_translation_domain(APP_PACKAGE_NAME)
builder.add_from_resource("/com/leinardi/gwe/ui/{}".format(APP_EDIT_OC_PROFILE_UI_NAME))
builder.add_from_resource(_UI_RESOURCE_PATH.format(APP_EDIT_OC_PROFILE_UI_NAME))
return builder
@singleton
......@@ -74,7 +76,7 @@ class ProviderModule(Module):
LOG.debug("provide Gtk.Builder")
builder = Gtk.Builder()
builder.set_translation_domain(APP_PACKAGE_NAME)
builder.add_from_resource("/com/leinardi/gwe/ui/{}".format(APP_HISTORICAL_DATA_UI_NAME))
builder.add_from_resource(_UI_RESOURCE_PATH.format(APP_HISTORICAL_DATA_UI_NAME))
return builder
@singleton
......@@ -83,7 +85,7 @@ class ProviderModule(Module):
LOG.debug("provide Gtk.Builder")
builder = Gtk.Builder()
builder.set_translation_domain(APP_PACKAGE_NAME)
builder.add_from_resource("/com/leinardi/gwe/ui/{}".format(APP_PREFERENCES_UI_NAME))
builder.add_from_resource(_UI_RESOURCE_PATH.format(APP_PREFERENCES_UI_NAME))
return builder
@singleton
......
......@@ -193,7 +193,7 @@ class FanProfileType(Enum):
class FanProfile(Model):
id = AutoIncrementField()
type = CharField(
constraints=[Check("type='%s' OR type='%s'" % (FanProfileType.AUTO.value, FanProfileType.FAN_CURVE.value))],
constraints=[Check(f"type='{FanProfileType.AUTO.value}' OR type='{FanProfileType.FAN_CURVE.value}'")],
default=FanProfileType.FAN_CURVE.value)
name = CharField()
read_only = BooleanField(default=False)
......@@ -256,8 +256,8 @@ class OverclockProfileType(Enum):
class OverclockProfile(Model):
id = AutoIncrementField()
type = CharField(
constraints=[Check("type='%s' OR type='%s'" % (
OverclockProfileType.DEFAULT.value, OverclockProfileType.OFFSET.value))],
constraints=[Check(f"type='{OverclockProfileType.DEFAULT.value}' "
f"OR type='{OverclockProfileType.OFFSET.value}'")],
default=OverclockProfileType.OFFSET.value)
name = CharField()
gpu = IntegerField(default=0)
......
......@@ -109,6 +109,6 @@ class EditOverclockProfilePresenter:
@staticmethod
def _handle_set_overclock_result(result: Any) -> bool:
if not isinstance(result, bool) or not result:
LOG.exception("Set overclock error: %s", str(result))
LOG.exception(f"Set overclock error: {str(result)}")
return False
return True
......@@ -215,12 +215,12 @@ class MainPresenter:
def _register_db_listeners(self) -> None:
self._speed_step_changed_subject.subscribe(on_next=self._on_speed_step_list_changed,
on_error=lambda e: LOG.exception("Db signal error: %s", str(e)))
on_error=lambda e: LOG.exception(f"Db signal error: {str(e)}"))
self._fan_profile_changed_subject.subscribe(on_next=self._on_fan_profile_list_changed,
on_error=lambda e: LOG.exception("Db signal error: %s", str(e)))
on_error=lambda e: LOG.exception(f"Db signal error: {str(e)}"))
self._overclock_profile_changed_subject.subscribe(on_next=self._on_overclock_profile_list_changed,
on_error=lambda e: LOG.exception("Db signal error: %s",
str(e)))
on_error=lambda e: LOG.exception(
f"Db signal error: {str(e)}"))
def _on_speed_step_list_changed(self, db_change: DbChange) -> None:
profile = db_change.entry.profile
......@@ -256,7 +256,7 @@ class MainPresenter:
.flat_map(lambda _: self._get_status())
.observe_on(GtkScheduler())
.subscribe(on_next=self._on_status_updated,
on_error=lambda e: LOG.exception("Refresh error: %s", str(e)))
on_error=lambda e: LOG.exception(f"Refresh error: {str(e)}"))
)
def _on_status_updated(self, status: Optional[Status]) -> None:
......@@ -289,7 +289,7 @@ class MainPresenter:
if fan.fan_list and fan.fan_list[0][0] != speed:
self._set_fan_speed(gpu_status.index, round(speed))
except ValueError:
LOG.exception('Unable to parse temperature %s', gpu_status.temp.gpu)
LOG.exception(f'Unable to parse temperature {gpu_status.temp.gpu}')
@staticmethod
def _get_fan_duty(profile: FanProfile, gpu_temperature: float) -> float:
......@@ -313,7 +313,7 @@ class MainPresenter:
data: List[Tuple[int, str]] = []
for fan_profile in FanProfile.select():
if self._fan_profile_applied is not None and self._fan_profile_applied.id == fan_profile.id:
name = "<b>%s</b>" % fan_profile.name
name = f"<b>{fan_profile.name}</b>"
else:
name = fan_profile.name
data.append((fan_profile.id, name))
......@@ -346,7 +346,7 @@ class MainPresenter:
.add(self._set_fan_speed_interactor.execute(gpu_index, speed, manual_control)
.subscribe_on(self._scheduler)
.observe_on(GtkScheduler())
.subscribe(on_error=lambda e: (LOG.exception("Set cooling error: %s", str(e)),
.subscribe(on_error=lambda e: (LOG.exception(f"Set cooling error: {str(e)}"),
self.main_view.set_statusbar_text('Error applying fan profile!'))))
def _update_current_fan_profile(self, profile: FanProfile) -> None:
......@@ -356,7 +356,7 @@ class MainPresenter:
else:
current.profile = profile
current.save()
self.main_view.set_statusbar_text('%s fan profile selected' % profile.name)
self.main_view.set_statusbar_text(f'{profile.name} fan profile selected')
def _refresh_overclock_profile_ui(self, init: bool = False, profile_id: Optional[int] = None) -> None:
gpu_index = 0
......@@ -375,7 +375,7 @@ class MainPresenter:
overclock_profile.memory)
if self._overclock_profile_applied is not None \
and self._overclock_profile_applied.id == overclock_profile.id:
name = "<b>{}</b>".format(name_with_freqs)
name = f"<b>{name_with_freqs}</b>"
else:
name = name_with_freqs
data.append((overclock_profile.id, name))
......@@ -410,10 +410,10 @@ class MainPresenter:
else:
current.profile = profile
current.save()
self.main_view.set_statusbar_text('%s overclock profile selected' % profile.name)
self.main_view.set_statusbar_text(f'{profile.name} overclock profile selected')
def _log_exception_return_empty_observable(self, ex: Exception) -> Observable:
LOG.exception("Err = %s", ex)
LOG.exception(f"Err = {ex}")
self.main_view.set_statusbar_text(str(ex))
return Observable.just(None)
......@@ -427,7 +427,7 @@ class MainPresenter:
.subscribe_on(self._scheduler)
.observe_on(GtkScheduler())
.subscribe(on_next=self._handle_new_version_response,
on_error=lambda e: LOG.exception("Check new version error: %s", str(e)))
on_error=lambda e: LOG.exception(f"Check new version error: {str(e)}"))
)
def _handle_set_power_limit_result(self, result: Any) -> None:
......@@ -439,24 +439,24 @@ class MainPresenter:
def _handle_generic_set_result(self, result: Any, name: str) -> bool:
if not isinstance(result, bool):
LOG.exception("Set overclock error: %s", str(result))
self.main_view.set_statusbar_text('Error applying %s! %s' % (name, str(result)))
LOG.exception(f"Set overclock error: {str(result)}")
self.main_view.set_statusbar_text(f'Error applying {name}! {str(result)}')
return False
if not result:
self.main_view.set_statusbar_text('Error applying %s!' % name)
self.main_view.set_statusbar_text(f'Error applying {name}!')
return False
self.main_view.set_statusbar_text('%s applied' % name.capitalize())
self.main_view.set_statusbar_text(f'{name.capitalize()} applied')
return True
def _handle_new_version_response(self, version: Optional[str]) -> None:
if version is not None:
message = "%s version <b>%s</b> is available! Click <a href=\"%s\"><b>here</b></a> " \
"to see what's new." % (APP_NAME, version, self._get_changelog_uri(version))
message = f"{APP_NAME} version <b>{version}</b> is available! " \
f"Click <a href=\"{self._get_changelog_uri(version)}\"><b>here</b></a> to see what's new."
self.main_view.show_main_infobar_message(message, True)
message = "%s version <b>%s</b> is available! Click here to see what's new: %s" \
% (APP_NAME, version, self._get_changelog_uri(version))
message = f"{APP_NAME} version <b>{version}</b> is available! " \
f"lick here to see what's new: {self._get_changelog_uri(version)}"
show_notification("GWE update available!", message, "dialog-information")
@staticmethod
def _get_changelog_uri(version: str = APP_VERSION) -> str:
return "{}/blob/{}/CHANGELOG.md".format(APP_SOURCE_URL, version)
return f"{APP_SOURCE_URL}/blob/{version}/CHANGELOG.md"
......@@ -224,7 +224,7 @@ class NvidiaRepository:
'-pl',
str(limit)]
result = run_and_get_stdout(cmd)
LOG.info("Exit code: %d. %s", result[0], result[1])
LOG.info(f"Exit code: {result[0]}. {result[1]}")
return result[0] == 0
def set_all_gpus_fan_to_auto(self) -> None:
......@@ -253,10 +253,10 @@ class NvidiaRepository:
return a_function(*args)
except NVMLError as err:
if err.value == NVML_ERROR_NOT_SUPPORTED:
LOG.debug("Function %s not supported", a_function.__name__)
LOG.debug(f"Function {a_function.__name__} not supported")
return None
if err.value == NVML_ERROR_UNKNOWN:
LOG.warning("Unknown error while executing function %s", a_function.__name__)
LOG.warning(f"Unknown error while executing function {a_function.__name__}")
return None
LOG.error("Error value = %d ", err.value)
raise err
......
......@@ -51,11 +51,11 @@ class DesktopParser(object):
for key, value in self.__property_list:
if key.lower() == name.lower():
return value
raise KeyError('%s' % name)
raise KeyError(name)
def set(self, name: str, value: str) -> None:
if not name:
raise ValueError("Invalid value for name: '%s'" % name)
raise ValueError(f"Invalid value for name: '{name}'")
for i, (key, _) in enumerate(self.__property_list):
if key.lower() == name.lower():
......@@ -81,4 +81,4 @@ class DesktopParser(object):
if value in ("0", "no", "false", "off"):
return False
raise ValueError("Cannot coerce '%s' to boolean" % value)
raise ValueError(f"Cannot coerce '{value}' to boolean")
......@@ -36,7 +36,7 @@ def set_autostart_entry(is_enabled: bool) -> None:
for key, value in DESKTOP_ENTRY.items():
desktop_parser.set(key, value)
desktop_parser.set(DESKTOP_ENTRY_ICON, get_data_path(APP_ICON_NAME))
desktop_parser.set(DESKTOP_ENTRY_EXEC, '%s --hide-window' % APP_PACKAGE_NAME)
desktop_parser.set(DESKTOP_ENTRY_EXEC, f'{APP_PACKAGE_NAME} --hide-window')
desktop_parser.set(AUTOSTART_FLAG, str(is_enabled).lower())
desktop_parser.write()
......
......@@ -30,7 +30,7 @@ UDEV_RULE_FILE_NAME = '60-gwe.rules'
def add_udev_rule() -> int:
if os.geteuid() == 0:
if not os.path.isdir(UDEV_RULES_DIR):
LOG.error("Udev rules have not been added (%s is not a directory)", UDEV_RULES_DIR)
LOG.error(f"Udev rules have not been added ({UDEV_RULES_DIR} is not a directory)")
return 1
try:
shutil.copy(get_data_path(UDEV_RULE_FILE_NAME), UDEV_RULES_DIR)
......@@ -55,7 +55,7 @@ def remove_udev_rule() -> int:
if os.geteuid() == 0:
path = Path(UDEV_RULES_DIR).joinpath(UDEV_RULE_FILE_NAME)
if not path.is_file():
LOG.error("Unable to add udev rule (file %s not found)", str(path))
LOG.error(f"Unable to add udev rule (file {str(path)} not found)")
return 1
try:
path.unlink()
......
......@@ -151,7 +151,7 @@ class EditFanProfileView(EditFanProfileViewInterface):
self._temperature_adjustment.set_lower(MIN_TEMP)
self._duty_adjustment.set_lower(FAN_MIN_DUTY)
else:
LOG.debug("prev = %s", prev_steps[0].temperature)
LOG.debug(f"prev = {prev_steps[0].temperature}")
self._temperature_adjustment.set_lower(prev_steps[0].temperature + 1)
self._duty_adjustment.set_lower(prev_steps[0].duty)
......
......@@ -60,10 +60,10 @@ class HistoricalDataView(HistoricalDataViewInterface):
self._graph_views: Dict[GraphType, Tuple[Gtk.Label, Gtk.Label, Gtk.Label]] = {}
self._graph_models: Dict[GraphType, Dazzle.GraphModel] = {}
for graph_type in GraphType:
self._graph_container: Gtk.Frame = self._builder.get_object('graph_container_%d' % graph_type.value)
self._graph_views[graph_type] = (self._builder.get_object('graph_min_value_%d' % graph_type.value),
self._builder.get_object('graph_max_value_%d' % graph_type.value),
self._builder.get_object('graph_max_axis_%d' % graph_type.value))
self._graph_container: Gtk.Frame = self._builder.get_object(f'graph_container_{graph_type.value}')
self._graph_views[graph_type] = (self._builder.get_object(f'graph_min_value_{graph_type.value}'),
self._builder.get_object(f'graph_max_value_{graph_type.value}'),
self._builder.get_object(f'graph_max_axis_{graph_type.value}'))
graph_views = Dazzle.GraphView()
graph_model = Dazzle.GraphModel()
graph_renderer = GraphStackedRenderer()
......@@ -102,23 +102,23 @@ class HistoricalDataView(HistoricalDataViewInterface):
self._graph_models[graph_type].props.value_max = max(data_tuple[4], max_value)
graph_model_iter = self._graph_models[graph_type].push(GLib.get_monotonic_time())
self._graph_models[graph_type].iter_set(graph_model_iter, 0, data_tuple[1])
self._graph_views[graph_type][2].set_text("%.0f %s" % (data_tuple[1], data_tuple[2]))
self._graph_views[graph_type][2].set_text(f"{data_tuple[1]:.0f} {data_tuple[2]}")
model_iter = Dazzle.GraphModelIter()
if self._dialog.props.visible and self._graph_models[graph_type].get_iter_first(model_iter):
min_value = data_tuple[4] * 10
max_value = data_tuple[3]
while Dazzle.GraphModel.iter_next(model_iter):
while Dazzle.GraphModel.iter_next(iter=model_iter):
gval = GObject.Value()
Dazzle.GraphModel.iter_get_value(model_iter, 0, gval)
Dazzle.GraphModel.iter_get_value(iter=model_iter, column=0, value=gval)
val = gval.get_double()
min_value = min(val, min_value)
max_value = max(val, max_value)
self._graph_views[graph_type][0].set_text("%.0f" % min_value)
self._graph_views[graph_type][1].set_text("%.0f" % max_value)
self._graph_views[graph_type][0].set_text(f"{min_value:.0f}")
self._graph_views[graph_type][1].set_text(f"{max_value:.0f}")
self._graph_models[graph_type].props.value_max = max(data_tuple[4], max_value)
time2 = time.time()
LOG.debug('Refresh graph took {%.3f} ms', ((time2 - time1) * 1000.0))
LOG.debug(f'Refresh graph took {((time2 - time1) * 1000.0):.3f} ms')
def show(self) -> None:
self._dialog.show_all()
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment