Changeset 786


Ignore:
Timestamp:
03/06/11 20:33:52 (9 years ago)
Author:
aspidites
Message:

Patch by Aspidites:

  • rewrote run.py:

+ now has a proper commandline interface, which currently takes

a single argument of -s/--settings, which takes a list of
files from which to load settings from

+ removed utils.addPaths lines, since their function wasnt,

obvious. If these are important, it would be trivial to
reintroduce them

+ removed main_is_frozen function since it only existed to assist

with py2exe installs, which is being deprecated in favor of a
properly written installer

+ removed get_main_dir function as it was not even being used
+ removed if name == 'main' idiom since this script is not

meant to be imported. Might be reintroduced if there is a need
for the script to be wrapped by some packagers

  • modified settings.ini:

+ removed trailing slashes from path names
+ added FifePath? to [parpg] section: location of fife module
+ added LogFile? to [parpg] section: name of log file, if specified.

by default, points to parpg.log in current working directory

+ LogLevel?: log level for log file, if specified. Defaults to critical

Location:
branches/active/character_customization/game
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/run.py

    • Property svn:executable deleted
    r765 r786  
    1414#   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    1515 
    16 import os 
    17 import shutil 
    18 import imp 
    1916import sys 
     17import logging 
    2018 
    21 """ Module never used 
    22 #Check if config.py exists. Get 'fife_path' from config 
    23 try: 
    24         import config 
    25         sys.path.append(config.fife_path) 
    26 except: 
    27         pass 
     19from argparse import ArgumentParser 
     20from parpg.settings import Settings 
     21 
     22# setup parser 
     23parser = ArgumentParser(description='PARPG Launcher Script') 
     24parser.add_argument('-s', '--settings', nargs='+', 
     25                    dest='filenames', metavar='filename', 
     26                    default='.', 
     27                    help='One or more files to load settings from') 
     28args = parser.parse_args() 
     29 
     30# initialize settigns 
     31settings = Settings(paths=args.filenames) 
     32 
     33levels = {'debug': logging.DEBUG, 
     34          'info': logging.INFO, 
     35          'warning': logging.WARNING, 
     36          'error': logging.ERROR, 
     37          'critical': logging.CRITICAL} 
     38 
     39log_file = settings.parpg.LogFile or 'parpg.log' 
     40log_level = settings.parpg.LogLevel or 'critical' 
     41logging.basicConfig(filename=log_file, level=levels[log_level]) 
     42 
     43if settings.parpg.FifePath is not None: 
     44    sys.path.insert(0, settings.parpg.FifePath) 
    2845 
    2946try: 
    30         from fife import fife 
    31         print "Using the FIFE python module found here: ", \ 
    32                 os.path.dirname(fife.__file__) 
     47    from fife import fife 
     48    from parpg.application import PARPGApplication 
     49 
     50    from parpg.common import utils 
    3351except ImportError: 
    34         print "====================================================================== \n\ 
    35 FIFE was not found in path. \n\ 
    36 Try installing FIFE or creating config.py in the PARPG root directory, \n\ 
    37 with a variable pointing to the 'python' subdirectory \n\ 
    38 fife_path='<path_to_your_FIFE>' \n\ 
    39 Example: fife_path='../fife/engine/python/' \n\ 
    40 ======================================================================" 
    41 """ 
     52    #TODO: pay attention to which module actually failed 
     53    logging.critical("Could not import fife module. 'Please install fife or add " 
     54                     "'FifePath' to the [parpg] section of your settings file") 
     55    sys.exit(1) 
    4256 
    43 from parpg.settings import Settings 
    44 from parpg.application import PARPGApplication 
     57# enable psyco if available and in settings file 
     58try: 
     59    import psyco 
     60    psyco_available = True 
     61except ImportError: 
     62    logging.warning('Psyco Acceleration unavailable') 
     63    psyco_available = False 
    4564 
    46 from parpg.common import utils 
     65if settings.fife.UsePsyco: 
     66    if psyco_available: 
     67        psyco.full() 
     68        logging.info('Psyco Acceleration enabled') 
     69    else: 
     70        logging.warning('Please install psyco before attempting to use it' 
     71                        'Psyco Acceleration disabled') 
     72else: 
     73    logging.info('Psycho Acceleration disabled') 
    4774 
    48 # add paths to the swig extensions 
    49 utils.addPaths ('../../engine/swigwrappers/python', '../../engine/extensions') 
    50 utils.addPaths ('./lib', './lib/extensions') 
    51  
    52  
    53 """This folder holds the main meta-data for PARPG. This file should be 
    54    minimal, since folding code into the controller with MVC is usually bad 
    55    All game and logic and data is held held and referenced in  
    56    /parpg/engine.py. All fife stuff goes in /parpg/world.py""" 
    57  
    58 def main_is_frozen(): 
    59     """returns True when running the exe,  
    60     and False when running from a script. """ 
    61     return (hasattr(sys, "frozen") or # new py2exe 
    62             hasattr(sys, "importers") # old py2exe 
    63             or imp.is_frozen("__main__")) # tools/freeze 
    64  
    65 def get_main_dir(): 
    66     """returns the directory name of the script  
    67     or the directory name of the exe""" 
    68     if main_is_frozen(): 
    69         return os.path.dirname(sys.executable) 
    70     return os.path.dirname(sys.argv[0]) 
    71  
    72  
    73 def main(): 
    74     """Application code starts from here""" 
    75     app = PARPGApplication(settings) 
    76     app.run() 
    77  
    78 if __name__ == '__main__': 
    79     #TODO: properly wrap this with option_parser 
    80     if '-c' in sys.argv: 
    81         settings = Settings(paths=sys.argv[sys.argv.index('-c') + 1:]) 
    82     else: 
    83         settings = Settings(paths='.') 
    84  
    85     if settings.fife.UsePsyco: 
    86         # Import Psyco if available 
    87         try: 
    88             import psyco 
    89             psyco.full() 
    90             print "Psyco acceleration in use" 
    91         except ImportError: 
    92             print "Psyco acceleration not used" 
    93     else: 
    94         print "Psyco acceleration not used" 
    95     main() 
     75# run the game 
     76app = PARPGApplication(settings) 
     77app.run() 
  • branches/active/character_customization/game/settings.ini

    r775 r786  
    1515WindowIcon = gui/icons/window_icon.png 
    1616Font = fonts/oldtypewriter.ttf 
    17 FontsDirectory = fonts/ 
     17FontsDirectory = fonts 
    1818FontGlyphs = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"" 
    1919DefaultFontSize = 12 
     
    2828 
    2929[parpg] 
     30LogFile = parpg.log 
     31LogLevel = debug 
    3032Map = Mall 
    3133ObjectDatabaseFile = objects/object_database.yaml 
    3234MapsFile = maps/maps.yaml 
    3335AllAgentsFile = maps/all_agents.yaml 
    34 AgentsDirectory = objects/ 
    35 CursorDirectory = gui/cursors/ 
     36AgentsDirectory = objects 
     37CursorDirectory = gui/cursors 
    3638CursorDefault = gui/cursors/cursor_plain.png 
    3739CursorUp = gui/cursors/cursor_up.png 
     
    3941CursorDown = gui/cursors/cursor_down.png 
    4042CursorLeft = gui/cursors/cursor_left.png 
    41 DialoguesDirectory = dialogue/ 
    42 QuestsDirectory = quests/ 
     43DialoguesDirectory = dialogue 
     44QuestsDirectory = quests 
    4345PCSpeed = 3 
Note: See TracChangeset for help on using the changeset viewer.