Module run
[hide private]
[frames] | no frames]

Source Code for Module run

 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      sys.path.insert(0, opts.module) 
45   
46  from parpg.settings import Settings 
47   
48  settings = Settings(*args) 
49   
50  levels = {'debug': logging.DEBUG, 
51            'info': logging.INFO, 
52            'warning': logging.WARNING, 
53            'error': logging.ERROR, 
54            'critical': logging.CRITICAL} 
55   
56  #TODO: setup formating 
57  logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel]) 
58  logger = logging.getLogger('parpg') 
59   
60  try: 
61      sys.path.insert(0, settings.parpg.FifePath)  
62  except AttributeError: 
63      logger.warning('[parpg] section has no FifePath option') 
64   
65  try: 
66      from fife import fife 
67  except 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   
72  from parpg.application import PARPGApplication 
73  from parpg.common import utils 
74   
75  # enable psyco if available and in settings file 
76  try: 
77      import psyco 
78      psyco_available = True 
79  except ImportError: 
80      logger.warning('Psyco Acceleration unavailable') 
81      psyco_available = False 
82   
83  if 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') 
90  else: 
91      logger.info('Psycho Acceleration disabled') 
92   
93  # run the game 
94  app = PARPGApplication(settings) 
95  app.run() 
96