2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/python
|
2010-07-04 03:05:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#Copyright 2009-2010 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
|
|
|
|
2010-09-22 17:51:56 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2009-12-03 10:26:40 +01:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import codecs
|
|
|
|
import Options
|
|
|
|
import HandHistoryConverter
|
2010-06-05 12:00:41 +02:00
|
|
|
import Configuration
|
2010-06-06 22:06:04 +02:00
|
|
|
import sys
|
2009-12-03 10:26:40 +01:00
|
|
|
|
2010-08-13 06:03:15 +02:00
|
|
|
|
2009-12-03 10:26:40 +01:00
|
|
|
(options, argv) = Options.fpdb_options()
|
2010-06-05 11:58:00 +02:00
|
|
|
config = Configuration.Config()
|
2009-12-03 10:26:40 +01:00
|
|
|
|
|
|
|
filter = options.hhc
|
|
|
|
|
|
|
|
filter_name = filter.replace("ToFpdb", "")
|
|
|
|
|
|
|
|
mod = __import__(filter)
|
|
|
|
obj = getattr(mod, filter_name, None)
|
|
|
|
|
2010-06-05 11:58:00 +02:00
|
|
|
hhc = obj(config, autostart=False)
|
2009-12-03 10:26:40 +01:00
|
|
|
|
|
|
|
if os.path.exists(options.infile):
|
|
|
|
in_fh = codecs.open(options.infile, 'r', "utf8")
|
|
|
|
filecontents = in_fh.read()
|
|
|
|
in_fh.close()
|
|
|
|
else:
|
2010-08-13 06:03:15 +02:00
|
|
|
print _("Could not find file %s") % options.infile
|
2009-12-03 10:26:40 +01:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
m = hhc.re_PlayerInfo.finditer(filecontents)
|
|
|
|
|
2010-06-06 22:06:04 +02:00
|
|
|
outfile = options.infile+".anon"
|
2010-08-13 06:03:15 +02:00
|
|
|
print _("Output being written to"), outfile
|
2010-06-06 22:06:04 +02:00
|
|
|
|
|
|
|
savestdout = sys.stdout
|
|
|
|
fsock = open(outfile,"w")
|
|
|
|
sys.stdout = fsock
|
|
|
|
|
2009-12-03 10:26:40 +01:00
|
|
|
players = []
|
|
|
|
for a in m:
|
|
|
|
players = players + [a.group('PNAME')]
|
|
|
|
|
|
|
|
uniq = set(players)
|
|
|
|
|
2010-06-05 11:58:00 +02:00
|
|
|
for i, name in enumerate(uniq):
|
2009-12-03 10:26:40 +01:00
|
|
|
filecontents = filecontents.replace(name, 'Player%d' %i)
|
|
|
|
|
|
|
|
print filecontents
|
2010-06-06 22:06:04 +02:00
|
|
|
|
|
|
|
sys.stdout = savestdout
|
|
|
|
fsock.close()
|
|
|
|
|