From eb1b758eb2c2095b37726994d5f87a091c8ddcf3 Mon Sep 17 00:00:00 2001 From: Worros Date: Mon, 14 Feb 2011 00:13:30 +0800 Subject: [PATCH] Script: Script to add a new stat to the regression test suite --- pyfpdb/ScriptAddStatToRegression.py | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 pyfpdb/ScriptAddStatToRegression.py diff --git a/pyfpdb/ScriptAddStatToRegression.py b/pyfpdb/ScriptAddStatToRegression.py new file mode 100644 index 00000000..49b92567 --- /dev/null +++ b/pyfpdb/ScriptAddStatToRegression.py @@ -0,0 +1,82 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +#Copyright 2008-2011 Carl Gherardi +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as published by +#the Free Software Foundation, version 3 of the License. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see . +#In the "official" distribution you can find the license in agpl-3.0.txt + +"""A script for adding new stats to the regression test library""" + +import Options + +import logging, os, sys +import re, urllib2 +import codecs +import pprint +pp = pprint.PrettyPrinter(indent=4) + +def write_file(filename, data): + print data + f = open(filename, 'w') + f.write(data) + f.close() + print f + +def update(leaf, stat, default): + filename = leaf + #print "DEBUG: fileanme: %s" % filename + + # Test if this is a hand history file + if filename.endswith('.hp'): + in_fh = codecs.open(filename, 'r', 'utf8') + whole_file = in_fh.read() + in_fh.close() + + hash = eval(whole_file) + for player in hash: + hash[player][stat] = default + + string = pp.pformat(hash) + write_file(filename, string) + +def walk_testfiles(dir, stat, default): + """Walks a directory, and executes a callback on each file """ + dir = os.path.abspath(dir) + for file in [file for file in os.listdir(dir) if not file in [".",".."]]: + nfile = os.path.join(dir,file) + if os.path.isdir(nfile): + walk_testfiles(nfile, stat, default) + else: + update(nfile, stat, default) + +def usage(): + print "USAGE:" + print "\t./ScriptAddStatToRegression.py" + sys.exit(0) + +def main(argv=None): + if argv is None: + argv = sys.argv[1:] + + (options, argv) = Options.fpdb_options() + + if options.usage == True: + usage() + + print "WARNING:" + print "This script will modify many files in the regression test suite" + print "As is safety precaution, you need to edit the file manually to run it" + #walk_testfiles('regression-test-files/', 'street0_C4BChance', False) + +if __name__ == '__main__': + main()