1
0
Fork 0
mirror of synced 2024-05-18 19:42:54 +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):
can_launch = True
try:
if self.args.offline:
pass
else:
if not self.args.offline:
# Force an update check and notice in case there are API changes
# self.core.check_for_updates(force=True)
# self.core.force_show_update = True
if self.core.login(force_refresh=True):
logger.info("You are logged in")
self.login_dialog.close()
else:
if not self.core.login(force_refresh=True):
raise ValueError("You are not logged in. Opening login window.")
logger.info("You are logged in")
self.login_dialog.close()
except ValueError as e:
logger.info(str(e))
# 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):
try:
if self.core.login():
self.logged_in = True
self.accept()
else:
if not self.core.login():
raise ValueError("Login failed.")
self.logged_in = True
self.accept()
except Exception as e:
logger.error(str(e))
self.core.lgd.invalidate_userdata()

View file

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

View file

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

View file

@ -146,7 +146,7 @@ class GamesTab(QStackedWidget):
def update_count_games_label(self):
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])
len(list(self.rcore.games)),
)
def setup_game_list(self):

View file

@ -45,7 +45,7 @@ class EnvVars(QGroupBox):
layout.addWidget(self.table_view)
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()
if not len(indexes):
return

View file

@ -97,7 +97,7 @@ class EnvVarsTableModel(QAbstractTableModel):
return value == match.group(0)
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():
return ""
if index.column() == 0:

View file

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

View file

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

View file

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