comparison scripts/pytouhou @ 561:bafe6361c0af

Use logging for errors in the pytouhou script.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Jun 2014 18:47:31 +0200
parents 653a9f087673
children 5f7f859a72f9
comparison
equal deleted inserted replaced
560:c759b97f4f81 561:bafe6361c0af
69 args = parser.parse_args() 69 args = parser.parse_args()
70 70
71 71
72 import sys 72 import sys
73 import logging 73 import logging
74 from pytouhou.utils.helpers import get_logger
75
76 if args.verbosity is not None:
77 logging.basicConfig(level=getattr(logging, args.verbosity))
78 logger = get_logger('pytouhou')
74 79
75 80
76 if args.game == 'EoSD': 81 if args.game == 'EoSD':
77 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game 82 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game
78 83
93 from pytouhou.formats.hint import Hint 98 from pytouhou.formats.hint import Hint
94 from pytouhou.network import Network 99 from pytouhou.network import Network
95 100
96 101
97 from importlib import import_module 102 from importlib import import_module
98 for backend in args.backend: 103 for backend_name in args.backend:
99 if backend == 'opengl': 104 if backend_name == 'opengl':
100 options = { 105 options = {
101 'flavor': args.gl_flavor, 106 'flavor': args.gl_flavor,
102 'version': args.gl_version, 107 'version': args.gl_version,
103 'double-buffer': args.double_buffer, 108 'double-buffer': args.double_buffer,
104 } 109 }
105 else: 110 else:
106 options = {} 111 options = {}
107 112
108 try: 113 try:
109 backend = import_module('pytouhou.ui.%s.backend' % backend) 114 backend = import_module('pytouhou.ui.%s.backend' % backend_name)
110 except ImportError as e: 115 except ImportError as e:
116 logger.error('Failed to import backend %s: %s', backend_name, e)
111 continue 117 continue
112 118
113 try: 119 try:
114 backend.init(options) 120 backend.init(options)
115 except Exception as e: 121 except Exception as e:
116 print('Backend', backend, 'failed to initialize:', e) 122 logger.error('Backend %s failed to initialize: %s', backend_name, e)
117 pass 123 continue
118 else: 124
119 GameRenderer = backend.GameRenderer 125 GameRenderer = backend.GameRenderer
120 break 126 break
121 else: 127 else:
122 show_simple_message_box(u'No graphical backend could be used, continuing with a windowless game.') 128 show_simple_message_box(u'No graphical backend could be used, continuing with a windowless game.')
123 backend = None 129 backend = None
124 GameRenderer = None 130 GameRenderer = None
125 131
152 Game.cleanup(self) 158 Game.cleanup(self)
153 159
154 160
155 def main(window, path, data, stage_num, rank, character, replay, save_filename, 161 def main(window, path, data, stage_num, rank, character, replay, save_filename,
156 skip_replay, boss_rush, debug, enable_background, enable_particles, 162 skip_replay, boss_rush, debug, enable_background, enable_particles,
157 hints, verbosity, port, remote, friendly_fire): 163 hints, port, remote, friendly_fire):
158 164
159 resource_loader = Loader(path) 165 resource_loader = Loader(path)
160 166
161 try: 167 try:
162 resource_loader.scan_archives(data) 168 resource_loader.scan_archives(data)
171 else: 177 else:
172 story = False 178 story = False
173 continues = 0 179 continues = 0
174 180
175 if debug: 181 if debug:
176 if not verbosity:
177 verbosity = 'DEBUG'
178 continues = -1 # Infinite lives 182 continues = -1 # Infinite lives
179
180 if verbosity:
181 logging.basicConfig(level=logging.__getattribute__(verbosity))
182 183
183 if replay: 184 if replay:
184 with open(replay, 'rb') as file: 185 with open(replay, 'rb') as file:
185 replay = T6RP.read(file) 186 replay = T6RP.read(file)
186 rank = replay.rank 187 rank = replay.rank
303 window = Window(backend, fps_limit=args.fps_limit) 304 window = Window(backend, fps_limit=args.fps_limit)
304 305
305 main(window, args.path, tuple(args.data), args.stage, args.rank, 306 main(window, args.path, tuple(args.data), args.stage, args.rank,
306 args.character, args.replay, args.save_replay, args.skip_replay, 307 args.character, args.replay, args.save_replay, args.skip_replay,
307 args.boss_rush, args.debug, args.no_background, args.no_particles, 308 args.boss_rush, args.debug, args.no_background, args.no_particles,
308 args.hints, args.verbosity, args.port, args.remote, 309 args.hints, args.port, args.remote, args.friendly_fire)
309 args.friendly_fire)
310 310
311 import gc 311 import gc
312 gc.collect() 312 gc.collect()