From bc01ab03476e8f30508774174cda880b7c0b334e Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Thu, 2 Mar 2017 19:28:05 -0800 Subject: [PATCH] Make codebase pass flake8 --- lutris/game.py | 4 ++-- lutris/gui/cellrenderers.py | 2 +- lutris/gui/config_boxes.py | 8 ++++---- lutris/gui/config_dialogs.py | 3 ++- lutris/gui/flowbox.py | 3 ++- lutris/gui/gameviews.py | 19 ++++++++++--------- lutris/gui/lutriswindow.py | 4 ++-- lutris/installer/errors.py | 3 +++ lutris/installer/interpreter.py | 6 +++--- lutris/pga.py | 2 ++ lutris/runners/ags.py | 2 +- lutris/runners/citra.py | 2 +- lutris/runners/desmume.py | 2 +- lutris/runners/dgen.py | 2 +- lutris/runners/winesteam.py | 2 +- lutris/runtime.py | 10 +++++----- lutris/shortcuts.py | 4 +--- lutris/tosec.py | 18 +++++++++--------- lutris/util/desktopapps.py | 10 ++++++---- lutris/util/extract.py | 5 +++-- tests/benchmark_download.py | 1 - tests/check_prefixes.py | 1 + 22 files changed, 61 insertions(+), 52 deletions(-) diff --git a/lutris/game.py b/lutris/game.py index b453a5b30..bfdf20177 100644 --- a/lutris/game.py +++ b/lutris/game.py @@ -347,8 +347,8 @@ class Game(object): def beat(self): """Watch the game's process(es).""" if self.game_thread.error: - dialogs.ErrorDialog("Error lauching the game:\n" - + self.game_thread.error) + dialogs.ErrorDialog("Error lauching the game:\n" + + self.game_thread.error) self.on_game_quit() return False self.game_log = self.game_thread.stdout diff --git a/lutris/gui/cellrenderers.py b/lutris/gui/cellrenderers.py index 2b0690a49..5d6e2e1ce 100644 --- a/lutris/gui/cellrenderers.py +++ b/lutris/gui/cellrenderers.py @@ -40,6 +40,6 @@ class CellRendererButton(Gtk.CellRenderer): (x, y, w, h) = self.do_get_size(widget, cell_area) h -= 4 # Gtk.render_background(context, cr, x, y, w, h) - Gtk.render_frame(context, cr, x, y, w-2, h+4) + Gtk.render_frame(context, cr, x, y, w - 2, h + 4) Gtk.render_layout(context, cr, x + 10, y, self.layout) context.restore() diff --git a/lutris/gui/config_boxes.py b/lutris/gui/config_boxes.py index 0b536cec9..04a5c5232 100644 --- a/lutris/gui/config_boxes.py +++ b/lutris/gui/config_boxes.py @@ -414,10 +414,10 @@ class ConfigBox(VBox): dialog.set_select_multiple(True) first_file_dir = os.path.dirname(value[0]) if value else None - dialog.set_current_folder(first_file_dir - or self.game.directory - or self.config.get('game_path') - or os.path.expanduser('~')) + dialog.set_current_folder(first_file_dir or + self.game.directory or + self.config.get('game_path') or + os.path.expanduser('~')) response = dialog.run() if response == Gtk.ResponseType.ACCEPT: self.add_files_to_treeview(dialog, option_name, self.wrapper) diff --git a/lutris/gui/config_dialogs.py b/lutris/gui/config_dialogs.py index 6f51f0bec..5b350ec17 100644 --- a/lutris/gui/config_dialogs.py +++ b/lutris/gui/config_dialogs.py @@ -5,7 +5,7 @@ from lutris import runners, settings from lutris.config import LutrisConfig, TEMP_CONFIG, make_game_config_id from lutris.game import Game from lutris import gui -from lutris.gui.config_boxes import GameBox, RunnerBox, SystemBox +from lutris.gui.config_boxes import GameBox, RunnerBox, SystemBox from lutris.gui.dialogs import ErrorDialog from lutris.gui.widgets import VBox, Dialog from lutris.util.log import logger @@ -29,6 +29,7 @@ class SlugEntry(Gtk.Entry, Gtk.Editable): return position + length return position + class NumberEntry(Gtk.Entry, Gtk.Editable): def __init__(self): super(NumberEntry, self).__init__() diff --git a/lutris/gui/flowbox.py b/lutris/gui/flowbox.py index 1a8287ea3..eab94a20d 100644 --- a/lutris/gui/flowbox.py +++ b/lutris/gui/flowbox.py @@ -235,7 +235,8 @@ class GameFlowBox(FlowBox): self.contextual_menu.popup(event, game=widget.game) def handle_key_press(self, widget, event): - if not self.selected_game: return + if not self.selected_game: + return key = event.keyval if key == Gdk.KEY_Delete: self.emit("remove-game") diff --git a/lutris/gui/gameviews.py b/lutris/gui/gameviews.py index d22ecb2c7..c4c5cf4b5 100644 --- a/lutris/gui/gameviews.py +++ b/lutris/gui/gameviews.py @@ -267,7 +267,8 @@ class GameView(object): self.contextual_menu.popup(event, game_row) def handle_key_press(self, widget, event): - if not self.selected_game: return + if not self.selected_game: + return key = event.keyval if key == Gdk.KEY_Delete: self.emit("remove-game") @@ -474,20 +475,20 @@ class ContextualMenu(Gtk.Menu): 'play': not is_installed, 'configure': not is_installed, 'desktop-shortcut': ( - not is_installed - or desktop_launcher_exists(game_slug, game_id) + not is_installed or + desktop_launcher_exists(game_slug, game_id) ), 'menu-shortcut': ( - not is_installed - or menu_launcher_exists(game_slug, game_id) + not is_installed or + menu_launcher_exists(game_slug, game_id) ), 'rm-desktop-shortcut': ( - not is_installed - or not desktop_launcher_exists(game_slug, game_id) + not is_installed or + not desktop_launcher_exists(game_slug, game_id) ), 'rm-menu-shortcut': ( - not is_installed - or not menu_launcher_exists(game_slug, game_id) + not is_installed or + not menu_launcher_exists(game_slug, game_id) ), 'browse': not is_installed or runner_slug == 'browser', } diff --git a/lutris/gui/lutriswindow.py b/lutris/gui/lutriswindow.py index f8458642e..a9fa1a20b 100644 --- a/lutris/gui/lutriswindow.py +++ b/lutris/gui/lutriswindow.py @@ -67,7 +67,7 @@ class LutrisWindow(Gtk.ApplicationWindow): width = int(settings.read_setting('width') or 800) height = int(settings.read_setting('height') or 600) self.window_size = (width, height) - self.maximized = settings.read_setting('maximized') == 'True' + self.maximized = settings.read_setting('maximized') == 'True' view_type = self.get_view_type() self.load_icon_type_from_settings(view_type) @@ -435,7 +435,7 @@ class LutrisWindow(Gtk.ApplicationWindow): self.actions['synchronize'].props.enabled = False def toggle_connection(self, is_connected, username=None): - connect_item = self.props.application.set_connect_state(is_connected) + self.props.application.set_connect_state(is_connected) if is_connected: connection_status = username logger.info('Connected to lutris.net as %s', connection_status) diff --git a/lutris/installer/errors.py b/lutris/installer/errors.py index 08771f1c0..8cb4d568b 100644 --- a/lutris/installer/errors.py +++ b/lutris/installer/errors.py @@ -19,6 +19,7 @@ class ScriptingError(Exception): def __repr__(self): return self.message + _excepthook = sys.excepthook @@ -30,4 +31,6 @@ def error_handler(error_type, value, traceback): ErrorDialog(message) else: _excepthook(error_type, value, traceback) + + sys.excepthook = error_handler diff --git a/lutris/installer/interpreter.py b/lutris/installer/interpreter.py index 74d53c17f..43c5ef2f7 100644 --- a/lutris/installer/interpreter.py +++ b/lutris/installer/interpreter.py @@ -91,9 +91,9 @@ class ScriptInterpreter(CommandsMixin): @property def should_create_target(self): return ( - not os.path.exists(self.target_path) - and 'nocreatedir' not in self.script - and self.creates_game_folder + not os.path.exists(self.target_path) and + 'nocreatedir' not in self.script and + self.creates_game_folder ) @property diff --git a/lutris/pga.py b/lutris/pga.py index 20bc0f475..669049894 100644 --- a/lutris/pga.py +++ b/lutris/pga.py @@ -155,10 +155,12 @@ def get_steam_games(): query = "select * from games where steamid is not null and steamid != ''" return sql.db_query(PGA_DB, query) + def get_desktop_games(): query = "select * from games where runner = 'linux' and installer_slug = 'desktopapp'" return sql.db_query(PGA_DB, query) + def get_game_by_field(value, field='slug', all=False): """Query a game based on a database field""" if field not in ('slug', 'installer_slug', 'id', 'configpath', 'steamid'): diff --git a/lutris/runners/ags.py b/lutris/runners/ags.py index 486be3ab9..06a0515b9 100644 --- a/lutris/runners/ags.py +++ b/lutris/runners/ags.py @@ -11,7 +11,7 @@ class ags(Runner): game_options = [{ 'option': 'main_file', 'type': 'file', - 'label': 'Game executable or directory' + 'label': 'Game executable or directory' }] runner_options = [ { diff --git a/lutris/runners/citra.py b/lutris/runners/citra.py index 2d0c88812..3855a4d09 100644 --- a/lutris/runners/citra.py +++ b/lutris/runners/citra.py @@ -11,7 +11,7 @@ class citra(Runner): game_options = [{ 'option': 'main_file', 'type': 'file', - 'label': 'ROM file', + 'label': 'ROM file', 'help': ("The game data, commonly called a ROM image.") }] diff --git a/lutris/runners/desmume.py b/lutris/runners/desmume.py index 1253d7948..9d2adb6b7 100644 --- a/lutris/runners/desmume.py +++ b/lutris/runners/desmume.py @@ -11,7 +11,7 @@ class desmume(Runner): game_options = [{ 'option': 'main_file', 'type': 'file', - 'label': 'ROM file', + 'label': 'ROM file', 'help': ("The game data, commonly called a ROM image.") }] diff --git a/lutris/runners/dgen.py b/lutris/runners/dgen.py index a4e142de2..a555340c8 100644 --- a/lutris/runners/dgen.py +++ b/lutris/runners/dgen.py @@ -11,7 +11,7 @@ class dgen(Runner): game_options = [{ 'option': 'main_file', 'type': 'file', - 'label': 'ROM file', + 'label': 'ROM file', 'help': ("The game data, commonly called a ROM image.") }] runner_options = [ diff --git a/lutris/runners/winesteam.py b/lutris/runners/winesteam.py index 45e096a57..46db66a2b 100644 --- a/lutris/runners/winesteam.py +++ b/lutris/runners/winesteam.py @@ -348,7 +348,7 @@ class winesteam(wine.wine): super(winesteam, self).prelaunch() def check_shutdown(is_running, times=10): - for x in range(1, times+1): + for x in range(1, times + 1): time.sleep(1) if not is_running(): return True diff --git a/lutris/runtime.py b/lutris/runtime.py index 466c5d02c..897242656 100644 --- a/lutris/runtime.py +++ b/lutris/runtime.py @@ -58,16 +58,16 @@ class RuntimeUpdater: for runtime in runtimes: # Skip 32bit runtimes on 64 bit systems except the lib32 one - if(runtime['architecture'] == 'i386' - and system.is_64bit - and runtime['name'] != 'lib32'): + if(runtime['architecture'] == 'i386' and + system.is_64bit and + runtime['name'] != 'lib32'): logger.debug('Skipping runtime %s for %s', runtime['name'], runtime['architecture']) continue # Skip 64bit runtimes on 32 bit systems - if(runtime['architecture'] == 'x86_64' - and not system.is_64bit): + if(runtime['architecture'] == 'x86_64' and + not system.is_64bit): logger.debug('Skipping runtime %s for %s', runtime['name'], runtime['architecture']) continue diff --git a/lutris/shortcuts.py b/lutris/shortcuts.py index 8041e6f46..c23a1df87 100644 --- a/lutris/shortcuts.py +++ b/lutris/shortcuts.py @@ -2,13 +2,11 @@ import os import stat import shutil -import subprocess from textwrap import dedent from gi.repository import GLib from lutris.util import system -from lutris.util.log import logger from lutris.settings import CACHE_DIR @@ -38,7 +36,7 @@ def create_launcher(game_slug, game_id, game_name, desktop=False, menu=False): launcher_filename = get_xdg_basename(game_slug, game_id, legacy=False) tmp_launcher_path = os.path.join(CACHE_DIR, launcher_filename) - tmp_launcher = open(tmp_launcher_path, "w") + tmp_launcher = open(tmp_launcher_path, "w") tmp_launcher.write(launcher_content) tmp_launcher.close() os.chmod(tmp_launcher_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | diff --git a/lutris/tosec.py b/lutris/tosec.py index 2e795e490..18f58f090 100644 --- a/lutris/tosec.py +++ b/lutris/tosec.py @@ -24,13 +24,13 @@ import os.path import datetime STANDARD_CODES = { - "[a]": "Alternate", - "[p]": "Pirate", - "[t]": "Trained", - "[T-]": "OldTranslation", - "[T+]": "NewerTranslation", - "(-)": "Unknown Year", - "[!]": "Verified Good Dump", + "[a]": "Alternate", + "[p]": "Pirate", + "[t]": "Trained", + "[T-]": "OldTranslation", + "[T+]": "NewerTranslation", + "(-)": "Unknown Year", + "[!]": "Verified Good Dump", "(\d+)": "(# of Languages)", "(??k)": "ROM Size", "(Unl)": "Unlicensed", @@ -111,8 +111,8 @@ class TOSEC: # If the old version is more recent thab the new one, the new one # shouldn't be added - if(actual_version - and datefromiso(actual_version) >= datefromiso(new_version)): + if(actual_version and + datefromiso(actual_version) >= datefromiso(new_version)): return False # What if we have to update the version instead of adding it ? diff --git a/lutris/util/desktopapps.py b/lutris/util/desktopapps.py index f91619c94..1aef3e89a 100644 --- a/lutris/util/desktopapps.py +++ b/lutris/util/desktopapps.py @@ -20,6 +20,7 @@ IGNORED_EXECUTABLES = ( "lutris", "steam" ) + def mark_as_installed(appid, runner_name, game_info): for key in ['name', 'slug']: assert game_info[key] @@ -42,6 +43,7 @@ def mark_as_installed(appid, runner_name, game_info): game_config.save() return game_id + def mark_as_uninstalled(game_info): assert 'id' in game_info assert 'name' in game_info @@ -53,6 +55,7 @@ def mark_as_uninstalled(game_info): ) return game_id + def sync_with_lutris(): apps = get_games() desktop_games_in_lutris = pga.get_desktop_games() @@ -75,13 +78,13 @@ def sync_with_lutris(): 'exe': app[2], 'args': app[3] } - game_id = mark_as_installed(appid, 'linux', game_info) + mark_as_installed(appid, 'linux', game_info) unavailable_slugs = slugs_in_lutris.difference(seen_slugs) for slug in unavailable_slugs: for game in desktop_games_in_lutris: if game['slug'] == slug: - game_id = mark_as_uninstalled(game) + mark_as_uninstalled(game) def get_games(): @@ -93,7 +96,6 @@ def get_games(): if app.get_nodisplay() or app.get_is_hidden(): continue appid = os.path.splitext(app.get_id())[0] - env = [] exe = None args = [] @@ -117,7 +119,7 @@ def get_games(): exe = cli[0] args = cli[1:] # remove %U etc. and change %% to % in arguments - args = list(map(lambda arg: re.sub('%[^%]', '', arg).replace('%%','%'), args)) + args = list(map(lambda arg: re.sub('%[^%]', '', arg).replace('%%', '%'), args)) args = subprocess.list2cmdline(args) diff --git a/lutris/util/extract.py b/lutris/util/extract.py index 5384caa45..7382bc273 100644 --- a/lutris/util/extract.py +++ b/lutris/util/extract.py @@ -38,8 +38,9 @@ def extract_archive(path, to_directory='.', merge_single=True, extractor=None): elif path.endswith('.gz') or extractor == 'gzip': decompress_gz(path, to_directory) return - elif(path.endswith('.tar.bz2') or path.endswith('.tbz') - or extractor == 'bz2'): + elif(path.endswith('.tar.bz2') or + path.endswith('.tbz') or + extractor == 'bz2'): opener, mode = tarfile.open, 'r:bz2' elif(is_7zip_supported(path, extractor)): opener = '7zip' diff --git a/tests/benchmark_download.py b/tests/benchmark_download.py index 910242cb4..3c14fe755 100644 --- a/tests/benchmark_download.py +++ b/tests/benchmark_download.py @@ -9,7 +9,6 @@ from gi.repository import Gtk, Gdk, GObject sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) -from lutris.util import http from lutris.gui.dialogs import DownloadDialog TEST_URL = "https://lutris.net/releases/lutris_0.3.0.tar.gz" diff --git a/tests/check_prefixes.py b/tests/check_prefixes.py index 630307b99..e6a5acbb0 100755 --- a/tests/check_prefixes.py +++ b/tests/check_prefixes.py @@ -37,6 +37,7 @@ def check_registry(registry_path): subprocess.call(["meld", registry_path, wrong_path]) sys.exit(2) + registries = get_registries() for registry in registries: check_registry(registry)