annotate main.py @ 176:67d3f629658f

Removed code to initialize pychan from PARPGApplication as that is already done in Application Base.
author Beliar <KarstenBock@gmx.net>
date Mon, 05 Mar 2012 20:17:34 +0100
parents 94196a3e9c07
children c41299c7e833
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
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
17
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
18 def main(parser):
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
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
20 opts, args = parser.parse_args()
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
21
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
22 levels = {'debug': logging.DEBUG,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
23 'info': logging.INFO,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
24 'warning': logging.WARNING,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
25 'error': logging.ERROR,
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
26 'critical': logging.CRITICAL}
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
27
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
28 #TODO: setup formating
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
29 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
30 logger = logging.getLogger('parpg')
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
31
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
32 try:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
33 old_path = sys.path
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
34 if opts.fife_path:
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
35 sys.path = [opts.fife_path]
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
36 import fife
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
37 except ImportError:
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
38 logger.critical("Could not import fife module. Please install fife or set the --fife-path command line value")
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
39 parser.print_help()
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
40 sys.exit(1)
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
41 finally:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
42 sys.path = old_path
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
43
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
44
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
45 from fife.extensions.fife_settings import Setting
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
46
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
47 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
48
175
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
49 settings.set("parpg","DataPath", abspath(settings.get("parpg","DataPath")))
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
50
94196a3e9c07 Added command line option to manually set a fife path.
Beliar <KarstenBock@gmx.net>
parents: 172
diff changeset
51
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
52 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
53 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
54
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
55 # 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
56 try:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
57 import psyco
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
58 psyco_available = True
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
59 except ImportError:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
60 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
61 psyco_available = False
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
62
167
b3b82c2aebee Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents: 149
diff changeset
63 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
64 if psyco_available:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
65 psyco.full()
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
66 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
67 else:
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
68 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
69 'Psyco Acceleration disabled')
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 else:
149
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
71 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
72
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
73 # run the game
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
74 app = PARPGApplication(settings)
86656563555e Created parpg.py and moved code from parpg\main.py to it.
KarstenBock@gmx.net
parents: 3
diff changeset
75 app.run()