Mercurial > touhou
comparison scripts/pytouhou @ 567:b2269b9c6119
Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 01 Jul 2014 23:17:40 +0200 |
parents | 04ae31809dc7 |
children | e7a4731a278b |
comparison
equal
deleted
inserted
replaced
566:04ae31809dc7 | 567:b2269b9c6119 |
---|---|
18 pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')), | 18 pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')), |
19 pathsep.join(('IN.DAT', 'th6*IN.DAT', '*IN.DAT', '*in.dat')), | 19 pathsep.join(('IN.DAT', 'th6*IN.DAT', '*IN.DAT', '*in.dat')), |
20 pathsep.join(('MD.DAT', 'th6*MD.DAT', '*MD.DAT', '*md.dat')), | 20 pathsep.join(('MD.DAT', 'th6*MD.DAT', '*MD.DAT', '*md.dat')), |
21 pathsep.join(('102h.exe', '102*.exe', '東方紅魔郷.exe', '*.exe'))) | 21 pathsep.join(('102h.exe', '102*.exe', '東方紅魔郷.exe', '*.exe'))) |
22 | 22 |
23 defaults = {'data': default_data} | 23 defaults = {'data': default_data, |
24 | 24 'path': '.', |
25 from pytouhou.options import parse_arguments | 25 'rank': 0, |
26 args = parse_arguments(defaults) | 26 'character': 0, |
27 | 27 'game': 'EoSD', |
28 verbosity = args.verbosity or 'WARNING' | 28 'interface': 'EoSD', |
29 'port': 0, | |
30 'backend': ['opengl', 'sdl'], | |
31 'gl-flavor': 'compatibility', | |
32 'gl-version': 2.1, | |
33 'double-buffer': None, | |
34 'fps-limit': -1} | |
35 | |
36 from pytouhou.options import parse_config, parse_arguments | |
37 options = parse_config('pytouhou', defaults) | |
38 args = parse_arguments(options) | |
39 | |
40 verbosity = args.verbosity or options.get('verbosity') or 'WARNING' | |
29 | 41 |
30 import logging | 42 import logging |
31 logging.basicConfig(level=getattr(logging, verbosity), | 43 logging.basicConfig(level=getattr(logging, verbosity), |
32 format='[%(name)s] [%(levelname)s]: %(message)s') | 44 format='[%(name)s] [%(levelname)s]: %(message)s') |
33 | 45 |
34 logger = logging | 46 logger = logging |
35 logger.root.name = 'pytouhou' | 47 logger.root.name = 'pytouhou' |
48 | |
49 logger.info('Configuration loaded from: %s', ', '.join(options.paths)) | |
36 | 50 |
37 if args.game == 'EoSD': | 51 if args.game == 'EoSD': |
38 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game | 52 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game |
39 | 53 |
40 if args.interface == 'EoSD': | 54 if args.interface == 'EoSD': |
67 options = {} | 81 options = {} |
68 | 82 |
69 try: | 83 try: |
70 backend = import_module('pytouhou.ui.%s.backend' % backend_name) | 84 backend = import_module('pytouhou.ui.%s.backend' % backend_name) |
71 except ImportError as e: | 85 except ImportError as e: |
72 logger.error('Failed to import backend %s: %s', backend_name, e) | 86 logger.exception('Failed to import backend %s:', backend_name) |
73 continue | 87 continue |
74 | 88 |
75 try: | 89 try: |
76 backend.init(options) | 90 backend.init(options) |
77 except Exception as e: | 91 except Exception as e: |
78 logger.error('Backend %s failed to initialize: %s', backend_name, e) | 92 logger.exception('Backend %s failed to initialize:', backend_name) |
79 continue | 93 continue |
80 | 94 |
81 GameRenderer = backend.GameRenderer | 95 GameRenderer = backend.GameRenderer |
82 break | 96 break |
83 else: | 97 else: |