Module create_sgf
[hide private]
[frames] | no frames]

Source Code for Module create_sgf

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  #       Create_sgf.py 
 5  #        
 6  #       Copyright 2010 Victor Ramirez <virako.9@gmail.com> 
 7  #        
 8  #       This program is free software; you can redistribute it and/or modify 
 9  #       it under the terms of the GNU General Public License as published by 
10  #       the Free Software Foundation; either version 2 of the License, or 
11  #       (at your option) any later version. 
12  #        
13  #       This program is distributed in the hope that it will be useful, 
14  #       but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #       GNU General Public License for more details. 
17  #        
18  #       You should have received a copy of the GNU General Public License 
19  #       along with this program; if not, write to the Free Software 
20  #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21  #       MA 02110-1301, USA. 
22   
23  import cte  
24   
25 -class Create_sgf:
26 """Clase que nos genera un archivo de extensión .sgf con una cabezera 27 predeterminada para guardar la partida que estamos capturando. """
28 - def __init__(self, path = "sgf"):
29 num = 0 30 self.path = path 31 self.cadena = cte.PLAYER_B + "-" + cte.PLAYER_W 32 name = self.cadena 33 try: 34 while 1: 35 file = open("%s/%s.sgf" %(self.path, self.cadena), "r") # TODO existe el archivo 36 file.close() 37 num += 1 38 self.cadena = name + "(" + str(num) + ")" 39 except IOError: 40 file = open("%s/%s.sgf" %(self.path, self.cadena), "w") 41 for elem in cte.INITSGF: 42 file.write(elem) 43 file.close()
44
45 - def add_text(self, text, color):
46 file = open("%s/%s.sgf" %(self.path, self.cadena), "a") 47 if color == cte.BLACK: 48 file.write("\n;B[%s]" %text) 49 elif color == cte.WHITE: 50 file.write("\n;W[%s]" %text) 51 else: 52 print "el color debe ser BLACK or WHITE" 53 file.close()
54
55 - def end_file(self):
56 file = open("%s/%s.sgf" %(self.path, self.cadena), "a") 57 file.write("))") 58 file.close()
59