Skip to content

Commit

Permalink
Clean up the launcher (pep8)
Browse files Browse the repository at this point in the history
- Use utf-8 as encoding
- remove names from comments
- gather and sort imports
- remove global vars
- pep8 the code (exceptions, spaces).
  • Loading branch information
Linkid committed Nov 12, 2017
1 parent bd7a0a5 commit bb5658c
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions FoFiX.py
@@ -1,11 +1,11 @@
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# -*- coding: utf-8 -*-

#####################################################################
# Frets on Fire X (FoFiX) #
# Copyright (C) 2006 Sami Kyöstilä #
# 2008 evilynux <evilynux@gmail.com> #
# 2012 FoFiX Team #
# 2009 akedrou #
# 2009-2017 FoFiX Team #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
Expand All @@ -28,11 +28,25 @@
'''

import argparse
import sys
import atexit
import os
import platform
import subprocess
import atexit
import sys
import traceback

import pygame
import fretwork
from fretwork import log

from fofix.core import Config
from fofix.core import VFS
from fofix.core import Version
from fofix.core.GameEngine import GameEngine
from fofix.core.Language import _
from fofix.core.VideoPlayer import VideoLayer, VideoPlayerError
from fofix.game.MainMenu import MainMenu


def run_command(command):
command = command.split(' ')
Expand Down Expand Up @@ -76,15 +90,16 @@ def disable_gl_checks():
OpenGL.SIZE_1_ARRAY_UNPACK = False
OpenGL.STORE_POINTERS = False


def cmd_args():
parser = argparse.ArgumentParser(description='Frets On Fire X (FoFiX)')
# Where the name automatically assigned to the metavar option is to long i used x in its place.
# Might go back and
options = parser.add_argument_group('Options')
options.add_argument('-r', '--resolution', type=str, metavar='x', help='Force a specific resolution to be used.', default=None)
options.add_argument('-f', '--fullscreen', action='store_true', help='Force usage of full-screen mode.', default=None)
options.add_argument('-c', '--config', type=str, metavar='x', help='Use this configuration file instead of the fofix.ini in its default location. Use "reset" to use the usual fofix.ini but clear it first.')
options.add_argument('-t', '--theme', type=str, metavar='x', help='Force the specified theme to be used. Remember to quote the theme name if it contains spaces (e.g. %(prog)s -t "Guitar Hero III")', default=None)
options.add_argument('-r', '--resolution', type=str, metavar='x', help='Force a specific resolution to be used.', default=None)
options.add_argument('-f', '--fullscreen', action='store_true', help='Force usage of full-screen mode.', default=None)
options.add_argument('-c', '--config', type=str, metavar='x', help='Use this configuration file instead of the fofix.ini in its default location. Use "reset" to use the usual fofix.ini but clear it first.')
options.add_argument('-t', '--theme', type=str, metavar='x', help='Force the specified theme to be used. Remember to quote the theme name if it contains spaces (e.g. %(prog)s -t "Guitar Hero III")', default=None)
options.add_argument('-s', '--song', type=str, help='Play a song in one-shot mode. (See "One-shot mode options" below.)')

osm = parser.add_argument_group('One-Shot Mode')
Expand All @@ -94,43 +109,24 @@ def cmd_args():
osm.add_argument('-n', '--players', type=int, help='Number of multiplayer players.')

adv = parser.add_argument_group('Advanced')
adv.add_argument('-v', '--verbose', action='store_true', help='Verbose messages')
adv.add_argument('-v', '--verbose', action='store_true', help='Verbose messages')
adv.add_argument('-g', '--gl-error-check', action='store_true', help='Enable OpenGL error checking.')

return vars(parser.parse_args())

args = cmd_args()

#stump: disable pyOpenGL error checking if we are not asked for it.
# This must be before *anything* that may import pyOpenGL!
if not args['gl_error_check']:
disable_gl_checks()

import traceback

import pygame

import fretwork

from fretwork import log

from fofix.core import Version
from fofix.core import VFS

# setup the logfile
# File object representing the logfile.
if os.name == "posix": # evilynux - logfile in ~/.fofix/ for GNU/Linux and MacOS X
# evilynux - Under MacOS X, put the logs in ~/Library/Logs
# logfile in ~/.fofix/ for GNU/Linux and MacOS X
if os.name == "posix":
# Under MacOS X, put the logs in ~/Library/Logs
if os.uname()[0] == "Darwin":
logFile = open(os.path.expanduser('~/Library/Logs/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME), 'w')
else: # GNU/Linux et al.
logFile = VFS.open('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME, 'w')
else:
logFile = VFS.open('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME, 'w')

log.setLogfile(logFile)

import fretwork
fretworkRequired = (0, 2, 0)
reqVerStr = '.'.join([str(i) for i in fretworkRequired])
fretworkErrorStr = '''
Expand All @@ -140,30 +136,25 @@ def cmd_args():
Installed: {0}
Required: {1}
'''
if hasattr(fretwork, '__version__'): # The first version of fretwork didnt have __version__
# The first version of fretwork didnt have __version__
if hasattr(fretwork, '__version__'):
version = fretwork.__version__.split('-')[0] # remove 'dev' from ver
version = tuple([int(i) for i in version.split('.')])

if version < fretworkRequired:
fwErrStr = fretworkErrorStr.format(fretwork.__version__, reqVerStr)
raise RuntimeError(fwErrStr)

else:
version = '0.1.0'
fwErrStr = fretworkErrorStr.format(version, reqVerStr)
raise RuntimeError(fwErrStr)

from fofix.core.VideoPlayer import VideoLayer, VideoPlayerError
from fofix.core.GameEngine import GameEngine
from fofix.game.MainMenu import MainMenu
from fofix.core.Language import _
from fofix.core import Config

class Main():
def __init__(self):
global args
self.args = args

# get args
self.args = cmd_args()
self.playing = self.args['song']
self.configFile = self.args['config']
self.fullscreen = self.args['fullscreen']
Expand All @@ -174,17 +165,23 @@ def __init__(self):
self.mode = self.args['mode']
self.players = self.args['players']

# disable pyOpenGL error checking if we are not asked for it.
# This must be before *anything* that may import pyOpenGL!
if not self.args['gl_error_check']:
disable_gl_checks()

# load config
self.config = self.load_config(self.configFile)

#Lysdestic - Allow support for manipulating fullscreen via CLI
# allow support for manipulating fullscreen via CLI
if self.fullscreen is not None:
Config.set("video", "fullscreen", self.fullscreen)

#Lysdestic - Change resolution from CLI
# change resolution from CLI
if self.resolution is not None:
Config.set("video", "resolution", self.resolution)

#Lysdestic - Alter theme from CLI
# alter theme from CLI
if self.theme is not None:
Config.set("coffee", "themename", self.theme)

Expand All @@ -206,14 +203,14 @@ def load_config(configPath):
os.remove(fileName)

# Recreate it
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault=True)

else:
# Load specified config file
config = Config.load(configPath, setAsDefault = True)
config = Config.load(configPath, setAsDefault=True)
else:
# Use default configuration file
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault=True)

return config

Expand Down Expand Up @@ -304,6 +301,7 @@ def run(self):
# evilynux - MainMenu class already calls this - useless?
self.engine.quit()


if __name__ == '__main__':
try:
# This loop restarts the game if a restart is requested
Expand All @@ -315,7 +313,7 @@ def run(self):

except (KeyboardInterrupt, SystemExit):
raise
except:
except Exception:
log.error("Terminating due to unhandled exception: ")
_logname = os.path.abspath(log.logFile.name)
_errmsg = "%s\n\n%s\n%s\n%s\n%s" % (
Expand Down

0 comments on commit bb5658c

Please sign in to comment.