In the "Games" filter, 27_3draw was showing up as 273draw with the 3 underlined....
[fpdb-dooglus.git] / pyfpdb / fpdb_prerun.py
blobe4ff8a3a4bcbaba2ea31d6e90a2e5c9ce781fe90
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2011, Gimick (bbtgaf@googlemail.com)
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 ########################################################################
20 failure_list = []
21 success_list = []
22 verbose = False
24 global_modules_to_test = ["gobject",
25 "pygtk",
26 "gtk",
27 "pango",
28 "cairo",
29 "matplotlib",
30 "numpy",
31 "pylab",
32 "sqlite3"]
34 windows_modules_to_test = ["win32gui",
35 "win32api",
36 "win32con",
37 "win32process",
38 "win32event",
39 "win32console",
40 "winpaths"]
42 linux_modules_to_test = []
43 mac_modules_to_test = []
44 posix_modules_to_test = []
46 def win_output(message):
48 win = Tk()
49 win.title("FPDB")
50 win.geometry("600x400")
51 listbox = Listbox(win)
52 for item in message:
53 listbox.insert(END,item)
54 listbox.pack(fill=BOTH, expand=YES)
55 win.mainloop()
57 def try_import(modulename):
59 try:
60 module = __import__(modulename)
61 success(module)
62 except:
63 failure( _('File not found')+ ": " +modulename)
64 if modulename in ["cairo", "gobject", "pygtk"]:
65 failure(_("Unable to load PyGTK modules required for GUI. Please install PyCairo, PyGObject, and PyGTK from www.pygtk.org."))
66 if modulename in ["win32console"]:
67 failure (_("We appear to be running in Windows, but the Windows Python Extensions are not loading. Please install the PYWIN32 package from http://sourceforge.net/projects/pywin32/"))
68 return False
70 if modulename == "pygtk":
71 try:
72 module.require('2.0')
73 success("pygtk 2.0")
74 return True
75 except:
76 failure("pygtk 2.0 " + _('File not found'))
77 return False
79 if modulename == "matplotlib":
80 try:
81 module.use('GTK')
82 success("matplotlib/gtk")
83 return False
84 except:
85 failure("matplotlib/gtk")
86 return False
88 return True
90 def success(message):
91 if verbose:
92 print message
93 success_list.append(message)
95 def failure(message):
96 if verbose:
97 print _("Error:"), message
98 failure_list.append(message)
100 #=====================================================================
103 # check for gross failures first, no translation on the first
104 # two messages because L10n not guaranteed to be available
107 from Tkinter import *
109 try:
110 try_import("sys")
111 except:
112 failure("python failure - could not import sys module")
113 win_output(failure_list)
114 sys.exit(1)
116 try:
117 try_import("Charset")
118 except:
119 failure("fpdb must be installed in an English path")
120 win_output(failure_list)
121 sys.exit(1)
123 import sys
124 try:
125 if sys.argv[1] == "-v":
126 verbose = True
127 except:
128 pass
130 import L10n
131 _ = L10n.get_translation()
132 import Configuration
133 config = Configuration.Config()
135 if config.python_version not in("2.6", "2.7"):
136 failure(_("\npython 2.6-2.7 not found, please install python 2.6 or 2.7 for fpdb\n"))
139 # next, check for individual modules existing
142 for i in global_modules_to_test:
143 try_import(i)
144 if config.os_family in ("XP", "Win7"):
145 for i in windows_modules_to_test:
146 try_import(i)
147 elif config.os_family == "Linux":
148 for i in linux_modules_to_test:
149 try_import(i)
150 elif config.os_family == "Mac":
151 for i in mac_modules_to_test:
152 try_import(i)
153 if config.posix:
154 for i in posix_modules_to_test:
155 try_import(i)
158 # finished, work out how to exit
161 if len(failure_list):
162 win_output(failure_list)
164 if config.install_method == "exe":
165 if len(failure_list):
166 sys.exit(1)
167 else:
168 sys.exit(0)
170 if len(failure_list):
171 if config.os_family in ("XP", "Win7"):
172 sys.exit(1)
173 else:
174 sys.exit(failure_list)
176 import os
177 os.chdir(os.path.join(config.fpdb_program_path, u"pyfpdb"))
179 if config.os_family in ("XP", "Win7"):
180 os.execvpe('pythonw.exe', list(('pythonw.exe', 'fpdb.pyw', '-r'))+sys.argv[1:], os.environ)
181 else:
182 os.execvpe('python', list(('python', 'fpdb.pyw', '-r'))+sys.argv[1:], os.environ)
184 ###################
185 # DO NOT INSERT ANY LINES BELOW HERE
186 # os.execvpe above stops transfers control to fpdb.pyw immediately