view main.py @ 1:4912a6f97c52

Various improvements to the build process including support for self-contained builds. * Note that despite all of these changes PARPG still does not run because asset paths are not standardized, * Modified the SCons script so that by default running `scons` with no arguments creates a self-contained "build" under a build subdirectory to make in-source testing easier. To install PARPG, use `scons install` instead. * Got rid of the binary launcher and replaced it with a shell script for unix and a batch script for Windows (batch script is untested). The binary turned out to be too much trouble to maintain. * Modified the parpg.settings module and parpg.main entry script so that PARPG searches through several default search paths for configuration file(s). PARPG thus no longer crashes if it can't find a configuration file in any particular search path, but will crash it if can't find any configuration files. * Paths supplied to parpg.main are now appended as search paths for the configuration file(s). * Changed the default configuration file name to "parpg.cfg" to simplify searches. * Created the site_scons directory tree where SCons extensions and tools should be placed. * Created a new SCons builder, CopyRecurse, which can copy only certain files and folders from a directory tree using filters (files and folders that start with a leading dot "." e.g. ".svn" are ignored by default). * Added the CPython SCons tool (stands for Compile-Python - I didn't name it!), which provides the InstallPython builder for pre-compiling python sources before they are installed. However, it is currently broken and only installs the python sources.
author M. George Hansen <technopolitica@gmail.com>
date Tue, 31 May 2011 02:46:20 -0700
parents 7a89ea5404b1
children 06145a6ee387
line wrap: on
line source

#!/usr/bin/env python2 
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

#TODO: Modularize this script
import sys
import logging

from optparse import OptionParser

usage = ('usage: %prog [options] settings_path [system_path user_path]\n\n'
         'The settings_path argument is mandatory and is the directory in \n'
         'which your system.cfg file is located. Optionally, you may \n'
         'specify where data files are located (system_path), and where \n'
         'the user settings and data files should be saved to (user_path)\n\n'
         'Example: python %prog .')

parser = OptionParser(description='PARPG Launcher Script', usage=usage)
parser.add_option('-f', '--logfile',
                  help='Name of log file to save to')
parser.add_option('-l', '--loglevel', default='critical',
                  help='desired output level for log file')
parser.add_option('-m', '--module',
                  help='location of the parpg module')
opts, args = parser.parse_args()

if not args:
    parser.print_help()
    sys.exit(1)
            

# initialize settings
if opts.module:
    print('added ' + opts.module)
    sys.path.insert(0, opts.module)

from parpg.settings import Settings

settings = Settings(*args)

levels = {'debug': logging.DEBUG,
          'info': logging.INFO,
          'warning': logging.WARNING,
          'error': logging.ERROR,
          'critical': logging.CRITICAL}

#TODO: setup formating
logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
logger = logging.getLogger('parpg')

try:
    sys.path.insert(0, settings.parpg.FifePath) 
except AttributeError:
    logger.warning('[parpg] section has no FifePath option')

try:
    from fife import fife
except ImportError:
    logger.critical("Could not import fife module. Please install fife or add "
                     "'FifePath' to the [parpg] section of your settings file")
    sys.exit(1)

from parpg.application import PARPGApplication
from parpg.common import utils

# enable psyco if available and in settings file
try:
    import psyco
    psyco_available = True
except ImportError:
    logger.warning('Psyco Acceleration unavailable')
    psyco_available = False

if settings.fife.UsePsyco:
    if psyco_available:
        psyco.full()
        logger.info('Psyco Acceleration enabled')
    else:
        logger.warning('Please install psyco before attempting to use it'
                        'Psyco Acceleration disabled')
else:
    logger.info('Psycho Acceleration disabled')

# run the game
app = PARPGApplication(settings)
app.run()