source: branches/active/character_customization/game/run.py @ 825

Revision 825, 2.8 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • changed the way the -p option runs to work around optparse limitations
  • now possible to only supply a global config location
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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
16import sys
17import logging
18
19from optparse import OptionParser
20from parpg.settings import Settings
21
22# Python 2.6 or lower
23parser = OptionParser(description='PARPG Launcher Script')
24parser.add_option('-p', '--paths',
25                  default='.',
26                  help='One or more paths to load settings from. If more than '
27                       'one path is given, be sure to surround the value in '
28                       'quotes.')
29parser.add_option('-f', '--logfile',
30                  help='Name of log file to save to')
31parser.add_option('-l', '--loglevel', default='critical',
32                  help='desired output level for log file')
33opts, args = parser.parse_args()
34
35# initialize settings
36paths = opts.paths.split(' ')
37print paths
38settings = Settings(*paths)
39
40levels = {'debug': logging.DEBUG,
41          'info': logging.INFO,
42          'warning': logging.WARNING,
43          'error': logging.ERROR,
44          'critical': logging.CRITICAL}
45
46#TODO: setup formating
47logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
48logger = logging.getLogger('parpg')
49
50try:
51    sys.path.insert(0, settings.parpg.FifePath)
52except AttributeError:
53    logger.warning('[parpg] section has no FifePath option')
54
55try:
56    from fife import fife
57    from parpg.application import PARPGApplication
58
59    from parpg.common import utils
60except ImportError:
61    #TODO: pay attention to which module actually failed
62    logger.critical("Could not import fife module. Please install fife or add "
63                     "'FifePath' to the [parpg] section of your settings file")
64    sys.exit(1)
65
66# enable psyco if available and in settings file
67try:
68    import psyco
69    psyco_available = True
70except ImportError:
71    logger.warning('Psyco Acceleration unavailable')
72    psyco_available = False
73
74if settings.fife.UsePsyco:
75    if psyco_available:
76        psyco.full()
77        logger.info('Psyco Acceleration enabled')
78    else:
79        logger.warning('Please install psyco before attempting to use it'
80                        'Psyco Acceleration disabled')
81else:
82    logger.info('Psycho Acceleration disabled')
83
84# run the game
85app = PARPGApplication(settings)
86app.run()
Note: See TracBrowser for help on using the repository browser.