annotate main.py @ 172:5d47ad053aef

Fixed code that was still using the (removed) parpg settings module.
author Beliar <KarstenBock@gmx.net>
date Sun, 26 Feb 2012 01:58:36 +0100
parents b3b82c2aebee
children 94196a3e9c07
rev   line source
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2 # This program is free software: you can redistribute it and/or modify
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # it under the terms of the GNU General Public License as published by
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # (at your option) any later version.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7 # This program is distributed in the hope that it will be useful,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # GNU General Public License for more details.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
14 import logging
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15 import sys
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
16 from os.path import abspath
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17
167
b3b82c2aebee Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents: 149
diff changeset
18 from fife.extensions.fife_settings import Setting
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
19
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
20
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
21 def main(args, opts):
167
b3b82c2aebee Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents: 149
diff changeset
22 settings = Setting(settings_file="settings.xml")
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
23
167
b3b82c2aebee Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents: 149
diff changeset
24 settings.set("parpg","DataPath", abspath(settings.get("parpg","DataPath")))
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
25
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
26 levels = {'debug': logging.DEBUG,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
27 'info': logging.INFO,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
28 'warning': logging.WARNING,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
29 'error': logging.ERROR,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
30 'critical': logging.CRITICAL}
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
31
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
32 #TODO: setup formating
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
33 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
34 logger = logging.getLogger('parpg')
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
35
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
36 try:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
37 old_path = sys.path
172
5d47ad053aef Fixed code that was still using the (removed) parpg settings module.
Beliar <KarstenBock@gmx.net>
parents: 167
diff changeset
38 sys.path = [settings.get("parpg", "FifePath")]
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
39 import fife
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
40 except AttributeError:
172
5d47ad053aef Fixed code that was still using the (removed) parpg settings module.
Beliar <KarstenBock@gmx.net>
parents: 167
diff changeset
41 logger.warning('parpg section has no FifePath option')
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
42 except ImportError:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
43 logger.critical("Could not import fife module. Please install fife or add "
172
5d47ad053aef Fixed code that was still using the (removed) parpg settings module.
Beliar <KarstenBock@gmx.net>
parents: 167
diff changeset
44 "'FifePath' to the parpg section of your settings file")
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
45 sys.exit(1)
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
46 finally:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
47 sys.path = old_path
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
48
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
49 from parpg.application import PARPGApplication
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
50 from parpg.common import utils
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
51
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
52 # enable psyco if available and in settings file
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
53 try:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
54 import psyco
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
55 psyco_available = True
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
56 except ImportError:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
57 logger.warning('Psyco Acceleration unavailable')
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
58 psyco_available = False
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
59
167
b3b82c2aebee Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents: 149
diff changeset
60 if settings.get("fife", "UsePsyco"):
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
61 if psyco_available:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
62 psyco.full()
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
63 logger.info('Psyco Acceleration enabled')
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
64 else:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
65 logger.warning('Please install psyco before attempting to use it'
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
66 'Psyco Acceleration disabled')
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 else:
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
68 logger.info('Psycho Acceleration disabled')
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
69
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
70 # run the game
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
71 app = PARPGApplication(settings)
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
72 app.run()