diff --git a/packaging/debian/changelog b/packaging/debian/changelog index ec66f4a7..4bacf635 100644 --- a/packaging/debian/changelog +++ b/packaging/debian/changelog @@ -1,8 +1,8 @@ -free-poker-tools (0.12-1) unstable; urgency=low +free-poker-tools (0.12~git20100122) unstable; urgency=low - * New release + * New snapshot release with reworked import code - -- Mika Bostrom Mon, 26 Oct 2009 17:49:07 +0200 + -- Mika Bostrom Fri, 22 Jan 2010 09:25:27 +0200 free-poker-tools (0.11.3+git20091023) unstable; urgency=low diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py new file mode 100644 index 00000000..f8043876 --- /dev/null +++ b/pyfpdb/Charset.py @@ -0,0 +1,52 @@ +#!/usr/bin/python + +#Copyright 2010 Mika Bostrom +#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 in the docs folder of the package. + +# String manipulation +import codecs + +# Settings +import Configuration + +encoder_to_utf = codecs.lookup('utf-8') +encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) + +# I'm saving a few cycles with this one +not_needed = False +if Configuration.LOCALE_ENCODING == 'utf-8': + not_needed = True + +def to_utf8(s): + if not_needed: return s + + try: + #(_out, _len) = encoder_to_utf.encode(s) + _out = unicode(s, Configuration.LOCALE_ENCODING).encode('utf-8') + return _out + except UnicodeDecodeError: + print 'Could not convert: "%s"' % s + raise + +def to_gui(s): + if not_needed: return s + + try: + (_out, _len) = encoder_to_sys.encode(s) + return _out + except UnicodeDecodeError: + print 'Could not convert: "%s"' % s + raise + diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 5f3c7c34..7194b230 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -48,6 +48,7 @@ import Configuration import SQL import Card import Tourney +import Charset from Exceptions import * log = Configuration.get_logger("logging.conf") @@ -595,7 +596,8 @@ class Database: if site_id is None: site_id = -1 c = self.get_cursor() - c.execute(self.sql.query['get_player_names'], (like_player_name, site_id, site_id)) + p_name = Charset.to_utf8(like_player_name) + c.execute(self.sql.query['get_player_names'], (p_name, site_id, site_id)) rows = c.fetchall() return rows diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 9ebeb0c5..c2778789 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -29,6 +29,7 @@ import gobject import Configuration import fpdb_db import FpdbSQLQueries +import Charset class Filters(threading.Thread): def __init__(self, db, config, qdict, display = {}, debug=True): @@ -242,6 +243,7 @@ class Filters(threading.Thread): print "DEBUG: %s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()]) def createPlayerLine(self, hbox, site, player): + print 'DEBUG :: add:"%s"' % player label = gtk.Label(site +" id:") hbox.pack_start(label, False, False, 0) @@ -258,13 +260,17 @@ class Filters(threading.Thread): completion.set_model(liststore) completion.set_text_column(0) names = self.db.get_player_names(self.conf) # (config=self.conf, site_id=None, like_player_name="%") - for n in names: - liststore.append(n) + for n in names: # list of single-element "tuples" + _n = Charset.to_gui(n[0]) + _nt = (_n, ) + liststore.append(_nt) self.__set_hero_name(pname, site) def __set_hero_name(self, w, site): - self.heroes[site] = w.get_text() + _name = w.get_text() + _guiname = Charset.to_gui(_name) + self.heroes[site] = _guiname # print "DEBUG: setting heroes[%s]: %s"%(site, self.heroes[site]) def __set_num_hands(self, w, val): @@ -452,7 +458,8 @@ class Filters(threading.Thread): vbox.pack_start(hBox, False, True, 0) player = self.conf.supported_sites[site].screen_name - self.createPlayerLine(hBox, site, player) + _pname = Charset.to_gui(player) + self.createPlayerLine(hBox, site, _pname) if "GroupsAll" in display and display["GroupsAll"] == True: hbox = gtk.HBox(False, 0) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 9daa940f..4534920a 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -145,7 +145,8 @@ class GuiGraphViewer (threading.Thread): if sites[site] == True: sitenos.append(siteids[site]) c = self.db.get_cursor() - c.execute(self.sql.query['getPlayerId'], (heroes[site],)) + _hname = Charset.to_utf8(heroes[site]) + c.execute(self.sql.query['getPlayerId'], (_hname,)) result = c.fetchall() if len(result) == 1: playerids.append( int(result[0][0]) ) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 1da08fbc..8aeff03d 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -29,6 +29,7 @@ import fpdb_import import Database import fpdb_db import Filters +import Charset colalias,colshow,colheading,colxalign,colformat,coltype = 0,1,2,3,4,5 ranks = {'x':0, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14} @@ -190,7 +191,8 @@ class GuiPlayerStats (threading.Thread): sitenos.append(siteids[site]) # Nasty hack to deal with multiple sites + same player name -Eric que = self.sql.query['getPlayerId'] + " AND siteId=%d" % siteids[site] - self.cursor.execute(que, (heroes[site],)) + _hname = Charset.to_utf8(heroes[site]) + self.cursor.execute(que, (_hname,)) result = self.db.cursor.fetchall() if len(result) == 1: playerids.append(result[0][0]) diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index d8cd7042..b5ca0867 100755 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -47,6 +47,7 @@ import fpdb_import import Database import Filters import FpdbSQLQueries +import Charset class GuiSessionViewer (threading.Thread): def __init__(self, config, querylist, mainwin, debug=True): @@ -181,7 +182,10 @@ class GuiSessionViewer (threading.Thread): for site in sites: if sites[site] == True: sitenos.append(siteids[site]) - self.cursor.execute(self.sql.query['getPlayerId'], (heroes[site],)) + _q = self.sql.query['getPlayerId'] + _name = Charset.to_utf8(heroes[site]) + print 'DEBUG(_name) :: %s' % _name + self.cursor.execute(_q, (_name,)) # arg = tuple result = self.db.cursor.fetchall() if len(result) == 1: playerids.append(result[0][0]) diff --git a/pyfpdb/GuiTableViewer.py b/pyfpdb/GuiTableViewer.py index 57fc772d..bfaa3824 100644 --- a/pyfpdb/GuiTableViewer.py +++ b/pyfpdb/GuiTableViewer.py @@ -79,7 +79,8 @@ class GuiTableViewer (threading.Thread): #then the data rows for player in range(len(self.player_names)): tmp=[] - tmp.append(self.player_names[player][0]) + p_name = Charset.to_gui(self.player_names[player][0]) + tmp.append(p_name) seatCount=len(self.player_names) if seatCount>=8: