annotate main.py @ 150:80672955ab70

PARPG now works with, and needs Fife 0.3.3.
author KarstenBock@gmx.net
date Tue, 11 Oct 2011 14:47:37 +0200
parents 86656563555e
children b3b82c2aebee
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
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
18 from parpg.settings import Settings
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):
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
22 settings = Settings(*args)
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
23
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
24 settings.parpg.DataPath = abspath(settings.parpg.DataPath)
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
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
38 sys.path = [settings.parpg.FifePath]
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:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
41 logger.warning('[parpg] section has no FifePath option')
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 "
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
44 "'FifePath' to the [parpg] section of your settings file")
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
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
60 if settings.fife.UsePsyco:
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()