From 9b59707a10c46c1d8020b2c88868056d7985aeb1 Mon Sep 17 00:00:00 2001 From: aznd <80119822+aznd@users.noreply.github.com> Date: Tue, 1 Feb 2022 22:29:34 +0100 Subject: [PATCH] Unify strings formatting (#158) * Part 1: Unifying strings * Part 2: Unifying strings * Part 3: Unifying strings * Fix missing close bracket * Remove unneeded str() --- rare/__main__.py | 2 +- rare/app.py | 5 ++--- rare/components/dialogs/launch_dialog.py | 2 +- rare/components/dialogs/login/import_login.py | 4 ++-- rare/components/tabs/account/__init__.py | 2 +- rare/components/tabs/downloads/__init__.py | 4 ++-- .../components/tabs/downloads/dl_queue_widget.py | 6 +++--- .../components/tabs/downloads/download_thread.py | 2 +- rare/components/tabs/games/__init__.py | 16 ++++++++-------- rare/components/tabs/games/cloud_save_utils.py | 6 +++--- .../tabs/games/game_info/game_settings.py | 14 +++++++------- rare/components/tabs/games/game_utils.py | 4 ++-- .../games/game_widgets/base_installed_widget.py | 2 +- .../games/game_widgets/installed_icon_widget.py | 2 +- .../games/game_widgets/installed_list_widget.py | 4 ++-- .../games/game_widgets/installing_game_widget.py | 2 +- .../tabs/games/import_sync/egl_sync_group.py | 2 +- .../tabs/games/import_sync/import_group.py | 2 +- rare/components/tabs/settings/about.py | 2 +- rare/components/tabs/settings/dxvk.py | 2 +- rare/components/tabs/settings/legendary.py | 2 +- rare/components/tabs/settings/rare.py | 6 +++--- rare/components/tabs/shop/game_info.py | 2 +- rare/components/tabs/shop/shop_api_core.py | 12 ++++++------ rare/components/tabs/shop/shop_widget.py | 6 +++--- rare/utils/legendary_utils.py | 10 +++++----- rare/utils/rpc.py | 10 +++++----- rare/utils/singleton.py | 4 ++-- rare/utils/steam_grades.py | 2 +- rare/utils/utils.py | 16 ++++++++-------- 30 files changed, 77 insertions(+), 78 deletions(-) diff --git a/rare/__main__.py b/rare/__main__.py index ff039c43..b1dcdc62 100644 --- a/rare/__main__.py +++ b/rare/__main__.py @@ -84,7 +84,7 @@ def main(): with open(os.path.join(data_dir, "lockfile"), "w") as file: if args.subparser == "launch": - file.write("launch " + args.app_name) + file.write(f"launch {args.app_name}") else: file.write("start") file.close() diff --git a/rare/app.py b/rare/app.py index 4e111c6f..1a523747 100644 --- a/rare/app.py +++ b/rare/app.py @@ -112,7 +112,7 @@ class App(QApplication): if os.path.isfile(f := os.path.join(resources_path, "languages", f"{lang}.qm")): self.translator.load(f) - logger.info("Your language is supported: " + lang) + logger.info(f"Your language is supported: {lang}") elif not lang == "en": logger.info("Your language is not supported") self.installTranslator(self.translator) @@ -189,8 +189,7 @@ class App(QApplication): i.app_name for i in self.core.get_installed_list() ]: logger.info( - "Launching " - + self.core.get_installed_game(shared.args.app_name).title + f"Launching {self.core.get_installed_game(shared.args.app_name).title}" ) self.mainwindow.tab_widget.games_tab.game_utils.prepare_launch( shared.args.app_name diff --git a/rare/components/dialogs/launch_dialog.py b/rare/components/dialogs/launch_dialog.py index bd1b1318..cac99059 100644 --- a/rare/components/dialogs/launch_dialog.py +++ b/rare/components/dialogs/launch_dialog.py @@ -142,7 +142,7 @@ class LaunchDialog(QDialog, Ui_LaunchDialog): self.finish() def handle_api_worker_result(self, result, text): - logger.debug("Api Request got from " + text) + logger.debug(f"Api Request got from {text}") if text == "gamelist": if result: self.api_results.game_list, self.api_results.dlcs = result diff --git a/rare/components/dialogs/login/import_login.py b/rare/components/dialogs/login/import_login.py index 087a1070..3859bc11 100644 --- a/rare/components/dialogs/login/import_login.py +++ b/rare/components/dialogs/login/import_login.py @@ -106,5 +106,5 @@ class ImportLogin(QWidget, Ui_ImportLogin): self.status_label.setText(self.tr("Login failed.")) logger.warning("Failed to import existing session.") except Exception as e: - self.status_label.setText(self.tr("Login failed. ") + str(e)) - logger.warning("Failed to import existing session: " + str(e)) + self.status_label.setText(self.tr("Login failed. {}").format(str(e))) + logger.warning(f"Failed to import existing session: {e}") diff --git a/rare/components/tabs/account/__init__.py b/rare/components/tabs/account/__init__.py index d7cb2794..8c938822 100644 --- a/rare/components/tabs/account/__init__.py +++ b/rare/components/tabs/account/__init__.py @@ -16,7 +16,7 @@ class MiniWidget(QWidget): if not username: username = "Offline" - self.layout.addWidget(QLabel(self.tr("Logged in as ") + str(username))) + self.layout.addWidget(QLabel(self.tr("Logged in as {}").format(username))) self.open_browser = QPushButton(self.tr("Account settings")) self.open_browser.clicked.connect( diff --git a/rare/components/tabs/downloads/__init__.py b/rare/components/tabs/downloads/__init__.py index 362b73ad..8722ee83 100644 --- a/rare/components/tabs/downloads/__init__.py +++ b/rare/components/tabs/downloads/__init__.py @@ -146,7 +146,7 @@ class DownloadsTab(QWidget, Ui_DownloadsTab): def status(self, text): if text == "finish": self.dl_name.setText(self.tr("Download finished. Reload library")) - logger.info("Download finished: " + self.active_game.app_title) + logger.info(f"Download finished: {self.active_game.app_title}") game = self.active_game self.active_game = None @@ -180,7 +180,7 @@ class DownloadsTab(QWidget, Ui_DownloadsTab): self.queue_widget.update_queue(self.dl_queue) elif text[:5] == "error": - QMessageBox.warning(self, "warn", "Download error: " + text[6:]) + QMessageBox.warning(self, "warn", f"Download error: {text[6:]}") elif text == "stop": self.reset_infos() diff --git a/rare/components/tabs/downloads/dl_queue_widget.py b/rare/components/tabs/downloads/dl_queue_widget.py index d507de20..2b0455c1 100644 --- a/rare/components/tabs/downloads/dl_queue_widget.py +++ b/rare/components/tabs/downloads/dl_queue_widget.py @@ -117,7 +117,7 @@ class DlQueueWidget(QGroupBox): self.item_removed.emit(app_name) break else: - logger.warning("BUG! " + app_name) + logger.warning(f"BUG! {app_name}") return self.update_list.emit(self.dl_queue) self.update_queue(self.dl_queue) @@ -130,7 +130,7 @@ class DlQueueWidget(QGroupBox): index = i break else: - logger.warning("Could not find appname" + app_name) + logger.warning(f"Could not find appname {app_name}") return self.dl_queue.insert(index - 1, self.dl_queue.pop(index)) self.update_list.emit(self.dl_queue) @@ -144,7 +144,7 @@ class DlQueueWidget(QGroupBox): index = i break else: - logger.warning("infoCould not find appname" + app_name) + logger.warning(f"Info: Could not find appname {app_name}") return self.dl_queue.insert(index + 1, self.dl_queue.pop(index)) self.update_list.emit(self.dl_queue) diff --git a/rare/components/tabs/downloads/download_thread.py b/rare/components/tabs/downloads/download_thread.py index 978219ed..ee04902e 100644 --- a/rare/components/tabs/downloads/download_thread.py +++ b/rare/components/tabs/downloads/download_thread.py @@ -134,7 +134,7 @@ class DownloadThread(QThread): logger.error( f"Installation failed after {time.time() - start_time:.02f} seconds: {e}" ) - self.status.emit("error " + str(e)) + self.status.emit(f"error {e}") return else: diff --git a/rare/components/tabs/games/__init__.py b/rare/components/tabs/games/__init__.py index 3139a207..d05d67ea 100644 --- a/rare/components/tabs/games/__init__.py +++ b/rare/components/tabs/games/__init__.py @@ -214,7 +214,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): pixmap = get_pixmap(app_name) try: if pixmap.isNull(): - logger.info(app_name + " has a corrupt image.") + logger.info(f"{app_name} has a corrupt image.") if app_name in self.no_asset_names and self.core.get_asset(app_name).namespace != "ue": download_image(self.core.get_game(app_name), force=True) pixmap = get_pixmap(app_name) @@ -224,7 +224,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): icon_widget = InstalledIconWidget(app_name, pixmap, self.game_utils) list_widget = InstalledListWidget(app_name, pixmap, self.game_utils) except Exception as e: - logger.error(app_name + " is broken. Don't add it to game list: " + str(e)) + logger.error(f"{app_name} is broken. Don't add it to game list: {e}") return self.widgets[app_name] = (icon_widget, list_widget) @@ -241,7 +241,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): try: if pixmap.isNull(): if self.core.get_asset(game.app_name).namespace != "ue": - logger.warning(game.app_title + " has a corrupt image. Reloading...") + logger.warning(f"{game.app_title} has a corrupt image. Reloading...") download_image(game, force=True) pixmap = get_uninstalled_pixmap(game.app_name) elif self.ue_name: @@ -250,7 +250,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): icon_widget = IconWidgetUninstalled(game, self.core, pixmap) list_widget = ListWidgetUninstalled(self.core, game, pixmap) except Exception as e: - logger.error(game.app_name + " is broken. Don't add it to game list: " + str(e)) + logger.error(f"{game.app_name} is broken. Don't add it to game list: {e}") return icon_widget.show_uninstalled_info.connect(self.show_uninstalled_info) @@ -315,7 +315,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): self.installing_widget.setVisible(get_visibility(self.installing_widget)) def update_list(self, app_names: list = None): - logger.debug("Updating list for " + str(app_names)) + logger.debug(f"Updating list for {app_names}") if app_names: update_list = False for app_name in app_names: @@ -325,7 +325,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): if self.core.is_installed(widgets[0].game.app_name) and isinstance( widgets[0], BaseInstalledWidget ): - logger.debug("Update Gamelist: Updated: " + app_name) + logger.debug(f"Update Gamelist: Updated: {app_name}") igame = self.core.get_installed_game(app_name) for w in widgets: w.igame = igame @@ -340,7 +340,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): elif self.core.is_installed(app_name) and isinstance( widgets[0], BaseUninstalledWidget ): - logger.debug("Update Gamelist: New installed " + app_name) + logger.debug(f"Update Gamelist: New installed {app_name}") self.widgets[app_name][0].deleteLater() self.widgets[app_name][1].deleteLater() self.widgets.pop(app_name) @@ -352,7 +352,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab): elif not self.core.is_installed( widgets[0].game.app_name ) and isinstance(widgets[0], BaseInstalledWidget): - logger.debug("Update list: Uninstalled: " + app_name) + logger.debug(f"Update list: Uninstalled: {app_name}") self.widgets[app_name][0].deleteLater() self.widgets[app_name][1].deleteLater() diff --git a/rare/components/tabs/games/cloud_save_utils.py b/rare/components/tabs/games/cloud_save_utils.py index 78353332..2109b470 100644 --- a/rare/components/tabs/games/cloud_save_utils.py +++ b/rare/components/tabs/games/cloud_save_utils.py @@ -288,13 +288,13 @@ class CloudSaveUtils(QObject): self.download_saves(igame) def upload_saves(self, igame: InstalledGame, dt_local): - logger.info("Uploading saves for " + igame.title) + logger.info(f"Uploading saves for {igame.title}") w = SaveWorker(UploadModel(igame.app_name, dt_local, igame.save_path)) w.signals.finished.connect(self.worker_finished) self.thread_pool.start(w) def download_saves(self, igame): - logger.info("Downloading saves for " + igame.title) + logger.info(f"Downloading saves for {igame.title}") w = SaveWorker( DownloadModel( igame.app_name, self.latest_saves.get(igame.app_name), igame.save_path @@ -312,7 +312,7 @@ class CloudSaveUtils(QObject): QMessageBox.warning( None, "Warning", - self.tr("Syncing with cloud failed: \n ") + error_message, + self.tr("Syncing with cloud failed: \n {}").format(error_message) ) self.sync_finished.emit(app_name) diff --git a/rare/components/tabs/games/game_info/game_settings.py b/rare/components/tabs/games/game_info/game_settings.py index 05831e2e..be898770 100644 --- a/rare/components/tabs/games/game_info/game_settings.py +++ b/rare/components/tabs/games/game_info/game_settings.py @@ -41,7 +41,7 @@ def find_proton_wrappers(): if os.path.exists(proton) and ( os.path.exists(compatibilitytool) or os.path.exists(toolmanifest) ): - wrapper = '"' + proton + '" run' + wrapper = f'"{proton}" run' possible_proton_wrappers.append(wrapper) if not possible_proton_wrappers: logger.warning("Unable to find any Proton version") @@ -260,8 +260,8 @@ class GameSettings(QWidget, Ui_GameSettings): self.core.lgd.config.remove_option( f"{self.game.app_name}.env", "STEAM_COMPAT_DATA_PATH" ) - if not self.core.lgd.config[self.game.app_name + ".env"]: - self.core.lgd.config.remove_section(self.game.app_name + ".env") + if not self.core.lgd.config[f"{self.game.app_name}.env"]: + self.core.lgd.config.remove_section(f"{self.game.app_name}.env") self.proton_prefix.setEnabled(False) # lk: TODO: This has to be fixed properly. # lk: It happens because of the widget update. Mask it for now behind disabling the save button @@ -279,12 +279,12 @@ class GameSettings(QWidget, Ui_GameSettings): wrapper = self.possible_proton_wrappers[i - 1] if self.game.app_name not in self.core.lgd.config.sections(): self.core.lgd.config[self.game.app_name] = {} - if self.game.app_name + ".env" not in self.core.lgd.config.sections(): - self.core.lgd.config[self.game.app_name + ".env"] = {} + if f"{self.game.app_name}.env" not in self.core.lgd.config.sections(): + self.core.lgd.config[f"{self.game.app_name}.env"] = {} self.core.lgd.config.set(self.game.app_name, "wrapper", wrapper) self.core.lgd.config.set(self.game.app_name, "no_wine", "true") self.core.lgd.config.set( - self.game.app_name + ".env", + f"{self.game.app_name}.env", "STEAM_COMPAT_DATA_PATH", os.path.expanduser("~/.proton"), ) @@ -305,7 +305,7 @@ class GameSettings(QWidget, Ui_GameSettings): def proton_prefix_save(self, text: str): self.core.lgd.config.set( - self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH", text + + f"{self.game.app_name}.env", "STEAM_COMPAT_DATA_PATH", text ) self.core.lgd.save_config() diff --git a/rare/components/tabs/games/game_utils.py b/rare/components/tabs/games/game_utils.py index d4cf8f0c..aa6ea7d1 100644 --- a/rare/components/tabs/games/game_utils.py +++ b/rare/components/tabs/games/game_utils.py @@ -143,7 +143,7 @@ class GameUtils(QObject): logger.info("Cancel Startup") self.finished.emit(app_name, "") return - logger.info("Launching " + game.app_title) + logger.info(f"Launching {game.app_title}") if game.third_party_store == "Origin": offline = False @@ -309,7 +309,7 @@ class GameUtils(QObject): ) def game_finished(self, exit_code, app_name): - logger.info("Game exited with exit code: " + str(exit_code)) + logger.info(f"Game exited with exit code: {exit_code}") is_origin = self.core.get_game(app_name).third_party_store == "Origin" if exit_code == 53 and is_origin: msg_box = QMessageBox() diff --git a/rare/components/tabs/games/game_widgets/base_installed_widget.py b/rare/components/tabs/games/game_widgets/base_installed_widget.py index b23a9f83..aa10e929 100644 --- a/rare/components/tabs/games/game_widgets/base_installed_widget.py +++ b/rare/components/tabs/games/game_widgets/base_installed_widget.py @@ -61,7 +61,7 @@ class BaseInstalledWidget(QGroupBox): self.game.app_name, platform=self.igame.platform, update=False ).build_version except ValueError: - logger.error("Asset error for " + self.game.app_title) + logger.error(f"Asset error for {self.game.app_title}") self.update_available = False else: if remote_version != self.igame.version: diff --git a/rare/components/tabs/games/game_widgets/installed_icon_widget.py b/rare/components/tabs/games/game_widgets/installed_icon_widget.py index 9f958911..7f7b1120 100644 --- a/rare/components/tabs/games/game_widgets/installed_icon_widget.py +++ b/rare/components/tabs/games/game_widgets/installed_icon_widget.py @@ -25,7 +25,7 @@ class InstalledIconWidget(BaseInstalledWidget): self.core = shared.core if self.update_available: - logger.info("Update available for game: " + self.game.app_name) + logger.info(f"Update available for game: {self.game.app_name}") self.layout.addWidget(self.image) diff --git a/rare/components/tabs/games/game_widgets/installed_list_widget.py b/rare/components/tabs/games/game_widgets/installed_list_widget.py index 008316a1..fca1c886 100644 --- a/rare/components/tabs/games/game_widgets/installed_list_widget.py +++ b/rare/components/tabs/games/game_widgets/installed_list_widget.py @@ -57,10 +57,10 @@ class InstalledListWidget(BaseInstalledWidget): self.childLayout.addWidget(self.launch_button) self.childLayout.addWidget(self.info) self.childLayout.addWidget(self.app_name_label) - self.developer_label = QLabel(self.tr("Developer: ") + self.dev) + self.developer_label = QLabel(self.tr("Developer: {}").format(self.dev)) self.childLayout.addWidget(self.developer_label) if self.igame: - self.version_label = QLabel("Version: " + str(self.igame.version)) + self.version_label = QLabel(f"Version: {self.igame.version}") self.size_label = QLabel( f"{self.tr('Installed size')}: {get_size(self.size)}" ) diff --git a/rare/components/tabs/games/game_widgets/installing_game_widget.py b/rare/components/tabs/games/game_widgets/installing_game_widget.py index 61a3e56b..d8b637a1 100644 --- a/rare/components/tabs/games/game_widgets/installing_game_widget.py +++ b/rare/components/tabs/games/game_widgets/installing_game_widget.py @@ -111,5 +111,5 @@ class PaintWidget(QWidget): # draw text painter.setPen(QColor(*text_color_for_background(self.rgb_tuple))) painter.setFont(QFont(None, 16)) - painter.drawText(a0.rect(), Qt.AlignCenter, str(self.progress) + "%") + painter.drawText(a0.rect(), Qt.AlignCenter, f"{self.progress}%") painter.end() diff --git a/rare/components/tabs/games/import_sync/egl_sync_group.py b/rare/components/tabs/games/import_sync/egl_sync_group.py index b190045c..9d316a53 100644 --- a/rare/components/tabs/games/import_sync/egl_sync_group.py +++ b/rare/components/tabs/games/import_sync/egl_sync_group.py @@ -247,7 +247,7 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup): try: i = EGLSyncListItem(item, self.export, self.list) except AttributeError: - logger.error(item.app_name + " does not work. Ignoring") + logger.error(f"{item.app_name} does not work. Ignoring") else: self.list.addItem(i) self.label.setVisible(not enabled or not bool(self.list.count())) diff --git a/rare/components/tabs/games/import_sync/import_group.py b/rare/components/tabs/games/import_sync/import_group.py index 522238a2..7dc4becc 100644 --- a/rare/components/tabs/games/import_sync/import_group.py +++ b/rare/components/tabs/games/import_sync/import_group.py @@ -175,6 +175,6 @@ class ImportGroup(QGroupBox, Ui_ImportGroup): else: logger.warning(f'Failed to import "{app_name}"') self.info_label.setText( - self.tr("Could not import {}: ").format(app_name) + err + self.tr("Could not import {}: {}").format(app_name, err) ) return diff --git a/rare/components/tabs/settings/about.py b/rare/components/tabs/settings/about.py index f6678f16..a8ff138c 100644 --- a/rare/components/tabs/settings/about.py +++ b/rare/components/tabs/settings/about.py @@ -51,7 +51,7 @@ class About(QWidget, Ui_About): if self.update_available: logger.info(f"Update available: {__version__} -> {latest_tag}") self.update_lbl.setText( - self.tr("Update available: ") + f"{__version__} -> {latest_tag}" + self.tr("Update available: {} -> {}").format(__version__, latest_tag) ) self.update_label.setVisible(True) self.update_lbl.setVisible(True) diff --git a/rare/components/tabs/settings/dxvk.py b/rare/components/tabs/settings/dxvk.py index 13cb3007..6a1af32a 100644 --- a/rare/components/tabs/settings/dxvk.py +++ b/rare/components/tabs/settings/dxvk.py @@ -54,7 +54,7 @@ class DxvkSettings(QGroupBox, Ui_DxvkSettings): try: self.dxvk_options_map[opt].setChecked(True) except KeyError: - print("Malformed DXVK Option: " + opt) + print(f"Malformed DXVK Option: {opt}") continue else: self.show_dxvk.setCurrentIndex(0) diff --git a/rare/components/tabs/settings/legendary.py b/rare/components/tabs/settings/legendary.py index aded8da8..18027203 100644 --- a/rare/components/tabs/settings/legendary.py +++ b/rare/components/tabs/settings/legendary.py @@ -127,7 +127,7 @@ class LegendarySettings(QWidget, Ui_LegendarySettings): if not text and "install_dir" in self.core.lgd.config["Legendary"].keys(): self.core.lgd.config["Legendary"].pop("install_dir") else: - logger.debug("Set config install_dir to " + text) + logger.debug(f"Set config install_dir to {text}") self.core.lgd.save_config() def max_worker_save(self, workers: str): diff --git a/rare/components/tabs/settings/rare.py b/rare/components/tabs/settings/rare.py index e6870021..01e153d8 100644 --- a/rare/components/tabs/settings/rare.py +++ b/rare/components/tabs/settings/rare.py @@ -152,7 +152,7 @@ class RareSettings(QWidget, Ui_RareSettings): def clean_logdir(self): for i in os.listdir(os.path.join(cache_dir, "logs")): - os.remove(os.path.join(cache_dir, "logs/") + i) + os.remove(os.path.join(cache_dir, f"logs/{i}")) self.log_dir_size_label.setText("0KB") def create_start_menu_link(self): @@ -168,7 +168,7 @@ class RareSettings(QWidget, Ui_RareSettings): QMessageBox.warning( self, "Error", - "Permission error, cannot remove " + str(self.start_menu_link), + f"Permission error, cannot remove {self.start_menu_link}", ) def create_desktop_link(self): @@ -183,7 +183,7 @@ class RareSettings(QWidget, Ui_RareSettings): logger.warning( self, "Error", - "Permission error, cannot remove " + str(self.desktop_file), + f"Permission error, cannot remove {self.desktop_file}", ) def on_color_select_changed(self, color): diff --git a/rare/components/tabs/shop/game_info.py b/rare/components/tabs/shop/game_info.py index 36657376..51d777de 100644 --- a/rare/components/tabs/shop/game_info.py +++ b/rare/components/tabs/shop/game_info.py @@ -236,7 +236,7 @@ class ShopGameInfo(QWidget, Ui_shop_info): icn = icon("mdi.web", "fa.search", scale_factor=1.5) else: try: - icn = icon("mdi." + name.lower(), "fa." + name.lower(), scale_factor=1.5) + icn = icon(f"mdi.{name.lower()}", f"fa.{name.lower()}", scale_factor=1.5) except Exception as e: logger.error(str(e)) continue diff --git a/rare/components/tabs/shop/shop_api_core.py b/rare/components/tabs/shop/shop_api_core.py index ade65f3d..06889628 100644 --- a/rare/components/tabs/shop/shop_api_core.py +++ b/rare/components/tabs/shop/shop_api_core.py @@ -24,7 +24,7 @@ class ShopApiCore(QObject): self.token = auth_token self.language_code: str = lc self.country_code: str = cc - self.locale = self.language_code + "-" + self.country_code + self.locale = f"{self.language_code}-{self.country_code}" self.manager = QtRequestManager() self.auth_manager = QtRequestManager(authorization_token=auth_token) @@ -44,7 +44,7 @@ class ShopApiCore(QObject): handle_func(["error", "Key error"]) return except Exception as e: - logger.error("Free games Api request failed: " + str(e)) + logger.error(f"Free games Api request failed: {e}") handle_func(["error", e]) return handle_func(results) @@ -56,7 +56,7 @@ class ShopApiCore(QObject): "query": wishlist_query, "variables": { "country": self.country_code, - "locale": self.language_code + "-" + self.country_code, + "locale": f"{self.language_code}-{self.country_code}", }, }, lambda data: self._handle_wishlist(data, handle_func), @@ -70,7 +70,7 @@ class ShopApiCore(QObject): handle_func(["error", "Key error"]) return except Exception as e: - logger.error("Free games Api request failed: " + str(e)) + logger.error(f"Free games Api request failed: {e}") handle_func(["error", e]) return @@ -105,7 +105,7 @@ class ShopApiCore(QObject): logger.error(str(e)) handle_func([]) except Exception as e: - logger.error("Search Api request failed: " + str(e)) + logger.error(f"Search Api request failed: {e}") handle_func([]) return @@ -158,7 +158,7 @@ class ShopApiCore(QObject): logger.error(str(e)) handle_func([]) except Exception as e: - logger.error("Browse games Api request failed: " + str(e)) + logger.error(f"Browse games Api request failed: {e}") handle_func([]) return else: diff --git a/rare/components/tabs/shop/shop_widget.py b/rare/components/tabs/shop/shop_widget.py index dc0db836..98fd4d74 100644 --- a/rare/components/tabs/shop/shop_widget.py +++ b/rare/components/tabs/shop/shop_widget.py @@ -88,7 +88,7 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): if wishlist and wishlist[0] == "error": self.discount_widget.layout().addWidget( - QLabel(self.tr("Failed to get wishlist: ") + wishlist[1]) + QLabel(self.tr("Failed to get wishlist: {}").format(wishlist[1])) ) btn = QPushButton(self.tr("Reload")) self.discount_widget.layout().addWidget(btn) @@ -109,7 +109,7 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): self.discount_widget.layout().addWidget(w) discounts += 1 except Exception as e: - logger.warning(str(game) + str(e)) + logger.warning(f"{game} {e}") continue self.discounts_gb.setVisible(discounts > 0) self.discount_stack.setCurrentIndex(0) @@ -124,7 +124,7 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): if free_games and free_games[0] == "error": self.free_widget.layout().addWidget( - QLabel(self.tr("Failed to fetch free games: ") + free_games[1]) + QLabel(self.tr("Failed to fetch free games: {}").format(free_games[1])) ) btn = QPushButton(self.tr("Reload")) self.free_widget.layout().addWidget(btn) diff --git a/rare/utils/legendary_utils.py b/rare/utils/legendary_utils.py index 484d0df5..f3aa1be5 100644 --- a/rare/utils/legendary_utils.py +++ b/rare/utils/legendary_utils.py @@ -69,14 +69,14 @@ def uninstall(app_name: str, core: LegendaryCore, options=None): logger.info("Removing sections in config file") if core.lgd.config.has_section(app_name): core.lgd.config.remove_section(app_name) - if core.lgd.config.has_section(app_name + ".env"): - core.lgd.config.remove_section(app_name + ".env") + if core.lgd.config.has_section(f"{app_name}.env"): + core.lgd.config.remove_section(f"{app_name}.env") core.lgd.save_config() def update_manifest(app_name: str, core: LegendaryCore): game = core.get_game(app_name) - logger.info("Reloading game manifest of " + game.app_title) + logger.info(f"Reloading game manifest of {game.app_title}") new_manifest_data, base_urls = core.get_cdn_manifest(game) # overwrite base urls in metadata with current ones to avoid using old/dead CDNs game.base_urls = base_urls @@ -163,7 +163,7 @@ class VerifyWorker(QRunnable): def import_game(core: LegendaryCore, app_name: str, path: str) -> str: _tr = QCoreApplication.translate - logger.info("Import " + app_name) + logger.info(f"Import {app_name}") game = core.get_game(app_name, update_meta=False) if not game: return _tr("LgdUtils", "Could not get game for {}").format(app_name) @@ -213,5 +213,5 @@ def import_game(core: LegendaryCore, app_name: str, path: str) -> str: if igame.needs_verification: logger.info(f"{igame.title} needs verification") - logger.info("Successfully imported Game: " + game.app_title) + logger.info(f"Successfully imported Game: {game.app_title}") return "" diff --git a/rare/utils/rpc.py b/rare/utils/rpc.py index a1d80578..d17014ef 100644 --- a/rare/utils/rpc.py +++ b/rare/utils/rpc.py @@ -66,15 +66,15 @@ class DiscordRPC(QObject): ) # Rare app: https://discord.com/developers/applications self.RPC.connect() except ConnectionRefusedError as e: - logger.warning("Discord is not active\n" + str(e)) + logger.warning(f"Discord is not active\n{e}") self.RPC = None return except FileNotFoundError as e: - logger.warning("File not found error\n" + str(e)) + logger.warning(f"File not found error\n{e}") self.RPC = None return except pypresence.exceptions.InvalidPipe as e: - logger.error("Is Discord running? \n" + str(e)) + logger.error(f"Is Discord running? \n{e}") self.RPC = None return except Exception as e: @@ -99,14 +99,14 @@ class DiscordRPC(QObject): try: title = self.core.get_installed_game(app_name).title except AttributeError: - logger.error("Could not get title of game: " + app_name) + logger.error(f"Could not get title of game: {app_name}") title = app_name start = None if self.settings.value("rpc_time", True, bool): start = str(time.time()).split(".")[0] os = None if self.settings.value("rpc_os", True, bool): - os = "via Rare on " + platform.system() + os = f"via Rare on {platform.system()}" self.RPC.update( large_image="logo", details=title, large_text=title, state=os, start=start diff --git a/rare/utils/singleton.py b/rare/utils/singleton.py index a9be16ab..6fc457ca 100644 --- a/rare/utils/singleton.py +++ b/rare/utils/singleton.py @@ -42,9 +42,9 @@ class SingleInstance(object): + "-%s" % flavor_id + ".lock" ) - self.lockfile = os.path.normpath(tempfile.gettempdir() + "/" + basename) + self.lockfile = os.path.normpath(f"{tempfile.gettempdir()}/{basename}") - logger.debug("SingleInstance lockfile: " + self.lockfile) + logger.debug(f"SingleInstance lockfile: {self.lockfile}") if sys.platform == "win32": try: # file already exists, we try to remove (in case previous diff --git a/rare/utils/steam_grades.py b/rare/utils/steam_grades.py index 1d998602..9c826742 100644 --- a/rare/utils/steam_grades.py +++ b/rare/utils/steam_grades.py @@ -74,7 +74,7 @@ def get_grade(steam_code): return "fail" steam_code = str(steam_code) url = "https://www.protondb.com/api/v1/reports/summaries/" - res = requests.get(url + steam_code + ".json") + res = requests.get(f"{url}{steam_code}.json") try: lista = json.loads(res.text) except json.decoder.JSONDecodeError: diff --git a/rare/utils/utils.py b/rare/utils/utils.py index 7138ead0..a887f541 100644 --- a/rare/utils/utils.py +++ b/rare/utils/utils.py @@ -74,8 +74,8 @@ def download_images(progress: pyqtSignal, results: pyqtSignal, core: LegendaryCo def download_image(game, force=False): if force and os.path.exists(f"{image_dir}/{game.app_name}"): shutil.rmtree(f"{image_dir}/{game.app_name}") - if not os.path.isdir(f"{image_dir}/" + game.app_name): - os.mkdir(f"{image_dir}/" + game.app_name) + if not os.path.isdir(f"{image_dir}/{game.app_name}"): + os.mkdir(f"{image_dir}/{game.app_name}") # to get picture updates if not os.path.isfile(f"{image_dir}/{game.app_name}/image.json"): @@ -367,7 +367,7 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop") - for c in r'<>?":|\/*': linkName.replace(c, "") - linkName = linkName.strip() + ".lnk" + linkName = f"{linkName.strip()}.lnk" # Path to location of link file pathLink = os.path.join(target_folder, linkName) @@ -384,12 +384,12 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop") - shortcut.WorkingDirectory = os.getcwd() # Icon - if not os.path.exists(icon + ".ico"): + if not os.path.exists(f"{icon}.ico"): img = QImage() - img.load(icon + ".png") - img.save(icon + ".ico") + img.load(f"{icon}.png") + img.save(f"{icon}.ico") logger.info("Create Icon") - shortcut.IconLocation = os.path.join(icon + ".ico") + shortcut.IconLocation = os.path.join(f"{icon}.ico") shortcut.save() return True @@ -550,7 +550,7 @@ def icon(icn_str: str, fallback: str = None, **kwargs): return qtawesome.icon(icn_str, **kwargs) except Exception as e: if not fallback: - logger.warning(str(e) + " " + icn_str) + logger.warning(f"{e} {icn_str}") if fallback: try: return qtawesome.icon(fallback, **kwargs)