1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00

Rare: cherry-pick some sourcery suggestions

This commit is contained in:
loathingKernel 2024-01-02 17:57:02 +02:00
parent 89c1a4eaf4
commit 80ac9296fc
10 changed files with 18 additions and 26 deletions

View file

@ -49,17 +49,14 @@ class LaunchDialog(BaseDialog):
def login(self): def login(self):
can_launch = True can_launch = True
try: try:
if self.args.offline: if not self.args.offline:
pass
else:
# Force an update check and notice in case there are API changes # Force an update check and notice in case there are API changes
# self.core.check_for_updates(force=True) # self.core.check_for_updates(force=True)
# self.core.force_show_update = True # self.core.force_show_update = True
if self.core.login(force_refresh=True): if not self.core.login(force_refresh=True):
logger.info("You are logged in")
self.login_dialog.close()
else:
raise ValueError("You are not logged in. Opening login window.") raise ValueError("You are not logged in. Opening login window.")
logger.info("You are logged in")
self.login_dialog.close()
except ValueError as e: except ValueError as e:
logger.info(str(e)) logger.info(str(e))
# Do not set parent, because it won't show a task bar icon # Do not set parent, because it won't show a task bar icon

View file

@ -143,11 +143,10 @@ class LoginDialog(BaseDialog):
def login_successful(self): def login_successful(self):
try: try:
if self.core.login(): if not self.core.login():
self.logged_in = True
self.accept()
else:
raise ValueError("Login failed.") raise ValueError("Login failed.")
self.logged_in = True
self.accept()
except Exception as e: except Exception as e:
logger.error(str(e)) logger.error(str(e))
self.core.lgd.invalidate_userdata() self.core.lgd.invalidate_userdata()

View file

@ -92,9 +92,7 @@ class ImportLogin(QFrame):
def do_login(self): def do_login(self):
self.ui.status_label.setText(self.tr("Loading...")) self.ui.status_label.setText(self.tr("Loading..."))
if os.name == "nt": if os.name != "nt":
pass
else:
logger.info("Using EGL appdata path at %s", {self.egl_appdata}) logger.info("Using EGL appdata path at %s", {self.egl_appdata})
self.core.egl.appdata_path = self.egl_appdata self.core.egl.appdata_path = self.egl_appdata
try: try:

View file

@ -193,9 +193,8 @@ class MainWindow(QMainWindow):
def timer_finished(self): def timer_finished(self):
file_path = lock_file() file_path = lock_file()
if os.path.exists(file_path): if os.path.exists(file_path):
file = open(file_path, "r") with open(file_path, "r") as file:
action = file.read() action = file.read()
file.close()
if action.startswith("show"): if action.startswith("show"):
self.show() self.show()
os.remove(file_path) os.remove(file_path)

View file

@ -146,7 +146,7 @@ class GamesTab(QStackedWidget):
def update_count_games_label(self): def update_count_games_label(self):
self.head_bar.set_games_count( self.head_bar.set_games_count(
len([game for game in self.rcore.games if game.is_installed]), len([game for game in self.rcore.games if game.is_installed]),
len([game for game in self.rcore.games]) len(list(self.rcore.games)),
) )
def setup_game_list(self): def setup_game_list(self):

View file

@ -45,7 +45,7 @@ class EnvVars(QGroupBox):
layout.addWidget(self.table_view) layout.addWidget(self.table_view)
def keyPressEvent(self, e): def keyPressEvent(self, e):
if e.key() == Qt.Key_Delete or e.key() == Qt.Key_Backspace: if e.key() in {Qt.Key_Delete, Qt.Key_Backspace}:
indexes = self.table_view.selectedIndexes() indexes = self.table_view.selectedIndexes()
if not len(indexes): if not len(indexes):
return return

View file

@ -97,7 +97,7 @@ class EnvVarsTableModel(QAbstractTableModel):
return value == match.group(0) return value == match.group(0)
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any: def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any:
if role == Qt.DisplayRole or role == Qt.EditRole: if role in {Qt.DisplayRole, Qt.EditRole}:
if index.row() == self.__data_length(): if index.row() == self.__data_length():
return "" return ""
if index.column() == 0: if index.column() == 0:

View file

@ -52,10 +52,10 @@ class PreLaunchThread(QRunnable):
else: else:
self.logger.info("No sync action") self.logger.info("No sync action")
args = self.prepare_launch(self.args) if args := self.prepare_launch(self.args):
if not args: self.signals.ready_to_launch.emit(args)
else:
return return
self.signals.ready_to_launch.emit(args)
def prepare_launch(self, args: InitArgs) -> Optional[LaunchArgs]: def prepare_launch(self, args: InitArgs) -> Optional[LaunchArgs]:
try: try:

View file

@ -97,7 +97,7 @@ def main() -> int:
print(f"Rare {__version__} Codename: {__codename__}") print(f"Rare {__version__} Codename: {__codename__}")
return 0 return 0
if args.subparser == "start" or args.subparser == "launch": if args.subparser in {"start", "launch"}:
from rare.launcher import launch from rare.launcher import launch
return launch(args) return launch(args)

View file

@ -318,8 +318,7 @@ class RareGameSlim(RareGameBase):
@property @property
def is_save_up_to_date(self): def is_save_up_to_date(self):
status, (_, _) = self.save_game_state status, (_, _) = self.save_game_state
return (status == SaveGameStatus.SAME_AGE) \ return status in {SaveGameStatus.SAME_AGE, SaveGameStatus.NO_SAVE}
or (status == SaveGameStatus.NO_SAVE)
@property @property
def raw_save_path(self) -> str: def raw_save_path(self) -> str: