Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

- DB save enhancements + minor improvements #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions Code/Gestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import random
import time
import logging

import LCEngine

Expand Down Expand Up @@ -1366,7 +1367,11 @@ def utilidades(self, liMasOpciones=None, siArbol=True):

menuSave.separador()

menuSave.opcion("dbfichero", _("Database"), Iconos.DatabaseCNew())
# menuSave.opcion("dbfichero", _("Database"), Iconos.DatabaseCNew())
dbAction = "dbfichero"
siFen = not self.partida.siFenInicial()
dbMenu = menuSave.submenu(_("Database"), Iconos.DatabaseCNew())
QTVarios.crearDBMenu(dbMenu, dbAction, self.configuracion, siFen)

menuSave.separador()

Expand Down Expand Up @@ -1480,8 +1485,11 @@ def utilidades(self, liMasOpciones=None, siArbol=True):
elif resp == "pgnfichero":
self.salvaPGN()

elif resp == "dbfichero":
self.salvaDB()
elif resp.startswith("dbfichero"):
db = resp.split(":")[1]
logging.info("Selected DB in menu: %s", db)
siFen = not self.partida.siFenInicial()
self.salvaDB(db, siFen)

elif resp.startswith("fen") or resp.startswith("fns"):
extension = resp[:3]
Expand All @@ -1498,14 +1506,13 @@ def showAnalisis(self):
um.final()
PantallaAnalisis.showGraph(self.pantalla, self, alm, Analisis.muestraAnalisis)

def salvaDB(self):
siFen = not self.partida.siFenInicial()
database = QTVarios.selectDB(self.pantalla, self.configuracion, siFen)
if database is None:
return

def salvaDB(self, dbNom, siFen):
logging.info("Saving to DB: %s", dbNom)

pgn = self.listado("pgn")
liTags = []

for linea in pgn.split("\n"):
if linea.startswith("["):
ti = linea.split('"')
Expand All @@ -1519,14 +1526,21 @@ def salvaDB(self):
pc = Partida.PartidaCompleta(liTags=liTags)
pc.leeOtra(self.partida)

database = os.path.abspath(dbNom)
logging.info("DB absPath: %s", database)
db = DBgamesFEN.DBgamesFEN(database) if siFen else DBgames.DBgames(database)

logging.info("Attempting save to DB: %s", db)
resp = db.inserta(pc)
db.close()
logging.info("DB response: %s", resp)

if resp:
QTUtil2.mensaje(self.pantalla, _("Saved"))
else:
QTUtil2.mensError(self.pantalla, _("This game already exists."))


def salvaPKS(self):
pgn = self.listado("pgn")
dic = self.procesador.saveAsPKS(self.estado, self.partida, pgn)
Expand Down
8 changes: 4 additions & 4 deletions Code/GestorPGN.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@


class GestorPGN(Gestor.Gestor):

def inicio(self, opcion):
self.finExit = True
self.tipoJuego = kJugPGN
self.finExit = False
self.estado = kFinJuego
self.nuestroFichero = self.configuracion.salvarFichero
self.siNuestroFichero = self.nuestroFichero and os.path.isfile(self.nuestroFichero)

liOpciones = [k_mainmenu]
self.muestraInicial = True # Para controlar si con un Cancel buscando un PGN se puede terminar

Expand Down Expand Up @@ -95,8 +96,7 @@ def procesarAccion(self, clave):
Gestor.Gestor.rutinaAccionDef(self, clave)

def comandoExterno(self):
self.finExit = True
fichero = sys.argv[1]
fichero = self.procesador.args.chessFile
if os.path.isfile(fichero):
siTemporal = os.path.dirname(fichero).lower() == "tmp"
self.pantalla.soloEdicionPGN(None if siTemporal else fichero)
Expand All @@ -107,7 +107,7 @@ def comandoExterno(self):

def finPartida(self):
if self.finExit:
fichero = sys.argv[1]
fichero = self.procesador.args.chessFile
if os.path.dirname(fichero).lower() == "tmp":
Util.borraFichero(fichero)
self.procesador.procesarAccion(k_terminar)
Expand Down
4 changes: 2 additions & 2 deletions Code/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
prlkn("DEBUG " * 20)


def init():
def init(args):
if not DEBUG:
sys.stderr = Util.Log("bug.log")

mainProcesador = Procesador.Procesador()
mainProcesador = Procesador.Procesador(args)
mainProcesador.setVersion(VERSION)
runSound = Sonido.RunSound()
resp = Gui.lanzaGUI(mainProcesador)
Expand Down
65 changes: 33 additions & 32 deletions Code/Procesador.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import sys
import webbrowser
import logging

from Code import AperturasStd
from Code import Routes
Expand Down Expand Up @@ -71,9 +72,10 @@ class Procesador:
"""
Vinculo entre pantalla y gestores
"""
def __init__(self):
def __init__(self, args):
if VarGen.listaGestoresMotor is None:
VarGen.listaGestoresMotor = XGestorMotor.ListaGestoresMotor()
self.args = args

def iniciaConUsuario(self, user):

Expand Down Expand Up @@ -126,45 +128,44 @@ def iniciarGUI(self):
self.tablero = self.pantalla.tablero

self.entrenamientos = Entrenamientos.Entrenamientos(self)
comando = self.args.chessFile
fen = self.args.fen
logging.info("Chess file to use: %s", comando)
logging.info("Fen to use: %s", fen)


if self.configuracion.siAplazada:
aplazamiento = self.configuracion.aplazamiento
self.juegaAplazada(aplazamiento)
else:
if len(sys.argv) > 1:
comando = sys.argv[1]
comandoL = comando.lower()
if comandoL.endswith(".pgn"):
aplazamiento = {}
aplazamiento["TIPOJUEGO"] = kJugPGN
aplazamiento["SIBLANCAS"] = True # Compatibilidad
self.juegaAplazada(aplazamiento)
return
elif comandoL.endswith(".pks"):
aplazamiento = {}
aplazamiento["TIPOJUEGO"] = kJugSolo
aplazamiento["SIBLANCAS"] = True # Compatibilidad
self.juegaAplazada(aplazamiento)
return
elif comandoL.endswith(".lcg"):
self.externDatabase(comando)
return
elif comando:
comandoL = comando.lower()
if comandoL.endswith(".pgn"):
aplazamiento = {}
aplazamiento["TIPOJUEGO"] = kJugPGN
aplazamiento["SIBLANCAS"] = True # Compatibilidad
self.juegaAplazada(aplazamiento)
return
elif comandoL.endswith(".pks"):
aplazamiento = {}
aplazamiento["TIPOJUEGO"] = kJugSolo
aplazamiento["SIBLANCAS"] = True # Compatibilidad
self.juegaAplazada(aplazamiento)
return
elif comandoL.endswith(".lcg"):
self.externDatabase(comando)
return
# elif comandoL.endswith(".lcf"):
# self.externDatabaseFEN(comando)
# return
elif comandoL.endswith(".bmt"):
self.inicio()
self.externBMT(comando)
return
elif comando == "-play":
fen = sys.argv[2]
self.juegaExterno(fen)

return

else:
elif comandoL.endswith(".bmt"):
self.inicio()
self.externBMT(comando)
return
elif fen:
self.juegaExterno(fen)
return
else:
self.inicio()

def reset(self):
self.pantalla.activaCapturas(False)
Expand Down Expand Up @@ -252,7 +253,7 @@ def juegaAplazada(self, aplazamiento):
elif tipoJuego == kJugPGN:
self.visorPGN("pgn_comandoExterno")
elif tipoJuego == kJugSolo:
self.jugarSolo(fichero=sys.argv[1])
self.jugarSolo(fichero=self.args.chessFile)
elif tipoJuego in (kJugFics, kJugFide):
self.gestor = GestorFideFics.GestorFideFics(self)
self.gestor.selecciona("Fics" if tipoJuego == kJugFics else "Fide")
Expand Down
49 changes: 47 additions & 2 deletions Code/QT/QTVarios.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import base64
import codecs
import os
import logging
import re

from PyQt4 import QtCore, QtGui, QtSvg

Expand Down Expand Up @@ -1072,17 +1074,31 @@ def list_irina():
)


#def baseDB(siFEN):
# if siFEN:
# base = configuracion.ficheroDBgamesFEN
# else:
# base = configuracion.ficheroDBgames
# base = os.path.abspath(base)
# return base


def listaDB(configuracion, siFEN):
if siFEN:
ext = "lcf"
base = configuracion.ficheroDBgamesFEN
else:
ext = "lcg"
base = configuracion.ficheroDBgames
base = os.path.abspath(base)

logging.info('Base database: %s', base)
basepath = os.path.abspath(base)
logging.info('Base full path: %s', basepath)

lista = [fich for fich in os.listdir(configuracion.carpeta)
if fich.endswith("." + ext) and os.path.abspath(os.path.join(configuracion.carpeta, fich)) != base
if fich.endswith("." + ext) and os.path.abspath(os.path.join(configuracion.carpeta, fich)) != basepath
]

return lista

# menu = LCMenu(owner)
Expand Down Expand Up @@ -1128,6 +1144,13 @@ def createDB(owner, configuracion, siFEN):

def selectDB(owner, configuracion, siFEN):
lista = listaDB(configuracion, siFEN)
if siFEN:
base = configuracion.ficheroDBgamesFEN
else:
base = configuracion.ficheroDBgames

if True:
return base
if not lista:
return None
menu = LCMenu(owner)
Expand All @@ -1137,3 +1160,25 @@ def selectDB(owner, configuracion, siFEN):
menu.separador()
return menu.lanza()

def crearDBMenu(menuDB, dbAction, configuracion, siFEN):
if siFEN:
base = configuracion.ficheroDBgamesFEN
else:
base = configuracion.ficheroDBgames

rp = rondoPuntos()

logging.info('Base database: %s', base)

baseNom = re.search(r'.*/(.*).lc.', base).group(1)
menuDB.opcion(dbAction + ":" + base, baseNom, rp.otro())

lista = listaDB(configuracion, siFEN)
if lista:
menuDB.separador()
for fich in lista:
fich = os.path.join(configuracion.carpeta, fich)
fichNom = re.search(r'.*/(.*).lc.', fich).group(1)
menuDB.opcion(dbAction + ":" + fich, fichNom, rp.otro())

return
5 changes: 4 additions & 1 deletion Code/QT/WBG_Games.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from Code.QT import PantallaAnalisisParam
from Code.QT import PantallaPlayPGN

import logging


class WGames(QtGui.QWidget):
def __init__(self, procesador, winBookGuide, dbGames, wsummary, siMoves=True):
Expand Down Expand Up @@ -64,7 +66,7 @@ def __init__(self, procesador, winBookGuide, dbGames, wsummary, siMoves=True):
# ToolBar
liAccionesWork = [
(_("Close"), Iconos.MainMenu(), self.tw_terminar), None,
(_("File"), Iconos.File(), self.tg_file), None,
(_("Database"), Iconos.DatabaseC(), self.tg_file), None,
(_("New"), Iconos.Nuevo(), self.tw_nuevo, _("Add a new game")), None,
(_("Edit"), Iconos.Modificar(), self.tw_editar), None,
(_("First"), Iconos.Inicio(), self.tw_gotop), None,
Expand Down Expand Up @@ -393,6 +395,7 @@ def tg_file(self):
menu.separador()

resp = menu.lanza()
logging.info('Selected operation: %s', resp)
if resp:
if type(resp) == str:
self.changeDBgames(resp)
Expand Down
2 changes: 1 addition & 1 deletion Code/QT/WBG_GamesFEN.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def tg_file(self):
menu = QTVarios.LCMenu(self)

lista = QTVarios.listaDB(self.configuracion, True)

if lista:
smenu = menu.submenu( _("Open another database"), Iconos.DatabaseC())
rp = QTVarios.rondoPuntos()
Expand Down Expand Up @@ -522,4 +523,3 @@ def changeDBgames(self, pathFich):
self.setNameToolBar()
self.limpiaColumnas()
self.actualiza(True)

Empty file modified LCEngine/irina/xmk_linux.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion LCEngine/xcython_linux.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ x=$(pwd)
export LIBRARY_PATH=$x
export LD_LIBRARY_PATH=$x
export PATH=$x:$PATH
python ./setup.py build_ext --inplace --verbose
python2 ./setup.py build_ext --inplace --verbose


if uname -m | grep 64
Expand Down
9 changes: 4 additions & 5 deletions Linux/LinuxInstallation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ Linux installation from sources
- sudo pip install Cython


3) chmod -R 777 * at top-level project directory, (to ensure all engines have exec-permissions)
3) chmod +x -R Engines/Linux64/ - to ensure all engines have exec-permissions

) 64 bits
4) 64 bits
- cd LCEngine/irina
- ./xmk_linux.sh
-


- cd .. #LXEngine
- ./xcython_linux.sh


Tested in Mate 14.04
Expand Down
Loading