Make codebase pass flake8

This commit is contained in:
Mathieu Comandon 2017-03-02 19:28:05 -08:00
parent 8c3b743a44
commit bc01ab0347
22 changed files with 61 additions and 52 deletions

View file

@ -347,8 +347,8 @@ class Game(object):
def beat(self):
"""Watch the game's process(es)."""
if self.game_thread.error:
dialogs.ErrorDialog("<b>Error lauching the game:</b>\n"
+ self.game_thread.error)
dialogs.ErrorDialog("<b>Error lauching the game:</b>\n" +
self.game_thread.error)
self.on_game_quit()
return False
self.game_log = self.game_thread.stdout

View file

@ -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()

View file

@ -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)

View file

@ -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__()

View file

@ -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")

View file

@ -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',
}

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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'):

View file

@ -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 = [
{

View file

@ -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.")
}]

View file

@ -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.")
}]

View file

@ -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 = [

View file

@ -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

View file

@ -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

View file

@ -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 |

View file

@ -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 ?

View file

@ -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)

View file

@ -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'

View file

@ -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"

View file

@ -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)