diff --git a/duo.py b/duo.py index 5f1c834..ca6a627 100755 --- a/duo.py +++ b/duo.py @@ -20,7 +20,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -[TODO: write this} +[TODO: write this] """ import getopt @@ -115,17 +115,17 @@ def print_gpl_warranty(): print WARRANTY -def read_command_line(): +def read_command_line(): """Analyse command line. - """ + """ # In the future, packages should be called to complete the list of # options they propose. OPT_LIST = 'u:hvqcw' - LONG_OPT_LIST = [OPT_UI, + LONG_OPT_LIST = [OPT_UI + '=', OPT_HELP, OPT_VERBOSE, OPT_QUIET, OPT_CONDITIONS, OPT_WARRANTY, - + ui.OPT_GAME_PLAYER_NAME + '=', ui.OPT_GAME_TRANSPORT + '=', ui.OPT_GAME_NB_PLAYERS + '=', @@ -142,12 +142,13 @@ def read_command_line(): opt_list, args = getopt.getopt( sys.argv[1:], OPT_LIST, LONG_OPT_LIST) if args: - print 'Unknown argument:', args print_usage() + print 'Unknown argument:', args sys.exit() - - except getopt.GetoptError: + + except getopt.GetoptError, err: print_usage() + print err sys.exit() # In depth analyse @@ -156,45 +157,44 @@ def read_command_line(): print_help() sys.exit() - if opt_name in ('-c', '--' + OPT_CONDITIONS): + elif opt_name in ('-c', '--' + OPT_CONDITIONS): print_gpl_conditions() sys.exit() - if opt_name in ('-w', '--' + OPT_WARRANTY): + elif opt_name in ('-w', '--' + OPT_WARRANTY): print_gpl_warranty() sys.exit() - if opt_name in ('-u', '--' + OPT_UI): + elif opt_name in ('-u', '--' + OPT_UI): options[OPT_UI] = opt_arg - if opt_name == ('--' + ui.OPT_GAME_PLAYER_NAME): + elif opt_name == ('--' + ui.OPT_GAME_PLAYER_NAME): options[ui.OPT_GAME_PLAYER_NAME] = opt_arg - if opt_name == ('--' + ui.OPT_GAME_TRANSPORT): + elif opt_name == ('--' + ui.OPT_GAME_TRANSPORT): options[ui.OPT_GAME_TRANSPORT] = opt_arg - if opt_name == ('--' + ui.OPT_GAME_NB_PLAYERS): + elif opt_name == ('--' + ui.OPT_GAME_NB_PLAYERS): options[ui.OPT_GAME_NB_PLAYERS] = int(opt_arg) - if opt_name == ('--' + ui.OPT_GAME_NB_CARDS): + elif opt_name == ('--' + ui.OPT_GAME_NB_CARDS): options[ui.OPT_GAME_NB_CARDS] = int(opt_arg) - if opt_name == ('--' + ui.OPT_GAME_START): + elif opt_name == ('--' + ui.OPT_GAME_START): options[ui.OPT_GAME_START] = True - if opt_name in ('-v', '--' + OPT_VERBOSE): + elif opt_name in ('-v', '--' + OPT_VERBOSE): if options[OPT_VERBOSE] != 0: options[OPT_VERBOSE] = logging.DEBUG else: print 'verbose option conflicts with quiet.' sys.exit() - - if opt_name in ('-q', '--' + OPT_QUIET): + + elif opt_name in ('-q', '--' + OPT_QUIET): if options[OPT_VERBOSE] != logging.DEBUG: options[OPT_VERBOSE] = 0 else: - print 'quiet option conflicts with \ - verbose option.' + print 'verbose option conflicts with quiet.' sys.exit() # Configure all future instances of Logger @@ -217,17 +217,16 @@ def read_command_line(): # Main try: options = read_command_line() - + # Set default language. (lang, encoding) = locale.getdefaultlocale() if not lang is None: duo.switch_to_language(lang) - + ui = ui.create_ui(options[OPT_UI], options) ui.launch() - + except KeyboardInterrupt, e: print e #except Exception, e: # print e -