Пример #1
0
    def importarPGN(self, owner, gamebase, ficheroPGN, maxDepth, variations):

        dlTmp = QTUtil2.BarraProgreso(owner, _("Import"), _("Working..."),
                                      Util.filesize(ficheroPGN)).mostrar()

        self.saveHistory(_("Import"), _("PGN with variations"),
                         os.path.basename(ficheroPGN))

        cursor = self._conexion.cursor()

        base = gamebase.pv() if gamebase else self.getconfig("BASEPV")

        sql_insert = "INSERT INTO LINES( XPV ) VALUES( ? )"
        sql_update = "UPDATE LINES SET XPV=? WHERE XPV=?"

        for n, (nbytes, game) in enumerate(Game.read_games(ficheroPGN)):
            dlTmp.pon(nbytes)

            li_pv = game.all_pv("", variations)
            for pv in li_pv:
                li = pv.split(" ")[:maxDepth]
                pv = " ".join(li)

                if base and not pv.startswith(base) or base == pv:
                    continue
                xpv = FasterCode.pv_xpv(pv)
                updated = False
                for npos, xpv_ant in enumerate(self.li_xpv):
                    if xpv_ant.startswith(xpv):
                        updated = True
                        break
                    if xpv.startswith(xpv_ant) and xpv > xpv_ant:
                        cursor.execute(sql_update, (xpv, xpv_ant))
                        self.li_xpv[npos] = xpv
                        updated = True
                        break
                if not updated:
                    if len(xpv) > 0:
                        cursor.execute(sql_insert, (xpv, ))
                        self.li_xpv.append(xpv)

            if n % 50:
                self._conexion.commit()

        cursor.close()
        self.li_xpv.sort()
        self._conexion.commit()
        dlTmp.cerrar()
Пример #2
0
    def importarPGN(self, owner, gamebase, ficheroPGN, maxDepth, with_variations, with_comments):

        dlTmp = QTUtil2.BarraProgreso(owner, _("Import"), _("Working..."), Util.filesize(ficheroPGN)).mostrar()

        self.saveHistory(_("Import"), _("PGN with variations"), os.path.basename(ficheroPGN))

        dic_comments = {}

        cursor = self._conexion.cursor()

        base = gamebase.pv() if gamebase else self.getconfig("BASEPV")

        sql_insert = "INSERT INTO LINES( XPV ) VALUES( ? )"
        sql_update = "UPDATE LINES SET XPV=? WHERE XPV=?"

        for n, (nbytes, game) in enumerate(Game.read_games(ficheroPGN)):
            dlTmp.pon(nbytes)

            li_pv = game.all_pv("", with_variations)
            for pv in li_pv:
                li = pv.split(" ")[:maxDepth]
                pv = " ".join(li)

                if base and not pv.startswith(base) or base == pv:
                    continue
                xpv = FasterCode.pv_xpv(pv)
                updated = False
                for npos, xpv_ant in enumerate(self.li_xpv):
                    if xpv_ant.startswith(xpv):
                        updated = True
                        break
                    if xpv.startswith(xpv_ant) and xpv > xpv_ant:
                        cursor.execute(sql_update, (xpv, xpv_ant))
                        self.li_xpv[npos] = xpv
                        updated = True
                        break
                if not updated:
                    if len(xpv) > 0:
                        cursor.execute(sql_insert, (xpv,))
                        self.li_xpv.append(xpv)

            if with_comments:
                dic_comments_game = game.all_comments(with_variations)
                for fenm2, dic in dic_comments_game.items():
                    d = self.getfenvalue(fenm2)
                    if "C" in dic:
                        d["COMENTARIO"] = dic["C"]
                    if "N" in dic:
                        for nag in dic["N"]:
                            if nag in (11, 14, 15, 16, 17, 18, 19):
                                d["VENTAJA"] = nag
                            elif 0 < nag < 7:
                                d["VALORACION"] = nag
                    if d:
                        dic_comments[fenm2] =  d

            if n % 50:
                self._conexion.commit()

        cursor.close()
        self.li_xpv.sort()
        self._conexion.commit()
        dlTmp.cerrar()
        if with_comments and dic_comments:
            self.db_fenvalues.set_faster_mode()
            um = QTUtil2.unMomento(owner)
            for fenm2, dic_comments_game in dic_comments.items():
                self.setfenvalue(fenm2, dic_comments_game)
            self.db_fenvalues.set_normal_mode()
            um.final()