Mercurial > parpg-core
comparison src/parpg/main.py @ 180:59c4db30fe05
Created parpg.py and moved code from parpg\main.py to it.
author | KarstenBock@gmx.net |
---|---|
date | Mon, 10 Oct 2011 15:12:33 +0200 |
parents | 2e2d6d9009a3 |
children |
comparison
equal
deleted
inserted
replaced
179:828dcf3d4ee7 | 180:59c4db30fe05 |
---|---|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 # GNU General Public License for more details. | 10 # GNU General Public License for more details. |
11 | 11 |
12 # You should have received a copy of the GNU General Public License | 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/>. | 13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | 14 import logging |
15 #TODO: Modularize this script | |
16 import sys | 15 import sys |
17 import logging | 16 from os.path import abspath |
18 | |
19 from optparse import OptionParser | |
20 | 17 |
21 from parpg.settings import Settings | 18 from parpg.settings import Settings |
22 | 19 |
23 usage = ('usage: %prog [options] settings_path [system_path user_path]\n\n' | 20 |
24 'The settings_path argument is mandatory and is the directory in \n' | 21 def main(args, opts): |
25 'which your system.cfg file is located. Optionally, you may \n' | 22 settings = Settings(*args) |
26 'specify where data files are located (system_path), and where \n' | 23 |
27 'the user settings and data files should be saved to (user_path)\n\n' | 24 settings.parpg.DataPath = abspath(settings.parpg.DataPath) |
28 'Example: python %prog .') | 25 |
29 | 26 levels = {'debug': logging.DEBUG, |
30 parser = OptionParser(description='PARPG Launcher Script', usage=usage) | 27 'info': logging.INFO, |
31 parser.add_option('-f', '--logfile', | 28 'warning': logging.WARNING, |
32 help='Name of log file to save to') | 29 'error': logging.ERROR, |
33 parser.add_option('-l', '--loglevel', default='critical', | 30 'critical': logging.CRITICAL} |
34 help='desired output level for log file') | 31 |
35 opts, args = parser.parse_args() | 32 #TODO: setup formating |
36 | 33 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel]) |
37 if not args: | 34 logger = logging.getLogger('parpg') |
38 parser.print_help() | 35 |
39 sys.exit(1) | 36 try: |
40 | 37 old_path = sys.path |
41 | 38 sys.path = [settings.parpg.FifePath] |
42 | 39 import fife |
43 settings = Settings(*args) | 40 except AttributeError: |
44 | 41 logger.warning('[parpg] section has no FifePath option') |
45 levels = {'debug': logging.DEBUG, | 42 except ImportError: |
46 'info': logging.INFO, | 43 logger.critical("Could not import fife module. Please install fife or add " |
47 'warning': logging.WARNING, | 44 "'FifePath' to the [parpg] section of your settings file") |
48 'error': logging.ERROR, | 45 sys.exit(1) |
49 'critical': logging.CRITICAL} | 46 finally: |
50 | 47 sys.path = old_path |
51 #TODO: setup formating | 48 |
52 logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel]) | 49 from parpg.application import PARPGApplication |
53 logger = logging.getLogger('parpg') | 50 from parpg.common import utils |
54 | 51 |
55 try: | 52 # enable psyco if available and in settings file |
56 old_path = sys.path | 53 try: |
57 sys.path = [settings.parpg.FifePath] | 54 import psyco |
58 import fife | 55 psyco_available = True |
59 except AttributeError: | 56 except ImportError: |
60 logger.warning('[parpg] section has no FifePath option') | 57 logger.warning('Psyco Acceleration unavailable') |
61 except ImportError: | 58 psyco_available = False |
62 logger.critical("Could not import fife module. Please install fife or add " | 59 |
63 "'FifePath' to the [parpg] section of your settings file") | 60 if settings.fife.UsePsyco: |
64 sys.exit(1) | 61 if psyco_available: |
65 finally: | 62 psyco.full() |
66 sys.path = old_path | 63 logger.info('Psyco Acceleration enabled') |
67 | 64 else: |
68 from parpg.application import PARPGApplication | 65 logger.warning('Please install psyco before attempting to use it' |
69 from parpg.common import utils | 66 'Psyco Acceleration disabled') |
70 | |
71 # enable psyco if available and in settings file | |
72 try: | |
73 import psyco | |
74 psyco_available = True | |
75 except ImportError: | |
76 logger.warning('Psyco Acceleration unavailable') | |
77 psyco_available = False | |
78 | |
79 if settings.fife.UsePsyco: | |
80 if psyco_available: | |
81 psyco.full() | |
82 logger.info('Psyco Acceleration enabled') | |
83 else: | 67 else: |
84 logger.warning('Please install psyco before attempting to use it' | 68 logger.info('Psycho Acceleration disabled') |
85 'Psyco Acceleration disabled') | 69 |
86 else: | 70 # run the game |
87 logger.info('Psycho Acceleration disabled') | 71 app = PARPGApplication(settings) |
88 | 72 app.run() |
89 # run the game | |
90 app = PARPGApplication(settings) | |
91 app.run() |