1111
1212from construct .core import ConstructError
1313from tabulate import tabulate
14- import tqdm
1514
1615import mgz
1716import mgz .const
2322
2423
2524LOGGER = logging .getLogger (__name__ )
26- CMD_PLAY = 'play'
27- CMD_EXTRACT = 'extract'
2825CMD_INFO = 'info'
2926CMD_CHAT = 'chat'
3027CMD_VALIDATE = 'validate'
3431CMD_PAD = 'pad'
3532
3633
37- class TqdmStream : # pylint: disable=too-few-public-methods
38- """Log handler for TQDM."""
39-
40- @classmethod
41- def write (cls , msg ):
42- """Handle progress bars and logs."""
43- tqdm .tqdm .write (msg , end = '' )
44-
45-
46- async def play_rec (playback , path ):
47- """Play a recorded game."""
48- if not playback :
49- raise RuntimeError ('playback not supported' )
50- from mgz .playback import Client , progress_bar
51- with open (path , 'rb' ) as handle :
52- summary = Summary (handle )
53- client = await Client .create (
54- playback , path , summary .get_start_time (), summary .get_duration ()
55- )
56- async for _ , _ , _ in progress_bar (client .sync (), client .duration ):
57- pass
58-
59-
60- async def extract_rec (playback , path , select = None ):
61- """Extract data from a recorded game."""
62- with open (path , 'rb' ) as handle :
63- summary = Summary (handle , playback = playback )
64- data = await summary .async_extract (30000 )
65- print ('version: {}, runtime: {}' .format (data ['version' ], data ['runtime' ]))
66- for key , records in data .items ():
67- if select and key != select :
68- continue
69- print (key )
70- print ('-------------' )
71- for record in records :
72- print (record )
73-
74-
7534def print_info (path ):
7635 """Print basic info."""
7736 with open (path , 'rb' ) as handle :
@@ -215,13 +174,7 @@ def print_histogram(path):
215174
216175async def run (args ): # pylint: disable=too-many-branches
217176 """Entry point."""
218- if args .cmd == CMD_PLAY :
219- for rec in args .rec_path :
220- await play_rec (args .playback .split (',' )[0 ], rec )
221- elif args .cmd == CMD_EXTRACT :
222- for rec in args .rec_path :
223- await extract_rec (args .playback .split (',' )[0 ], rec , args .select )
224- elif args .cmd == CMD_INFO :
177+ if args .cmd == CMD_INFO :
225178 for rec in args .rec_path :
226179 print_info (rec )
227180 elif args .cmd == CMD_CHAT :
@@ -247,19 +200,12 @@ async def run(args): # pylint: disable=too-many-branches
247200def get_args ():
248201 """Get arguments."""
249202 parser = argparse .ArgumentParser ()
250- parser .add_argument ('-p' , '--playback' ,
251- default = os .environ .get ('AOC_PLAYBACK' , '' ))
252203 subparsers = parser .add_subparsers (dest = 'cmd' )
253204 subparsers .required = True
254205 info = subparsers .add_parser (CMD_INFO )
255206 info .add_argument ('rec_path' , nargs = '+' )
256207 chat = subparsers .add_parser (CMD_CHAT )
257208 chat .add_argument ('rec_path' , nargs = '+' )
258- play = subparsers .add_parser (CMD_PLAY )
259- play .add_argument ('rec_path' , nargs = '+' )
260- extract = subparsers .add_parser (CMD_EXTRACT )
261- extract .add_argument ('-s' , '--select' )
262- extract .add_argument ('rec_path' , nargs = '+' )
263209 validate = subparsers .add_parser (CMD_VALIDATE )
264210 validate .add_argument ('rec_path' , nargs = '+' )
265211 dump = subparsers .add_parser (CMD_DUMP )
0 commit comments