예제 #1
0
    def __findRundata(self, engine):
        """ Searches for a readable, executable named 'name' in the PATH.
            For the PyChess engine, special handling is taken, and we search
            PYTHONPATH as well as the directory from where the 'os' module is
            imported """
        if engine.get("vm_name") is not None:
            altpath = engine.get("vm_command")
            if getattr(sys, 'frozen', False) and engine["vm_name"] == "wine":
                vmpath = None
            else:
                vmpath = searchPath(engine["vm_name"],
                                    access=os.R_OK | os.X_OK,
                                    altpath=altpath)

            if engine["name"] == "PyChess.py" and not getattr(
                    sys, 'frozen', False):
                path = join(abspath(dirname(__file__)), "PyChess.py")
                if not vmpath.endswith(PYTHONBIN):
                    # from python to python3
                    engine["vm_name"] = PYTHONBIN
                    vmpath = searchPath(PYTHONBIN,
                                        access=os.R_OK | os.X_OK,
                                        altpath=None)
                if not os.access(path, os.R_OK):
                    path = None
            else:
                altpath = engine.get("command")
                path = searchPath(engine["name"],
                                  access=os.R_OK,
                                  altpath=altpath)

            if vmpath and path:
                return vmpath, path
            elif path and sys.platform == "win32" and engine.get(
                    "vm_name") == "wine":
                return None, path

        else:
            altpath = engine.get("command")
            if sys.platform == "win32" and not altpath:
                altpath = os.path.join(getDataPrefix(), "engines",
                                       engine["name"])
            path = searchPath(engine["name"],
                              access=os.R_OK | os.X_OK,
                              altpath=altpath)
            if path:
                return None, path
        return False
예제 #2
0
파일: ping.py 프로젝트: sshivaji/pychess
 def start(self):
     assert not self.subproc
     if sys.platform == "win32":
         args = ["-t", self.host]
     else:
         args = ["-i10", self.host]
     self.subproc = SubProcess(searchPath("ping"), args, env={"LANG": "en"})
     self.conid1 = self.subproc.connect("line", self.__handleLines)
     self.conid2 = self.subproc.connect("died", self.__handleDead)
예제 #3
0
    def start(self, host, port, connected_event, timeseal=True):
        if self.canceled:
            raise CanceledException()
        self.port = port
        self.host = host
        self.connected_event = connected_event
        self.timeseal = timeseal

        self.name = host

        if host == "chessclub.com":
            self.ICC = True
            self.timeseal = False

            # You can get ICC timestamp from
            # https://www.chessclub.com/user/resources/icc/timestamp/
            if sys.platform == "win32":
                timestamp = "timestamp_win32.exe"
            else:
                timestamp = "timestamp_linux_2.6.8"

            altpath = os.path.join(getEngineDataPrefix(), timestamp)
            path = searchPath(timestamp, os.X_OK, altpath=altpath)
            if path:
                self.host = "127.0.0.1"
                self.port = 5500
                try:
                    self.timestamp_proc = subprocess.Popen(
                        ["%s" % path, "-p",
                         "%s" % self.port])
                    log.info("%s started OK" % path)
                except OSError as err:
                    log.info("Can't start %s OSError: %s %s" %
                             (err.errno, err.strerror, path))
                    self.port = port
                    self.host = host
            else:
                log.info("%s not found" % altpath)

        def cb(reader, writer):
            reader.stream_writer = writer
            reader.connected_event.set()

        loop = asyncio.get_event_loop()
        self.reader = ICSStreamReader(_DEFAULT_LIMIT, loop,
                                      self.connected_event, self.name)
        self.protocol = ICSStreamReaderProtocol(self.reader, cb, loop,
                                                self.name, self.timeseal)
        coro = loop.create_connection(lambda: self.protocol, self.host,
                                      self.port)
        self.transport, _protocol = yield from coro
        # writer = asyncio.StreamWriter(transport, protocol, reader, loop)

        if self.timeseal:
            self.write(self.get_init_string())
예제 #4
0
        def add(button):
            self.add = True
            response = engine_chooser_dialog.run()

            if response == Gtk.ResponseType.OK:
                new_engine = engine_chooser_dialog.get_filename()
                vm_name = None
                vm_args = None
                vmpath = ""
                if new_engine.lower().endswith(".exe") and sys.platform != "win32":
                    vm_name = "wine"
                    vmpath = searchPath(vm_name, access=os.R_OK | os.X_OK)
                    if vmpath is None:
                        msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR,
                                                    buttons=Gtk.ButtonsType.OK)
                        msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" %
                                             new_engine))
                        msg_dia.format_secondary_text(_("wine not installed"))
                        msg_dia.run()
                        msg_dia.hide()
                        new_engine = ""

                for vm in VM_LIST:
                    ext = os.path.splitext(new_engine)[1]
                    if ext == vm.ext:
                        vm_name = vm.name
                        vm_args = vm.args
                        vmpath = searchPath(vm_name, access=os.R_OK | os.X_OK)
                        if vmpath is None:
                            msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR,
                                                        buttons=Gtk.ButtonsType.OK)
                            msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" %
                                                 new_engine))
                            msg_dia.format_secondary_text(vm_name + _(" is not installed"))
                            msg_dia.run()
                            msg_dia.hide()
                            new_engine = ""
                        break

                if new_engine:
                    vm_ext_list = [vm.ext for vm in VM_LIST]
                    if ext not in vm_ext_list and not os.access(new_engine, os.X_OK):
                        msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR,
                                                    buttons=Gtk.ButtonsType.OK)
                        msg_dia.set_markup(_("<big><b>%s is not marked executable in the filesystem</b></big>" %
                                             new_engine))
                        msg_dia.format_secondary_text(_("Try chmod a+x %s" % new_engine))
                        msg_dia.run()
                        msg_dia.hide()
                        self.add = False
                        engine_chooser_dialog.hide()
                        return

                    try:
                        engine_command = []
                        if vmpath:
                            engine_command.append(vmpath)
                        if vm_args is not None:
                            engine_command.append(vm_args)
                        engine_command.append(new_engine)
                        # Some engines support CECP and UCI, but main variant engines are CECP,
                        # so we better to start with CECP this case
                        variant_engines = ("fmax", "sjaakii", "sjeng")
                        if any((True
                                for eng in variant_engines
                                if eng in new_engine.lower())):
                            checkers = [is_cecp, is_uci]
                        else:
                            checkers = [is_uci, is_cecp]

                        uci = False
                        for checker in checkers:
                            check_ok = checker(engine_command)
                            if check_ok:
                                uci = checker is is_uci
                                break
                            else:
                                continue
                            if not check_ok:
                                # restore the original
                                engine = discoverer.getEngineByName(
                                    self.cur_engine)
                                engine_chooser_dialog.set_filename(engine[
                                    "command"])
                                msg_dia = Gtk.MessageDialog(
                                    type=Gtk.MessageType.ERROR,
                                    buttons=Gtk.ButtonsType.OK)
                                msg_dia.set_markup(
                                    _("<big><b>Unable to add %s</b></big>" %
                                      new_engine))
                                msg_dia.format_secondary_text(_(
                                    "There is something wrong with this executable"))
                                msg_dia.run()
                                msg_dia.hide()
                                engine_chooser_dialog.hide()
                                self.add = False
                                engine_chooser_dialog.hide()
                                return

                        binname = os.path.split(new_engine)[1]
                        for eng in discoverer.getEngines():
                            if eng["name"] == binname:
                                binname = eng["name"] + "(1)"
                                break

                        self.widgets["engine_command_entry"].set_text(new_engine)
                        self.widgets["engine_protocol_combo"].set_active(0 if uci else 1)
                        self.widgets["engine_args_entry"].set_text("")

                        # active = self.widgets["engine_protocol_combo"].get_active()
                        protocol = "uci" if uci else "xboard"

                        if vm_args is not None:
                            vm_args = vm_args.split(",")
                        # print(binname, new_engine, protocol, vm_name, vm_args)
                        discoverer.addEngine(binname, new_engine, protocol, vm_name, vm_args)
                        self.cur_engine = binname
                        self.add = False
                        discoverer.discover()
                    except:
                        msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR,
                                                    buttons=Gtk.ButtonsType.OK)
                        msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" %
                                             new_engine))
                        msg_dia.format_secondary_text(_(
                            "There is something wrong with this executable"))
                        msg_dia.run()
                        msg_dia.hide()
                        self.add = False
                        engine_chooser_dialog.hide()
                        return
                else:
                    # restore the original
                    engine = discoverer.getEngineByName(self.cur_engine)
                    engine_chooser_dialog.set_filename(engine["command"])

            engine_chooser_dialog.hide()
예제 #5
0
}

pgn2Const = {
    "*": RUNNING,
    "?": RUNNING,
    "1/2-1/2": DRAW,
    "1/2": DRAW,
    "1-0": WHITEWON,
    "0-1": BLACKWON
}

this_dir = os.path.dirname(os.path.abspath(__file__))
external = os.path.join(this_dir, "..", "external")
executable = "pgnextractor.exe" if sys.platform == "win32" else "pgnextractor"
pgnextractor = searchPath(executable,
                          access=os.X_OK,
                          altpath=os.path.join(external, executable))


def download_file(url, progressbar=None):
    temp_file = None
    try:
        if progressbar is not None:
            GLib.idle_add(progressbar.set_text, "Downloading %s ..." % url)
        else:
            print("Downloading %s ..." % url)
        f = urlopen(url)

        temp_file = os.path.join(tempfile.gettempdir(), os.path.basename(url))
        with open(temp_file, "wb") as local_file:
            local_file.write(f.read())
예제 #6
0
파일: pgn.py 프로젝트: sshivaji/pychess
        else:
            mvcount = ""
    return mvcount


def load(handle, progressbar=None):
    return PGNFile(handle, progressbar)


this_dir = os.path.dirname(os.path.abspath(__file__))
external = os.path.join(this_dir, "..", "external")

if use_scoutfish:
    executable = "scoutfish.exe" if sys.platform == "win32" else "scoutfish"
    scoutfish_path = searchPath(executable,
                                access=os.X_OK,
                                altpath=os.path.join(external, executable))
else:
    scoutfish_path = None

if use_chess_db:
    executable = "parser.exe" if sys.platform == "win32" else "parser"
    chess_db_path = searchPath(executable,
                               access=os.X_OK,
                               altpath=os.path.join(external, executable))
else:
    chess_db_path = None


class PGNFile(ChessFile):
    def __init__(self, handle, progressbar):
예제 #7
0
                mvcount = ""
        else:
            mvcount = ""
    return mvcount


def load(handle, progressbar=None):
    return PGNFile(handle, progressbar)


BITNESS = "64" if platform.machine().endswith('64') else "32"
EXT = ".exe" if sys.platform == "win32" else ""

scoutfish = "scoutfish_x%s%s" % (BITNESS, EXT)
altpath = os.path.join(getEngineDataPrefix(), scoutfish)
scoutfish_path = searchPath(scoutfish, access=os.X_OK, altpath=altpath)
if scoutfish_path is None:
    binary = "https://github.com/gbtami/scoutfish/releases/download/20170627/%s" % scoutfish
    filename = download_file(binary)
    if filename is not None:
        dest = shutil.move(filename, altpath)
        os.chmod(dest, stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)


parser = "parser_x%s%s" % (BITNESS, EXT)
altpath = os.path.join(getEngineDataPrefix(), parser)
chess_db_path = searchPath(parser, access=os.X_OK, altpath=altpath)
if chess_db_path is None:
    binary = "https://github.com/gbtami/chess_db/releases/download/20170627/%s" % parser
    filename = download_file(binary)
    if filename is not None: