11#!/usr/bin/env python
2- # -*- coding: utf-8 -*-
32"""sc2autosave is a utility for reorganizing and renaming Starcraft II files.
43
54Overview
7877keeps the script from looking into the 'Saved' subdirectory.
7978
8079 sc2autosave \
81- --source ~/My\ Documents/Starcraft\ II/Accounts/.../Mutliplayer \
82- --dest ~/My\ Documents/Starcraft\ II/Accounts/.../Multiplater/Saved \
80+ --source ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Mutliplayer \
81+ --dest ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Multiplater/Saved \
8382 --period 10 \
8483 --depth 0
8584
8685This next configuration runs in batch mode using the default renaming format.
8786
8887 sc2autosave \
89- --source ~/My\ Documents/Starcraft\ II/Accounts/.../Mutliplayer \
90- --dest ~/My\ Documents/Starcraft\ II/Accounts/.../Multiplater/Saved \
88+ --source ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Mutliplayer \
89+ --dest ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Multiplater/Saved \
9190 --rename
9291
9392 (ZvP) Lost Temple: ShadesofGray(Z) vs Trisfall(P).SC2Replay
9796by replay format and favors ShadesofGray in the player and team orderings.
9897
9998 sc2autosave \
100- --source ~/My\ Documents/Starcraft\ II/Accounts/.../Mutliplayer \
101- --dest ~/My\ Documents/Starcraft\ II/Accounts/.../Multiplater/Saved \
99+ --source ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Mutliplayer \
100+ --dest ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Multiplater/Saved \
102101 --rename "{:format}/{:matchup} on {:map}: {:teams}" \
103102 --player-format "{:name}({:play_race})" \
104103 --team-order-by number \
113112length to show both minutes and seconds.
114113
115114 sc2autosave \
116- --source ~/My\ Documents/Starcraft\ II/Accounts/.../Mutliplayer \
117- --dest ~/My\ Documents/Starcraft\ II/Accounts/.../Multiplater/Saved \
115+ --source ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Mutliplayer \
116+ --dest ~/My\\ Documents/Starcraft\ \ II/Accounts/.../Multiplater/Saved \
118117 --rename "{:matchup}/({:length}) {:map}: {:teams}" \
119118 --player-format "{:name}({:play_race})" \
120119 --team-order-by number \
@@ -200,7 +199,7 @@ def run(args):
200199 directory = make_directory (args , ("parse_error" ,))
201200 new_path = os .path .join (directory , file_name )
202201 source_path = path [len (args .source ) :]
203- args .log .write ("Error parsing replay: {0}" . format ( source_path ) )
202+ args .log .write (f "Error parsing replay: { source_path } " )
204203 if not args .dryrun :
205204 args .action .run (path , new_path )
206205
@@ -250,7 +249,7 @@ def run(args):
250249
251250
252251def filter_out_replay (args , replay ):
253- player_names = set ([ player .name for player in replay .players ])
252+ player_names = { player .name for player in replay .players }
254253 filter_out_player = not set (args .filter_player ) & player_names
255254
256255 if args .filter_rule == "ALLOW" :
@@ -262,7 +261,7 @@ def filter_out_replay(args, replay):
262261# We need to create these compare functions at runtime because the ordering
263262# hinges on the --favored PLAYER options passed in from the command line.
264263def create_compare_funcs (args ):
265- favored_set = set ( name .lower () for name in args .favored )
264+ favored_set = { name .lower () for name in args .favored }
266265
267266 def player_compare (player1 , player2 ):
268267 # Normalize the player names and generate our key metrics
@@ -290,8 +289,8 @@ def player_compare(player1, player2):
290289
291290 def team_compare (team1 , team2 ):
292291 # Normalize the team name lists and generate our key metrics
293- team1_names = set ( p .name .lower () for p in team1 .players )
294- team2_names = set ( p .name .lower () for p in team2 .players )
292+ team1_names = { p .name .lower () for p in team1 .players }
293+ team2_names = { p .name .lower () for p in team2 .players }
295294 team1_favored = team1_names & favored_set
296295 team2_favored = team2_names & favored_set
297296
@@ -341,7 +340,7 @@ def make_directory(args, path_parts):
341340 for part in path_parts :
342341 directory = os .path .join (directory , part )
343342 if not os .path .exists (directory ):
344- args .log .write ("Creating subfolder: {0 }\n " . format ( directory ) )
343+ args .log .write (f "Creating subfolder: { directory } \n " )
345344 if not args .dryrun :
346345 os .mkdir (directory )
347346 elif not os .path .isdir (directory ):
@@ -351,7 +350,7 @@ def make_directory(args, path_parts):
351350
352351
353352def scan (args , state ):
354- args .log .write ("SCANNING: {0 }\n " . format ( args . source ) )
353+ args .log .write (f "SCANNING: { args . source } \n " )
355354 files = sc2reader .utils .get_files (
356355 path = args .source ,
357356 regex = args .exclude_files ,
@@ -374,13 +373,13 @@ def reset(args):
374373 exit ("Cannot reset, destination must be directory: {0}" , args .dest )
375374
376375 print (
377- "About to reset directory: {0 }\n All files and subdirectories will be removed." .format (
376+ "About to reset directory: {}\n All files and subdirectories will be removed." .format (
378377 args .dest
379378 )
380379 )
381380 choice = raw_input ("Proceed anyway? (y/n) " )
382381 if choice .lower () == "y" :
383- args .log .write ("Removing old directory: {0 }\n " . format ( args . dest ) )
382+ args .log .write (f "Removing old directory: { args . dest } \n " )
384383 if not args .dryrun :
385384 print (args .dest )
386385 shutil .rmtree (args .dest )
@@ -404,13 +403,13 @@ def setup(args):
404403 if not args .dryrun :
405404 os .mkdir (args .dest )
406405 else :
407- args .log .write ("Creating destination: {0 }\n " . format ( args . dest ) )
406+ args .log .write (f "Creating destination: { args . dest } \n " )
408407 elif not os .path .isdir (args .dest ):
409408 sys .exit ("Destination must be a directory.\n \n Script Aborted" )
410409
411410 data_file = os .path .join (args .dest , "sc2autosave.dat" )
412411
413- args .log .write ("Loading state from file: {0 }\n " . format ( data_file ) )
412+ args .log .write (f "Loading state from file: { data_file } \n " )
414413 if os .path .isfile (data_file ) and not args .reset :
415414 with open (data_file ) as file :
416415 return cPickle .load (file )
@@ -425,7 +424,7 @@ def save_state(state, args):
425424 with open (data_file , "w" ) as file :
426425 cPickle .dump (state , file )
427426 else :
428- args .log .write ("Writing state to file: {0 }\n " . format ( data_file ) )
427+ args .log .write (f "Writing state to file: { data_file } \n " )
429428
430429
431430def main ():
0 commit comments