2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Carl Gherardi
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt
18 """A script for adding new stats to the regression test library"""
22 import logging
, os
, sys
, string
23 import re
, urllib2
, datetime
, pytz
26 pp
= pprint
.PrettyPrinter(indent
=4)
28 def write_file(filename
, data
):
30 f
= open(filename
, 'w')
35 def update(leaf
, file_type
, stat
, default
):
37 #print "DEBUG: fileanme: %s" % filename
39 # Test if this is a hand history file
40 if filename
.endswith(file_type
):
41 in_fh
= codecs
.open(filename
, 'r', 'utf8')
42 whole_file
= in_fh
.read()
45 hash = eval(whole_file
)
48 print "player:", player
, "<end>"
49 hash[player
][stat
] = default
50 elif file_type
==".hands":
53 out_string
= pp
.pformat(hash)
54 out_string
= string
.replace(out_string
, "<UTC>", "pytz.utc")
55 write_file(filename
, out_string
)
57 def walk_test_files(dir, file_type
, stat
, default
):
58 """Walks a directory, and executes a callback on each file
59 dir: directory of to search
60 file_type: .hands or .hp
62 default: value to insert"""
63 dir = os
.path
.abspath(dir)
64 for file in [file for file in os
.listdir(dir) if not file in [".",".."]]:
65 nfile
= os
.path
.join(dir,file)
66 if os
.path
.isdir(nfile
):
67 walk_test_files(nfile
, file_type
, stat
, default
)
69 update(nfile
, file_type
, stat
, default
)
73 print "Edit this script to activate walk_test_files in main(). Parameters explained in comment of walk_test_files."
74 print "\t./ScriptAddStatToRegression.py"
81 (options
, argv
) = Options
.fpdb_options()
83 if options
.usage
== True: # or (len(argv) < 1):
87 print "This script will modify many files in the regression test suite"
88 print "As a safety precaution, you need to edit the file manually to run it"
89 #walk_test_files('regression-test-files/', '.hp', 'NEW_STAT', "DEFAULT_VALUE")
91 if __name__
== '__main__':