# The master toctree document. master_doc = 'index' # General information about the project. project = u'pyChallenge' copyright = u'2011, pyChallenge Team' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. rev = subprocess.Popen(['git', 'rev-parse', 'HEAD'], cwd='..', stdout=subprocess.PIPE).communicate()[0].strip()[:8] # # The short X.Y version. version = pychallenge.get_version() # The full version, including alpha/beta/rc tags. release = '%s %s' % (version, rev) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files.
def parse(arguments=None): """ Parses the command-line arguments either passed in the parameter arguments, or if None, from the standard input. """ parser = argparse.ArgumentParser(prog='pyChallenge') parser.add_argument('-g', '--game', help='The game for the following ' \ 'command. The default value is "chess".') parser.add_argument('-a', '--algorithm', help='The algorithm for the ' \ 'following command. The default value is "elo"') parser.add_argument('-v', '--version', action='version', version="%s version: %s" % ("%(prog)s", pychallenge.get_version()), help='Print out the version of pyChallenge and exit') subparsers = parser.add_subparsers(help='sub-command help') # import config p_config = subparsers.add_parser( 'import-config', help='Update the config table with a given config file in csv format.') p_config.add_argument('file', help='The (csv) config file to import') p_config.set_defaults(func=import_config) # import results p_import = subparsers.add_parser('import-results', help='Import data to the result table from a csv file. This only ' \ 'adds the matches but does not compute any ratings.') p_import.add_argument('file', help='The file to import') p_import.set_defaults(func=import_results) # add result p_add_result = subparsers.add_parser('add-result', help='Add a result to the result table. This only adds the matches ' \ 'but does not compute any ratings.') p_add_result.add_argument('player1', help='Nickname of player 1') p_add_result.add_argument('player2', help='Nickname of player 2') p_add_result.add_argument('outcome', type=float, help='Outcome of the ' \ 'game: 0 = player 1 lost; 0.5 = draw; 1 = player 1 won') p_add_result.add_argument('date', type=int, help='The date of the game') p_add_result.set_defaults(func=add_result) # update p_update = subparsers.add_parser('update', help='Update the rating values for all players in the given game ' \ 'for the specified algorithm.') p_update.set_defaults(func=update) # match p_match = subparsers.add_parser('match', help='Find the best opponent for the given player in the specified ' \ 'game with the selected algorithm.') p_match.add_argument('player', help='Nickname of the player') p_match.set_defaults(func=match) # get value p_value = subparsers.add_parser('rating', help='Query the rating of the ' \ 'given player in the specified game using the selected algorithm.') p_value.add_argument('player', help='Nickname of the player') p_value.set_defaults(func=rating) # best p_best = subparsers.add_parser( 'best', help='Query the best player(s) in the given game and algorithm.') p_best.add_argument('amount', nargs='?', type=int, default=1, help='The number of players to query. "10" for Top 10') p_best.set_defaults(func=lambda x: best_worst(x, True)) # worst p_worst = subparsers.add_parser( 'worst', help='Query the worst player(s) in the given game and algorithm.') p_worst.add_argument( 'amount', nargs='?', type=int, default=1, help='The number of player to query. "10" for Worst 10') p_worst.set_defaults(func=lambda x: best_worst(x, False)) # predict p_predict = subparsers.add_parser('predict', help='Predict the matches listed in a csv file and write the ' \ 'predicted results to another csv file.') p_predict.add_argument('ifile', help='The file to import') p_predict.add_argument('ofile', help='The output file') p_predict.add_argument('-i', '--incremental', action="store_true", help='If specified, updates the ratings after each match on-the-fly.' \ ' This does not set any values in the database. If not specified, ' \ 'uses the current ratings for each listed game.') p_predict.set_defaults(func=predict) # compare two players p_compare = subparsers.add_parser('compare', help='Compare two players in the specified game with the given ' \ 'algorithm and predict who will win.') p_compare.add_argument('player1', help='Nickname of player 1') p_compare.add_argument('player2', help='Nickname of player 2') p_compare.set_defaults(func=compare) # create new player p_create_player = subparsers.add_parser('create-player', help='Creates a new player in the database and initializes his ' \ 'rating with the default values.') p_create_player.add_argument('nickname', help='Nickname for the new player') p_create_player.add_argument('firstname', type=unicode, help='First name of the new player') p_create_player.add_argument('lastname', type=unicode, help='Last name of the new player') p_create_player.set_defaults(func=create_player) # clear p_clear = subparsers.add_parser( 'clear', help='Clears ratings and/or matches. See --ranks and --matches.') p_clear.add_argument( '-r', '--ranks', action='store_true', help='Clear the ranks and set the default values for all players') p_clear.add_argument('-m', '--matches', action='store_true', help='Clear all matches') p_clear.set_defaults(func=clear) # history p_history = subparsers.add_parser( 'history', help='Shows the history of the given player(s)') p_history.add_argument('player1', help='Nickname of player 1') p_history.add_argument('player2', nargs='?', default=None, help='Nickname of player 2') p_history.set_defaults(func=history) if arguments is None: args = parser.parse_args() else: args = parser.parse_args(arguments) if (not utils.prepare_args(args)): return print "" args.func(args) print ""
master_doc = 'index' # General information about the project. project = u'pyChallenge' copyright = u'2011, pyChallenge Team' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. rev = subprocess.Popen(['git', 'rev-parse', 'HEAD'], cwd='..', stdout=subprocess.PIPE).communicate()[0].strip()[:8] # # The short X.Y version. version = pychallenge.get_version() # The full version, including alpha/beta/rc tags. release = '%s %s' % (version, rev) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files.
def parse(arguments=None): """ Parses the command-line arguments either passed in the parameter arguments, or if None, from the standard input. """ parser = argparse.ArgumentParser(prog='pyChallenge') parser.add_argument('-g', '--game', help='The game for the following ' \ 'command. The default value is "chess".') parser.add_argument('-a', '--algorithm', help='The algorithm for the ' \ 'following command. The default value is "elo"') parser.add_argument('-v', '--version', action='version', version="%s version: %s" % ("%(prog)s", pychallenge.get_version()), help='Print out the version of pyChallenge and exit') subparsers = parser.add_subparsers(help='sub-command help') # import config p_config = subparsers.add_parser('import-config', help='Update the config table with a given config file in csv format.') p_config.add_argument('file', help='The (csv) config file to import') p_config.set_defaults(func=import_config) # import results p_import = subparsers.add_parser('import-results', help='Import data to the result table from a csv file. This only ' \ 'adds the matches but does not compute any ratings.') p_import.add_argument('file', help='The file to import') p_import.set_defaults(func=import_results) # add result p_add_result = subparsers.add_parser('add-result', help='Add a result to the result table. This only adds the matches ' \ 'but does not compute any ratings.') p_add_result.add_argument('player1', help='Nickname of player 1') p_add_result.add_argument('player2', help='Nickname of player 2') p_add_result.add_argument('outcome', type=float, help='Outcome of the ' \ 'game: 0 = player 1 lost; 0.5 = draw; 1 = player 1 won') p_add_result.add_argument('date', type=int, help='The date of the game') p_add_result.set_defaults(func=add_result) # update p_update = subparsers.add_parser('update', help='Update the rating values for all players in the given game ' \ 'for the specified algorithm.') p_update.set_defaults(func=update) # match p_match = subparsers.add_parser('match', help='Find the best opponent for the given player in the specified ' \ 'game with the selected algorithm.') p_match.add_argument('player', help='Nickname of the player') p_match.set_defaults(func=match) # get value p_value = subparsers.add_parser('rating', help='Query the rating of the ' \ 'given player in the specified game using the selected algorithm.') p_value.add_argument('player', help='Nickname of the player') p_value.set_defaults(func=rating) # best p_best = subparsers.add_parser('best', help='Query the best player(s) in the given game and algorithm.') p_best.add_argument('amount', nargs='?', type=int, default=1, help='The number of players to query. "10" for Top 10') p_best.set_defaults(func=lambda x: best_worst(x, True)) # worst p_worst = subparsers.add_parser('worst', help='Query the worst player(s) in the given game and algorithm.') p_worst.add_argument('amount', nargs='?', type=int, default=1, help='The number of player to query. "10" for Worst 10') p_worst.set_defaults(func=lambda x: best_worst(x, False)) # predict p_predict = subparsers.add_parser('predict', help='Predict the matches listed in a csv file and write the ' \ 'predicted results to another csv file.') p_predict.add_argument('ifile', help='The file to import') p_predict.add_argument('ofile', help='The output file') p_predict.add_argument('-i', '--incremental', action="store_true", help='If specified, updates the ratings after each match on-the-fly.' \ ' This does not set any values in the database. If not specified, ' \ 'uses the current ratings for each listed game.') p_predict.set_defaults(func=predict) # compare two players p_compare = subparsers.add_parser('compare', help='Compare two players in the specified game with the given ' \ 'algorithm and predict who will win.') p_compare.add_argument('player1', help='Nickname of player 1') p_compare.add_argument('player2', help='Nickname of player 2') p_compare.set_defaults(func=compare) # create new player p_create_player = subparsers.add_parser('create-player', help='Creates a new player in the database and initializes his ' \ 'rating with the default values.') p_create_player.add_argument('nickname', help='Nickname for the new player') p_create_player.add_argument('firstname', type=unicode, help='First name of the new player') p_create_player.add_argument('lastname', type=unicode, help='Last name of the new player') p_create_player.set_defaults(func=create_player) # clear p_clear = subparsers.add_parser('clear', help='Clears ratings and/or matches. See --ranks and --matches.') p_clear.add_argument('-r', '--ranks', action='store_true', help='Clear the ranks and set the default values for all players') p_clear.add_argument('-m', '--matches', action='store_true', help='Clear all matches') p_clear.set_defaults(func=clear) # history p_history = subparsers.add_parser('history', help='Shows the history of the given player(s)') p_history.add_argument('player1', help='Nickname of player 1') p_history.add_argument('player2', nargs='?', default=None, help='Nickname of player 2') p_history.set_defaults(func=history) if arguments is None: args = parser.parse_args() else: args = parser.parse_args(arguments) if (not utils.prepare_args(args)): return print "" args.func(args) print ""