From 81fea29c24e9f5f6dea498abc9bfb8dd37f643fb Mon Sep 17 00:00:00 2001 From: phear Date: Tue, 6 Sep 2005 19:05:10 +0000 Subject: [PATCH] never forget to do svn commit from the root directory of the project ;> --- goban.py | 18 ++---------------- helper.py | 18 +++++++++++++++++- psql.py | 19 ++++++++++++++++++- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/goban.py b/goban.py index 06c4176..1bd9155 100755 --- a/goban.py +++ b/goban.py @@ -92,21 +92,7 @@ def display_goban(goban): -def string_to_tuple(str): - """ - gets a string. If the string contains '(',')' and ',', then return - a tuple processed from the string. If the partial string is empty, then - -1 will be returned for that value. - """ - if (str[0] =='(') and (str[-1] ==')') and (string.find(str,',')): - splitlist = string.split(str[1:-1],",") - returnlist = [] - for item in splitlist: - try: - returnlist.append(int(item)) - except: #empty string - returnlist.append(-1) - return tuple(returnlist) + def process_form(goban): @@ -123,7 +109,7 @@ def process_form(goban): if form.keys() != []: #cut out the name of the clicked button namestring = string.split(form.keys()[0],".x")[0] - position = string_to_tuple(namestring) + position = helper.string_to_tuple(namestring) ret = set_stone(goban, position) if (type(ret) == type("")): return (goban,ret) #return old goban and error string diff --git a/helper.py b/helper.py index cdb4d3e..3b3ce6a 100644 --- a/helper.py +++ b/helper.py @@ -35,4 +35,20 @@ def check_for_int(data): ret = int(data) else: ret = data - return ret \ No newline at end of file + return ret + +def string_to_tuple(str): + """ + gets a string. If the string contains '(',')' and ',', then return + a tuple processed from the string. If the partial string is empty, then + -1 will be returned for that value. + """ + if (str[0] =='(') and (str[-1] ==')') and (string.find(str,',')): + splitlist = string.split(str[1:-1],",") + returnlist = [] + for item in splitlist: + try: + returnlist.append(int(item)) + except: #empty string + returnlist.append(-1) + return tuple(returnlist) \ No newline at end of file diff --git a/psql.py b/psql.py index f0b1df3..3de261b 100755 --- a/psql.py +++ b/psql.py @@ -68,6 +68,23 @@ def create_goban_table(size): gets:size of goban. creates postgresql table containing goban data. returns: name of created table. + + the table looks like this: + line x1 x2 x3 x4 ... x(size) + y1 + y2 + y3 + ... + y(size) + turn_number + size + name + + and the meaning of these fields: + (xn,yn) is a field of the goban, + (turn_number,x1) is the current turn, + (size,x1) is the length of a side of the goban, + (name,x1) is the name of this goban. """ tablename="test" data="line varchar(15)" @@ -188,7 +205,7 @@ def set_user_timeout(username): gets username, sets timeout to time.time + 30min """ import time - timeout = int(time.time()) + 1800 #current time in seconds + seconds for session + timeout = int(time.time()) + 900 #current time in seconds + seconds for session executestring ="UPDATE users SET timeout = '%s' WHERE username = '%s'" %(timeout, username) sql_one_liner(executestring)