3 # ###################################################
4 # Copyright (C) 2008 The OpenAnno Team
6 # This file is part of OpenAnno.
8 # OpenAnno is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 # ###################################################
24 """This is the OpenAnno launcher, it looks for fife and tries to start the game. If you want to digg
25 into the game, continue to game/main.py. Read all docstrings and get familiar with the functions and
26 attributes. I will mark all tutorial instructions with 'TUTORIAL:'. Have fun :-)"""
31 # check if fife is already in python-path
41 _paths
= [config
.fife_path
]
42 except (ImportError, AttributeError):
44 _paths
+= [ a
+ '/' + b
+ '/' + c
for a
in ('.', '..', '../..') for b
in ('.', 'fife', 'FIFE', 'Fife') for c
in ('.', 'trunk') ]
49 # check if we are in a fife dir...
50 for pe
in [ os
.path
.abspath(p
+ '/' + a
) for a
in ('.', 'engine', 'engine/extensions', 'engine/swigwrappers/python') ]:
51 if not os
.path
.exists(pe
):
55 print "Found FIFE in:", fife_path
57 #add python paths (<fife>/engine/extensions <fife>/engine/swigwrappers/python)
58 for pe
in [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('engine/extensions', 'engine/swigwrappers/python') ]:
59 if os
.path
.exists(pe
):
61 os
.environ
['PYTHONPATH'] = os
.path
.pathsep
.join(os
.environ
.get('PYTHONPATH', '').split(os
.path
.pathsep
) + [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('engine/extensions', 'engine/swigwrappers/python') ])
63 #add windows paths (<fife>/.)
64 os
.environ
['PATH'] = os
.path
.pathsep
.join(os
.environ
.get('PATH', '').split(os
.path
.pathsep
) + [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('.') ])
65 os
.path
.defpath
+= os
.path
.pathsep
+ os
.path
.pathsep
.join([ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('.') ])
68 print 'FIFE was not found.'
69 print "Please create a config.py file and add a line with: fife_path = '<path to fife>' eg. fife_path = '../../fife/trunk/'"
73 if not os
.environ
.get('LD_LIBRARY_PATH', '').startswith(os
.path
.abspath(fife_path
)):
76 except ImportError, e
:
77 os
.environ
['LD_LIBRARY_PATH'] = os
.path
.pathsep
.join([ os
.path
.abspath(p
+ '/' + a
) for a
in ('ext/minizip', 'ext/install/lib') ] + (os
.environ
['LD_LIBRARY_PATH'].split(os
.path
.pathsep
) if os
.environ
.has_key('LD_LIBRARY_PATH') else []))
78 print "Restarting with proper LD_LIBRARY_PATH..."
79 args
= [sys
.executable
] + sys
.argv
80 #we are already in openanno root, so just exec local executeable
81 args
[1] = os
.path
.split(os
.path
.realpath(args
[1]))[1]
82 # support for python -O flag (disables __debug__)
85 os
.execvp(args
[0], args
)
88 except ImportError, e
:
89 print 'FIFE was not found or failed to load.'
90 print 'Reason: ' + e
.message
91 print "Please create a config.py file and add a line with: path = '<path to fife>' eg. path = '../../fife/trunk/'"
99 _paths
= [config
.fife_path
]
100 except (ImportError, AttributeError):
102 _paths
+= [ a
+ '/' + b
+ '/' + c
for a
in ('.', '..', '../..') for b
in ('.', 'fife', 'FIFE', 'Fife') for c
in ('.', 'trunk') ]
106 if p
not in sys
.path
:
107 # check if we are in a fife dir...
108 for pe
in [ os
.path
.abspath(p
+ '/' + a
) for a
in ('.', 'engine', 'engine/extensions', 'engine/swigwrappers/python') ]:
109 if not os
.path
.exists(pe
):
113 print "Found FIFE in:", fife_path
115 #add python paths (<fife>/engine/extensions <fife>/engine/swigwrappers/python)
116 for pe
in [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('engine/extensions', 'engine/swigwrappers/python') ]:
117 if os
.path
.exists(pe
):
119 os
.environ
['PYTHONPATH'] = os
.path
.pathsep
.join(os
.environ
.get('PYTHONPATH', '').split(os
.path
.pathsep
) + [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('engine/extensions', 'engine/swigwrappers/python') ])
121 #add windows paths (<fife>/.)
122 os
.environ
['PATH'] = os
.path
.pathsep
.join(os
.environ
.get('PATH', '').split(os
.path
.pathsep
) + [ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('.') ])
123 os
.path
.defpath
+= os
.path
.pathsep
+ os
.path
.pathsep
.join([ os
.path
.abspath(fife_path
+ '/' + a
) for a
in ('.') ])
126 print 'FIFE was not found.'
127 print "Please create a config.py file and add a line with: fife_path = '<path to fife>' eg. fife_path = '../../fife/trunk/'"
131 if __name__
== '__main__':
132 #chdir to openanno root
133 os
.chdir( os
.path
.split( os
.path
.realpath( sys
.argv
[0]) )[0] )
135 #find fife and setup search paths
138 #for some external libraries distributed with openanno
139 sys
.path
.append('game/ext')