1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#!/usr/bin/python
# PyChess startup script.
# This script is to check package requirements, and set up system/enviroment
# stuff, to make the PyChess Main class run smoothly.
from __future__ import print_function
import argparse
import os, sys
import gettext, locale
# faulthandler will be in Python 3.3; for 2.x you can download it from pypi
if not getattr(sys, 'frozen', False):
try:
import faulthandler
faulthandler.enable()
except ImportError:
pass
###############################################################################
# Check requirements
if sys.version_info < (2, 7, 0):
print('ERROR: PyChess requires Python >= 2.7')
sys.exit(1)
try:
import cairo
except ImportError:
print("ERROR: PyChess requires python-cairo to be installed.")
sys.exit(1)
try:
import gi
except ImportError:
print("ERROR: PyChess requires pygobject to be installed.")
sys.exit(1)
try:
gi.require_version("cairo", "1.0")
gi.require_version("GLib", "2.0")
gi.require_version("Gdk", "3.0")
gi.require_version("GdkPixbuf", "2.0")
gi.require_version("GObject", "2.0")
gi.require_version("Gtk", "3.0")
gi.require_version("GtkSource", "3.0")
gi.require_version("Pango", "1.0")
gi.require_version("PangoCairo", "1.0")
gi.require_version("Rsvg", "2.0")
except ValueError as e:
print("ERROR: Not all dependencies installed! You can find them in INSTALL")
print(e)
sys.exit(1)
###############################################################################
# Fix environment
if getattr(sys, 'frozen', False):
this_dir = os.path.dirname(sys.executable)
else:
this_dir = os.path.dirname(os.path.abspath(__file__))
if os.path.isdir(os.path.join(this_dir, "lib/pychess")) and \
os.path.join(this_dir, "lib") not in sys.path:
sys.path = [os.path.join(this_dir, "lib")] + sys.path
###############################################################################
# Ensure access to data store
try:
from pychess.System.prefix import addDataPrefix, getDataPrefix, isInstalled
except ImportError:
print("ERROR: Could not import modules.")
print("Please try to run pychess as stated in the INSTALL file")
sys.exit(1)
# now we can import from compat module
from pychess.compat import PY2
if PY2:
# This hack fixes some UnicodDecode Errors caused pygi not making
# magic hidden automatic unicode conversion pygtk did
reload(sys)
sys.setdefaultencoding("utf-8")
###############################################################################
# Parse command line arguments
import pychess
no_debug = False
idle_add_debug = False
no_thread_debug = False
log_viewer = False
chess_file = sys.argv[1] if len(sys.argv) > 1 else None
ics_host = None
ics_port = None
version = "%s (%s)" % (pychess.VERSION, pychess.VERSION_NAME)
description = "The PyChess chess client, version %s." % version
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--version', action='version',
version="%(prog)s" + " %s" % version)
parser.add_argument('--no-debug', action='store_true',
help='turn off debugging output')
parser.add_argument('--idle-add-debug', action='store_true',
help='turn on idle-add debugging output')
parser.add_argument('--thread-debug', action='store_true',
help='turn on thread debugging output')
parser.add_argument('--no-gettext', action='store_true',
help='turn off locale translations')
parser.add_argument('--log-viewer', action='store_true',
help='enable Log Viewer menu')
parser.add_argument('--purge-recent', action='store_true',
help='purge recent games menu')
parser.add_argument('--ics-host', action='store',
help='the hostname of internet chess server (default is freechess.org)')
parser.add_argument('--ics-port', action='store', type=int,
help='the connection port of internet chess server (default is 5000)')
parser.add_argument('chess_file', nargs='?', metavar='chessfile',
help='a chess file in PGN, EPD, FEN, or HTML (Chess Alpha 2 Diagram) format')
args = parser.parse_args()
no_debug = args.no_debug
idle_add_debug = args.idle_add_debug
thread_debug = args.thread_debug
no_gettext = args.no_gettext
log_viewer = args.log_viewer
purge_recent = args.purge_recent
chess_file = args.chess_file
ics_host = args.ics_host
ics_port = args.ics_port
###############################################################################
# Set up translations
from pychess.System import uistuff
uistuff.no_gettext = no_gettext
if no_gettext:
os.environ['LANG'] = "C"
locale.setlocale(locale.LC_ALL, 'C')
else:
locale.setlocale(locale.LC_ALL, '')
# http://stackoverflow.com/questions/3678174/python-gettext-doesnt-load-translations-on-windows
if sys.platform.startswith('win'):
if os.getenv('LANG') is None:
lang, enc = locale.getdefaultlocale()
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
domain = "pychess"
if isInstalled():
if sys.platform == "win32":
locale_dir = os.path.join(os.path.dirname(getDataPrefix()), "locale")
else:
locale_dir = None
else:
locale_dir = addDataPrefix("lang")
if PY2:
gettext.install(domain, localedir=locale_dir, unicode=1, names=('ngettext',))
else:
gettext.install(domain, localedir=locale_dir, names=('ngettext',))
# http://stackoverflow.com/questions/10094335/how-to-bind-a-text-domain-to-a-local-folder-for-gettext-under-gtk3
if sys.platform == "win32":
from ctypes import cdll
libintl = cdll.LoadLibrary("libintl-8")
libintl.bindtextdomain(domain, locale_dir)
libintl.bind_textdomain_codeset(domain, 'UTF-8')
else:
locale.bindtextdomain(domain, locale_dir)
###############################################################################
# Let's rumble!
import pychess.Main
pychess.Main.run(no_debug, idle_add_debug, thread_debug, log_viewer,
purge_recent, chess_file, ics_host, ics_port)
|