comparison main.py @ 0:7a89ea5404b1

Initial commit of parpg-core.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 14 May 2011 01:12:35 -0700
parents
children 06145a6ee387
comparison
equal deleted inserted replaced
-1:000000000000 0:7a89ea5404b1
1 #!/usr/bin/env python2
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
6
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15 #TODO: Modularize this script
16 import sys
17 import logging
18
19 from optparse import OptionParser
20
21 usage = ('usage: %prog [options] settings_path [system_path user_path]\n\n'
22 'The settings_path argument is mandatory and is the directory in \n'
23 'which your system.cfg file is located. Optionally, you may \n'
24 'specify where data files are located (system_path), and where \n'
25 'the user settings and data files should be saved to (user_path)\n\n'
26 'Example: python %prog .')
27
28 parser = OptionParser(description='PARPG Launcher Script', usage=usage)
29 parser.add_option('-f', '--logfile',
30 help='Name of log file to save to')
31 parser.add_option('-l', '--loglevel', default='critical',
32 help='desired output level for log file')
33 parser.add_option('-m', '--module',
34 help='location of the parpg module')
35 opts, args = parser.parse_args()
36
37 if not args:
38 parser.print_help()
39 sys.exit(1)
40
41
42 # initialize settings
43 if opts.module:
44 print('added ' + opts.module)
45 sys.path.insert(0, opts.module)
46
47 from parpg.settings import Settings
48
49 settings = Settings(*args)
50
51 levels = {'debug': logging.DEBUG,
52 'info': logging.INFO,
53 'warning': logging.WARNING,
54 'error': logging.ERROR,
55 'critical': logging.CRITICAL}
56
57 #TODO: setup formating
58 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
59 logger = logging.getLogger('parpg')
60
61 try:
62 sys.path.insert(0, settings.parpg.FifePath)
63 except AttributeError:
64 logger.warning('[parpg] section has no FifePath option')
65
66 try:
67 from fife import fife
68 except ImportError:
69 logger.critical("Could not import fife module. Please install fife or add "
70 "'FifePath' to the [parpg] section of your settings file")
71 sys.exit(1)
72
73 from parpg.application import PARPGApplication
74 from parpg.common import utils
75
76 # enable psyco if available and in settings file
77 try:
78 import psyco
79 psyco_available = True
80 except ImportError:
81 logger.warning('Psyco Acceleration unavailable')
82 psyco_available = False
83
84 if settings.fife.UsePsyco:
85 if psyco_available:
86 psyco.full()
87 logger.info('Psyco Acceleration enabled')
88 else:
89 logger.warning('Please install psyco before attempting to use it'
90 'Psyco Acceleration disabled')
91 else:
92 logger.info('Psycho Acceleration disabled')
93
94 # run the game
95 app = PARPGApplication(settings)
96 app.run()