Mercurial > parpg-core
annotate src/parpg/main.py @ 195:fabe303ab74f
Added RunScriptAction class.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 19 Nov 2011 16:00:32 +0100 |
parents | 59c4db30fe05 |
children |
rev | line source |
---|---|
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
1fd2201f5c36
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 |
1fd2201f5c36
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 |
1fd2201f5c36
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 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 # (at your option) any later version. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 |
1fd2201f5c36
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, |
1fd2201f5c36
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 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 |
1fd2201f5c36
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 |
1fd2201f5c36
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/>. |
180
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
14 import logging |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 import sys |
180
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
16 from os.path import abspath |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 |
12
d60f1dab8469
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 |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
19 |
180
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
20 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
21 def main(args, opts): |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
22 settings = Settings(*args) |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
23 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
24 settings.parpg.DataPath = abspath(settings.parpg.DataPath) |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
25 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
26 levels = {'debug': logging.DEBUG, |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
27 'info': logging.INFO, |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
28 'warning': logging.WARNING, |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
29 'error': logging.ERROR, |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
30 'critical': logging.CRITICAL} |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
31 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
32 #TODO: setup formating |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
33 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel]) |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
34 logger = logging.getLogger('parpg') |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
35 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
36 try: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
37 old_path = sys.path |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
38 sys.path = [settings.parpg.FifePath] |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
39 import fife |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
40 except AttributeError: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
41 logger.warning('[parpg] section has no FifePath option') |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
42 except ImportError: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
43 logger.critical("Could not import fife module. Please install fife or add " |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
44 "'FifePath' to the [parpg] section of your settings file") |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
45 sys.exit(1) |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
46 finally: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
47 sys.path = old_path |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
48 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
49 from parpg.application import PARPGApplication |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
50 from parpg.common import utils |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
51 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
52 # enable psyco if available and in settings file |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
53 try: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
54 import psyco |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
55 psyco_available = True |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
56 except ImportError: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
57 logger.warning('Psyco Acceleration unavailable') |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
58 psyco_available = False |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
59 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
60 if settings.fife.UsePsyco: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
61 if psyco_available: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
62 psyco.full() |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
63 logger.info('Psyco Acceleration enabled') |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
64 else: |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
65 logger.warning('Please install psyco before attempting to use it' |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
66 'Psyco Acceleration disabled') |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 else: |
180
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
68 logger.info('Psycho Acceleration disabled') |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
69 |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
70 # run the game |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
71 app = PARPGApplication(settings) |
59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents:
18
diff
changeset
|
72 app.run() |