Mercurial > parpg-source
annotate main.py @ 2:06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
* PARPG should now run without issue (system installation not tested).
* Utilized FIFE's VFS module to remove path dependencies from most PARPG modules.
* The new parpg.vfs module is a singleton with a single global variable, VFS, which is a reference to the global VFS instance. Although a singleton is not ideal it should be replaced once PARPG's core code is refactored.
* The parpg.vfs singleton is initialized in the parpg.applicaiton.PARPGApplication class with the absolute path to the data directory via the parpg.settings module and corresponding configuration file.
* A new DataPath entry was added to the default system configuration file template under the [parpg] section to support the new parpg.vfs module.
* Updated the parpg-assets subrepo to revision 3 to fix some dialog file format issues (for details see commit message for parpg-assets).
* Fixed a few bugs in the parpg.dialogueparsers.YAMLDialogueParser class related to exception handling.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Mon, 06 Jun 2011 15:56:14 -1000 |
parents | 7a89ea5404b1 |
children | 06be71be07f1 |
rev | line source |
---|---|
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 # (at your option) any later version. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
14 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 #TODO: Modularize this script |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 import sys |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 import logging |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 from optparse import OptionParser |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
21 from parpg.settings import Settings |
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
22 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 usage = ('usage: %prog [options] settings_path [system_path user_path]\n\n' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 'The settings_path argument is mandatory and is the directory in \n' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 'which your system.cfg file is located. Optionally, you may \n' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 'specify where data files are located (system_path), and where \n' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 'the user settings and data files should be saved to (user_path)\n\n' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
28 'Example: python %prog .') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 parser = OptionParser(description='PARPG Launcher Script', usage=usage) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
31 parser.add_option('-f', '--logfile', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 help='Name of log file to save to') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 parser.add_option('-l', '--loglevel', default='critical', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 help='desired output level for log file') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 opts, args = parser.parse_args() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 if not args: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 parser.print_help() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 sys.exit(1) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 settings = Settings(*args) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 levels = {'debug': logging.DEBUG, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 'info': logging.INFO, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 'warning': logging.WARNING, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 'error': logging.ERROR, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 'critical': logging.CRITICAL} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 #TODO: setup formating |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel]) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 logger = logging.getLogger('parpg') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 try: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 sys.path.insert(0, settings.parpg.FifePath) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 except AttributeError: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 logger.warning('[parpg] section has no FifePath option') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 try: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 from fife import fife |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 except ImportError: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 logger.critical("Could not import fife module. Please install fife or add " |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 "'FifePath' to the [parpg] section of your settings file") |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 sys.exit(1) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 from parpg.application import PARPGApplication |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 from parpg.common import utils |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 # enable psyco if available and in settings file |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 try: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 import psyco |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 psyco_available = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 except ImportError: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 logger.warning('Psyco Acceleration unavailable') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 psyco_available = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 if settings.fife.UsePsyco: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 if psyco_available: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 psyco.full() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 logger.info('Psyco Acceleration enabled') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 logger.warning('Please install psyco before attempting to use it' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 'Psyco Acceleration disabled') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 logger.info('Psycho Acceleration disabled') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 # run the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 app = PARPGApplication(settings) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 app.run() |