166
166
import sys
167
167
import textwrap
168
168
import time
169
+ from functools import cmp_to_key
169
170
170
171
import sc2reader
171
172
@@ -268,6 +269,7 @@ def run(args):
268
269
# Apply the aspects to the rename formatting.
269
270
#'/' is a special character for creation of subdirectories.
270
271
# TODO: Handle duplicate replay names, its possible..
272
+
271
273
path_parts = args .rename .format (** aspects ).split ("/" )
272
274
filename = path_parts .pop () + ".SC2Replay"
273
275
@@ -281,9 +283,9 @@ def run(args):
281
283
282
284
# Log the action and run it if we are live
283
285
msg = "{0}:\n \t Source: {1}\n \t Dest: {2}\n "
284
- args .log .write (msg .format (args .action . type , source_path , dest_path ))
286
+ args .log .write (msg .format (args .action [ " type" ] , source_path , dest_path ))
285
287
if not args .dryrun :
286
- args .action . run (path , new_path )
288
+ args .action [ " run" ] (path , new_path )
287
289
288
290
# After every batch completes, save the state and flush the log
289
291
# TODO: modify the state to include a list of remaining files
@@ -368,19 +370,19 @@ def team_compare(team1, team2):
368
370
369
371
370
372
def generate_aspects (args , replay ):
371
- teams = sorted (replay .teams , args .team_compare )
373
+ teams = sorted (replay .teams , key = cmp_to_key ( args .team_compare ) )
372
374
matchups , team_strings = list (), list ()
373
375
for team in teams :
374
- team .players = sorted (team .players , args .player_compare )
376
+ team .players = sorted (team .players , key = cmp_to_key ( args .player_compare ) )
375
377
composition = sorted (p .play_race [0 ].upper () for p in team .players )
376
378
matchups .append ("" .join (composition ))
377
379
string = ", " .join (p .format (args .player_format ) for p in team .players )
378
380
team_strings .append (string )
379
381
380
- return sc2reader . utils . AttributeDict (
382
+ return dict (
381
383
result = teams [0 ].result ,
382
384
length = replay .length ,
383
- map = replay .map ,
385
+ map = replay .map_name . replace ( ":" , "" ) ,
384
386
type = replay .type ,
385
387
date = replay .date .strftime (args .date_format ),
386
388
matchup = "v" .join (matchups ),
@@ -412,7 +414,7 @@ def scan(args, state):
412
414
depth = args .depth ,
413
415
followlinks = args .follow_links ,
414
416
)
415
- return filter (lambda f : os .path .getctime (f ) > state . last_sync , files )
417
+ return filter (lambda f : os .path .getctime (f ) > state [ " last_sync" ] , files )
416
418
417
419
418
420
def exit (msg , * args , ** kwargs ):
@@ -439,7 +441,7 @@ def reset(args):
439
441
440
442
def setup (args ):
441
443
args .team_compare , args .player_compare = create_compare_funcs (args )
442
- args .action = sc2reader . utils . AttributeDict (
444
+ args .action = dict (
443
445
type = args .action , run = shutil .copy if args .action == "COPY" else shutil .move
444
446
)
445
447
if not os .path .exists (args .source ):
@@ -461,17 +463,17 @@ def setup(args):
461
463
462
464
args .log .write (f"Loading state from file: { data_file } \n " )
463
465
if os .path .isfile (data_file ) and not args .reset :
464
- with open (data_file ) as file :
466
+ with open (data_file , "rb" ) as file :
465
467
return pickle .load (file )
466
468
else :
467
- return sc2reader . utils . AttributeDict (last_sync = 0 )
469
+ return dict (last_sync = 0 )
468
470
469
471
470
472
def save_state (state , args ):
471
- state . last_sync = time .time ()
473
+ state [ " last_sync" ] = time .time ()
472
474
data_file = os .path .join (args .dest , "sc2autosave.dat" )
473
475
if not args .dryrun :
474
- with open (data_file , "w " ) as file :
476
+ with open (data_file , "wb " ) as file :
475
477
pickle .dump (state , file )
476
478
else :
477
479
args .log .write (f"Writing state to file: { data_file } \n " )
0 commit comments