source: trunk/game/run.py @ 833

Revision 832, 3.1 KB checked in by aspidites, 9 years ago (diff)

Patch by Aspidites: added example invokation

  • 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
20
21usage = ('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
28parser = OptionParser(description='PARPG Launcher Script', usage=usage)
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')
33parser.add_option('-m', '--module',
34                  help='location of the parpg module')
35opts, args = parser.parse_args()
36
37if not args:
38    parser.print_help()
39    sys.exit(1)
40           
41
42# initialize settings
43if opts.module:
44    sys.path.insert(0, opts.module)
45
46from parpg.settings import Settings
47
48settings = Settings(*args)
49
50levels = {'debug': logging.DEBUG,
51          'info': logging.INFO,
52          'warning': logging.WARNING,
53          'error': logging.ERROR,
54          'critical': logging.CRITICAL}
55
56#TODO: setup formating
57logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
58logger = logging.getLogger('parpg')
59
60try:
61    sys.path.insert(0, settings.parpg.FifePath) 
62except AttributeError:
63    logger.warning('[parpg] section has no FifePath option')
64
65try:
66    from fife import fife
67except ImportError:
68    logger.critical("Could not import fife module. Please install fife or add "
69                     "'FifePath' to the [parpg] section of your settings file")
70    sys.exit(1)
71
72from parpg.application import PARPGApplication
73from parpg.common import utils
74
75# enable psyco if available and in settings file
76try:
77    import psyco
78    psyco_available = True
79except ImportError:
80    logger.warning('Psyco Acceleration unavailable')
81    psyco_available = False
82
83if settings.fife.UsePsyco:
84    if psyco_available:
85        psyco.full()
86        logger.info('Psyco Acceleration enabled')
87    else:
88        logger.warning('Please install psyco before attempting to use it'
89                        'Psyco Acceleration disabled')
90else:
91    logger.info('Psycho Acceleration disabled')
92
93# run the game
94app = PARPGApplication(settings)
95app.run()
Note: See TracBrowser for help on using the repository browser.