예제 #1
0
    def grabarFichSTAT(self, nomGuide, fich):
        # Para convertir datos de games a bookGuide
        self.changeTo(None, nomGuide)
        f = open(fich, "rb")
        liRegs = []
        for linea in f:
            linea = linea.strip()
            xpv, pv, fen = linea.split("|")
            reg = SQLDBF.Almacen()
            reg.XPV = xpv
            reg.PV = pv
            reg.FEN = fen
            self.ultPos += 1
            reg.POS = self.ultPos

            liRegs.append(reg)

        select = "XPV,PV,FEN,POS"
        dbf = SQLDBF.DBFT(self.conexion, self.tablaDatos, select)

        def dispatch(num):
            pass

        dbf.insertarLista(liRegs, dispatch)
        dbf.cerrar()
예제 #2
0
    def appendFrom(self, wowner, otraGuide):
        self.grabar()

        otroFichero = self.pathGuide(otraGuide)
        otraConexion = sqlite3.connect(otroFichero)
        otraConexion.text_factory = lambda x: unicode(x, "utf-8", "ignore")

        cursor = otraConexion.cursor()
        cursor.execute("pragma table_info(%s)" % self.tablaDatos)
        liCamposOtra = cursor.fetchall()
        cursor.close()
        if not liCamposOtra:
            return False

        st = set()
        for x in liCamposOtra:
            st.add(x[1])  # nombre
        liselect = ("XPV", "PV", "NAG", "ADV", "COMMENT", "FEN", "MARK",
                    "GRAPHICS", "XDATA")
        libasic = ("XPV", "PV", "FEN")
        li = []
        for x in liselect:
            if x not in st:
                if x in libasic:
                    otraConexion.close()
                    QTUtil2.mensError(wowner,
                                      _("This guide file is not valid"))
                    return False
            else:
                li.append(x)
        select = ",".join(li)
        dbfOtra = SQLDBF.DBF(otraConexion, self.tablaDatos, select)
        dbfOtra.leer()
        reccount = dbfOtra.reccount()

        bp = QTUtil2.BarraProgreso(wowner, otraGuide, "", reccount).mostrar()

        liReg = []
        for recno in range(reccount):
            bp.pon(recno)
            if bp.siCancelado():
                break

            dbfOtra.goto(recno)
            reg = dbfOtra.registroActual()
            liReg.append(reg)
        dbfOtra.cerrar()
        otraConexion.close()

        def dispatch(recno):
            bp.pon(recno)

        if liReg:
            dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)
            dbf.insertarLista(liReg, dispatch)
            dbf.cerrar()

        bp.cerrar()

        return len(liReg) > 0
예제 #3
0
        def hazFEN(fen, ply, seq):
            plyN = ply + 1
            siWhite = " w " in fen
            siMax = False
            if whiteBest:
                siMax = siWhite
            if blackBest:
                siMax = siMax or not siWhite

            liPV = book.miraListaPV(fen, siMax)
            for pv in liPV:
                cp.leeFen(fen)
                cp.mover(pv[:2], pv[2:4], pv[4:])
                fenN = cp.fen()
                reg = SQLDBF.Almacen()
                lireg.append(reg)
                reg.PV = pv
                seqN = seq + LCEngine.pv2xpv(pv)
                reg.XPV = seqN
                reg.COMMENT = ""
                reg.NAG = 0
                reg.FEN = fenN
                reg.ADV = 0
                self.ultPos += 1
                reg.POS = self.ultPos
                tmpBP2.ponTotal(1, self.ultPos - basePos)
                tmpBP2.pon(1, self.ultPos - basePos)
                if plyN < depth:
                    fenM2 = cp.fenM2()
                    if fenM2 not in stFenM2:
                        stFenM2.add(fenM2)
                        hazFEN(fenN, plyN, seqN)
예제 #4
0
 def addMoves(moves, depth, seq):
     for mv in moves.liMoves:
         if depth > maxDepth:
             break
         seqM1 = seq
         pv = mv.pv
         seq += LCEngine.pv2xpv(pv)
         reg = SQLDBF.Almacen()
         reg.PV = pv
         reg.XPV = seq
         reg.COMMENT = "\n".join(mv.comentarios)
         reg.FEN = mv.fen
         reg.NAG = 0
         reg.ADV = 0
         self.ultPos += 1
         reg.POS = self.ultPos
         for critica in mv.criticas:
             if critica.isdigit():
                 t = int(critica)
                 if t in (4, 2, 1, 3, 5, 6):
                     reg.NAG = t
                 elif t in (11, 14, 15, 16, 17, 18, 19):
                     reg.ADV = t
             else:
                 if critica in dnag:
                     reg.NAG = dnag[critica]
         liReg.append(reg)
         if mv.variantes:
             for variante in mv.variantes:
                 addMoves(variante, depth, seqM1)
         depth += 1
예제 #5
0
파일: Base.py 프로젝트: xaizek/lucaschessR
    def dbfT(self, ctabla, select, condicion="", orden=""):
        """
        Acceso a una tabla con un navegador tipo DBF, con lectura completa de todos los datos.

        @param ctabla: name de la tabla
        @param select: lista de campos separados por comas
        @param condicion: sentencia de condicion SQL
        @param orden: sentencia de orden SQL
        """
        return DBF.DBFT(self.conexion, ctabla, select, condicion, orden)
예제 #6
0
 def readEXT(self, move):
     select = "COMMENT,GRAPHICS,XDATA"
     condicion = "XPV='%s'" % move.xpv()
     dbf = SQLDBF.DBFT(self.conexion, self.tablaDatos, select, condicion)
     dbf.leer()
     if dbf.reccount():
         dbf.goto(0)
         move.comment(dbf.COMMENT, True)
         move.graphics(dbf.GRAPHICS, True)
         move.xdata(Util.blob2var(dbf.XDATA), True)
     dbf.cerrar()
예제 #7
0
    def readAllDB(self):
        self.transpositions = {}
        self.bookmarks = []
        self.ultPos = 0
        select = "ROWID,XPV,PV,NAG,ADV,FEN,MARK,POS"
        orden = "XPV"
        condicion = ""
        dbf = SQLDBF.DBFT(self.conexion, self.tablaDatos, select, condicion,
                          orden)
        dbf.leer()

        dicMoves = {}
        dicMoves[""] = self.root
        for recno in range(dbf.reccount()):
            dbf.goto(recno)
            xpv = dbf.XPV
            pv = dbf.PV
            if not pv:
                self.root.rowid(dbf.ROWID)
                continue
            xpvfather = xpv[:-2 if len(pv) == 4 else -3]
            if xpvfather in dicMoves:
                father = dicMoves[xpvfather]
                mv = UnMove(self, father)
                mv.pv(pv)
                mv.xpv(xpv)
                mv.fen(dbf.FEN)
                mv.rowid(dbf.ROWID)
                mv.nag(dbf.NAG, True)
                mv.adv(dbf.ADV, True)
                mark = dbf.MARK
                if mark:
                    self.bookmarks.append(mv)
                mv.mark(dbf.MARK, True)
                mv.pos(dbf.POS, True)
                if dbf.POS >= self.ultPos:
                    self.ultPos = dbf.POS
                dicMoves[xpv] = mv
                father.addChildren(mv)

        dbf.cerrar()
예제 #8
0
    def borrar(self, uno):

        liBorrados = [uno]

        def allChildren(li, uno):
            for x in uno.children():
                li.append(x.rowid())
                liBorrados.append(x)
                allChildren(li, x)

        liRowid = []
        if uno.rowid():
            liRowid.append(uno.rowid())
        allChildren(liRowid, uno)
        if liRowid:
            dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, "")
            dbf.borrarListaRaw(liRowid)
            if len(liRowid) > 10:
                dbf.pack()
            dbf.cerrar()

        liQuitarTrasposition = []
        for mov in liBorrados:
            if mov in self.bookmarks:
                del self.bookmarks[self.bookmarks.index(mov)]
            fenM2 = mov.fenM2()
            li = self.transpositions[fenM2]
            if len(li) <= 1:
                del self.transpositions[fenM2]
            else:
                del li[li.index(mov)]
                if len(li) == 1:
                    xm = li[0]
                    if xm not in liBorrados:
                        liQuitarTrasposition.append(xm)

        return liBorrados, liQuitarTrasposition
예제 #9
0
    def grabarPolyglot(self, ventana, ficheroBIN, depth, whiteBest, blackBest):

        titulo = _("Import a polyglot book")
        tmpBP2 = QTUtil2.BarraProgreso2(ventana, titulo)
        tmpBP2.ponTotal(1, 1)
        tmpBP2.ponRotulo(
            1, "1. " + _X(_("Reading %1"), os.path.basename(ficheroBIN)))
        tmpBP2.ponTotal(2, 1)
        tmpBP2.ponRotulo(2, "")
        tmpBP2.mostrar()

        basePos = self.ultPos

        book = Books.Libro("P", ficheroBIN, ficheroBIN, True)
        book.polyglot()
        cp = ControlPosicion.ControlPosicion()

        lireg = []
        stFenM2 = set()  # para que no se produzca un circulo vicioso

        def hazFEN(fen, ply, seq):
            plyN = ply + 1
            siWhite = " w " in fen
            siMax = False
            if whiteBest:
                siMax = siWhite
            if blackBest:
                siMax = siMax or not siWhite

            liPV = book.miraListaPV(fen, siMax)
            for pv in liPV:
                cp.leeFen(fen)
                cp.mover(pv[:2], pv[2:4], pv[4:])
                fenN = cp.fen()
                reg = SQLDBF.Almacen()
                lireg.append(reg)
                reg.PV = pv
                seqN = seq + LCEngine.pv2xpv(pv)
                reg.XPV = seqN
                reg.COMMENT = ""
                reg.NAG = 0
                reg.FEN = fenN
                reg.ADV = 0
                self.ultPos += 1
                reg.POS = self.ultPos
                tmpBP2.ponTotal(1, self.ultPos - basePos)
                tmpBP2.pon(1, self.ultPos - basePos)
                if plyN < depth:
                    fenM2 = cp.fenM2()
                    if fenM2 not in stFenM2:
                        stFenM2.add(fenM2)
                        hazFEN(fenN, plyN, seqN)

        hazFEN(ControlPosicion.FEN_INICIAL, 0, "")
        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)
        tmpBP2.ponTotal(2, len(lireg))
        tmpBP2.ponRotulo(2, _("Writing..."))

        def dispatch(num):
            tmpBP2.pon(2, num)

        dbf.insertarLista(lireg, dispatch)

        dbf.cerrar()
        tmpBP2.cerrar()

        return len(lireg) > 0
예제 #10
0
    def grabarPGN(self, ventana, ficheroPGN, maxDepth):

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        SQLDBF.DBF(self.conexion, self.tablaDatos, select)

        erroneos = duplicados = importados = 0
        dlTmp = QTVarios.ImportarFicheroPGN(ventana)
        dlTmp.hideDuplicados()
        dlTmp.show()

        select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS"
        dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)
        dnag = {"!!": 3, "!": 1, "?": 2, "??": 4, "!?": 5, "?!": 6}

        for n, g in enumerate(PGNreader.readGames(ficheroPGN)):

            if not dlTmp.actualiza(n + 1, erroneos, duplicados, importados):
                break
            if g.erroneo:
                erroneos += 1
                continue
            if not g.moves:
                erroneos += 1
                continue

            liReg = []

            def addMoves(moves, depth, seq):
                for mv in moves.liMoves:
                    if depth > maxDepth:
                        break
                    seqM1 = seq
                    pv = mv.pv
                    seq += LCEngine.pv2xpv(pv)
                    reg = SQLDBF.Almacen()
                    reg.PV = pv
                    reg.XPV = seq
                    reg.COMMENT = "\n".join(mv.comentarios)
                    reg.FEN = mv.fen
                    reg.NAG = 0
                    reg.ADV = 0
                    self.ultPos += 1
                    reg.POS = self.ultPos
                    for critica in mv.criticas:
                        if critica.isdigit():
                            t = int(critica)
                            if t in (4, 2, 1, 3, 5, 6):
                                reg.NAG = t
                            elif t in (11, 14, 15, 16, 17, 18, 19):
                                reg.ADV = t
                        else:
                            if critica in dnag:
                                reg.NAG = dnag[critica]
                    liReg.append(reg)
                    if mv.variantes:
                        for variante in mv.variantes:
                            addMoves(variante, depth, seqM1)
                    depth += 1

            addMoves(g.moves, 1, "")
            if liReg:
                dbf.insertarLista(liReg, None)

        dbf.cerrar()
        dlTmp.actualiza(n, erroneos, duplicados, importados)
        dlTmp.ponContinuar()

        return len(liReg) > 0
예제 #11
0
    def generarStandard(self, ventana, siBasic):

        oLista = AperturasStd.ListaAperturasStd(self.configuracion, True, True)
        dic = oLista.dic

        titulo = _("Openings")
        tmpBP2 = QTUtil2.BarraProgreso2(ventana, titulo)
        tf = len(dic)
        tmpBP2.ponTotal(1, tf)
        tmpBP2.ponRotulo(1, "1. " + _X(_("Reading %1"), titulo))
        tmpBP2.ponTotal(2, tf)
        tmpBP2.ponRotulo(2, "")
        tmpBP2.mostrar()

        liRegs = []
        dRegs = {}  # se guarda una lista con los pv, para determinar el padre
        for nR, k in enumerate(oLista.dic):
            tmpBP2.pon(1, nR)
            tmpBP2.siCancelado()
            ae = oLista.dic[k]
            if siBasic and not ae.siBasic:
                continue
            liPV = ae.a1h8.split(" ")

            ult = len(liPV) - 1
            seqFather = ""
            cp = ControlPosicion.ControlPosicion()
            cp.posInicial()
            for pos, pv in enumerate(liPV):
                desde, hasta, coronacion = pv[:2], pv[2:4], pv[4:]
                seq = seqFather + LCEngine.pv2xpv(pv)
                cp.mover(desde, hasta, coronacion)

                if seq not in dRegs:
                    reg = SQLDBF.Almacen()
                    reg.XPV = seq
                    reg.PV = pv
                    reg.FEN = cp.fen()
                    reg.COMMENT = ae.trNombre if pos == ult else ""
                    self.ultPos += 1
                    reg.POS = self.ultPos

                    liRegs.append(reg)
                    dRegs[seq] = reg

                seqFather = seq

        tmpBP2.ponRotulo(2, "2. " + _X(_("Converting %1"), titulo))
        tmpBP2.ponTotal(2, len(liRegs))

        select = "XPV,PV,COMMENT,FEN,POS"
        dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select)

        def dispatch(num):
            tmpBP2.pon(2, num)
            tmpBP2.siCancelado()

        dbf.insertarLista(liRegs, dispatch)
        dbf.cerrar()

        tmpBP2.cerrar()