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") vmpath = searchPath(engine["vm_name"], access=os.R_OK | os.X_OK, altpath=altpath) if engine["name"] == "PyChess.py": path = join(abspath(dirname(__file__)), "PyChess.py") 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") path = searchPath(engine["name"], access=os.R_OK | os.X_OK, altpath=altpath) if path: return None, path return False
def __findRundata(self, engine): """ Searches for a readable, executable named 'binname' 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.find('vm') is not None: altpath = engine.find('vm').find('path') is not None and \ engine.find('vm').find('path').text.strip() vmpath = searchPath(engine.find('vm').get('binname'), access=os.R_OK | os.X_OK, altpath=altpath) if engine.get('binname') == "PyChess.py": path = join(abspath(dirname(__file__)), "PyChess.py") if not os.access(path, os.R_OK): path = None else: altpath = engine.find('path') is not None and engine.find( 'path').text.strip() path = searchPath(engine.get('binname'), access=os.R_OK, altpath=altpath) if vmpath and path: return vmpath, path else: altpath = engine.find('path') is not None and engine.find( 'path').text.strip() path = searchPath(engine.get('binname'), access=os.R_OK | os.X_OK, altpath=altpath) if path: return None, path return False
def __findRundata (self, engine): """ Searches for a readable, executable named 'binname' 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.find('vm') is not None: altpath = engine.find('vm').find('path') is not None and \ engine.find('vm').find('path').text.strip() vmpath = searchPath(engine.find('vm').get('binname'), access=os.R_OK|os.X_OK, altpath = altpath) if engine.get('binname') == "PyChess.py": path = join(abspath(dirname(__file__)), "PyChess.py") if not os.access(path, os.R_OK): path = None else: altpath = engine.find('path') is not None and engine.find('path').text.strip() path = searchPath(engine.get('binname'), access=os.R_OK, altpath=altpath) if vmpath and path: return vmpath, path else: altpath = engine.find('path') is not None and engine.find('path').text.strip() path = searchPath(engine.get('binname'), access=os.R_OK|os.X_OK, altpath=altpath) if path: return None, path return False
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") vmpath = searchPath(engine["vm_name"], access=os.R_OK|os.X_OK, altpath = altpath) if engine["name"] == "PyChess.py": path = join(abspath(dirname(__file__)), "PyChess.py") 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") path = searchPath(engine["name"], access=os.R_OK|os.X_OK, altpath=altpath) if path: return None, path return False
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)
def start (self): assert not self.subproc self.subproc = SubProcess(searchPath("ping"), ["-i10", self.host], env={"LANG":"en"}) self.conid1 = self.subproc.connect("line", self.__handleLines) self.conid2 = self.subproc.connect("died", self.__handleDead)
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() 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: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("wine not installed")) d.run() d.hide() new_engine = "" else: vmpath += " " else: vm_name = None vmpath = "" if new_engine: try: # Some engines support CECP and UCI, but variant engines are CECP, # so we better to start with CECP this case variant_engines = ("fmax", "sjaakii", "sjeng") if any((True for e in variant_engines if e in new_engine.lower())): checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: ok = checker(vmpath + new_engine) if ok: uci = checker is is_uci break else: continue if not ok: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() engine_chooser_dialog.hide() return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["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" discoverer.addEngine(binname, new_engine, protocol, vm_name) self.cur_engine = binname self.add = False discoverer.discover() except: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() 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 = "" else: vmpath += " " elif new_engine.lower().endswith(".js"): vm_name = "node" 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(_("node.js is not installed")) msg_dia.run() msg_dia.hide() new_engine = "" else: vm_name = None vmpath = "" if new_engine: if not new_engine.lower().endswith(".js") 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: # 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: engine_command = (vmpath, new_engine) if vmpath else new_engine 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" discoverer.addEngine(binname, new_engine, protocol, vm_name) 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()
def start(self): assert not self.subproc self.subproc = SubProcess(searchPath("ping"), [self.host], env={"LANG": "en"}) self.conid1 = self.subproc.connect("line", self.__handleLines) self.conid2 = self.subproc.connect("died", self.__handleDead)
mvcount = "" 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: scoutfish_path = searchPath("scoutfish", access=os.X_OK, altpath=external + "scoutfish") else: scoutfish_path = None if use_chess_db: chess_db_path = searchPath("parser", access=os.X_OK, altpath=external + "parser") else: chess_db_path = None class PGNFile(ChessFile): def __init__(self, handle, progressbar): ChessFile.__init__(self, handle)
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() if new_engine.lower().endswith(".exe"): vm_name = "wine" vmpath = searchPath(vm_name, access=os.R_OK|os.X_OK) if vmpath is None: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("wine not installed")) d.run() d.hide() new_engine = "" else: vmpath += " " else: vm_name = None vmpath = "" if new_engine: try: uci = is_uci(vmpath + new_engine) if not uci: if not is_cecp(vmpath + new_engine): # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() engine_chooser_dialog.hide() return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["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 active==0 else "xboard" discoverer.addEngine(binname, new_engine, protocol, vm_name) self.cur_engine = binname glock_connect_after(discoverer, "engine_discovered", update_store) self.add = False discoverer.discover() except: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
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):
ord(u"-"): None, ord(u" "): None, } 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())
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() 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: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("wine not installed")) d.run() d.hide() new_engine = "" else: vmpath += " " else: vm_name = None vmpath = "" if new_engine: try: uci = is_uci(vmpath + new_engine) if not uci: if not is_cecp(vmpath + new_engine): # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() engine_chooser_dialog.hide() return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["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 active==0 else "xboard" discoverer.addEngine(binname, new_engine, protocol, vm_name) self.cur_engine = binname discoverer.connect_after("engine_discovered", update_store) self.add = False discoverer.discover() except: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()