Skip to content

Commit 33747e2

Browse files
authored
Merge pull request #210 from Primvin/fix-sc2autosave
Fix: examples/sc2autosave.py update to Python 3
2 parents 609e1df + da0747f commit 33747e2

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

docs/source/utilities.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ Length
2626
:members:
2727

2828

29-
PersonDict
30-
---------------
31-
32-
.. autoclass:: PersonDict
33-
:members:
34-
35-
36-
AttributeDict
37-
------------------
38-
39-
.. autoclass:: AttributeDict
40-
:members:
41-
4229
get_files
4330
---------------
4431

examples/sc2autosave.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
import sys
167167
import textwrap
168168
import time
169+
from functools import cmp_to_key
169170

170171
import sc2reader
171172

@@ -268,6 +269,7 @@ def run(args):
268269
# Apply the aspects to the rename formatting.
269270
#'/' is a special character for creation of subdirectories.
270271
# TODO: Handle duplicate replay names, its possible..
272+
271273
path_parts = args.rename.format(**aspects).split("/")
272274
filename = path_parts.pop() + ".SC2Replay"
273275

@@ -281,9 +283,9 @@ def run(args):
281283

282284
# Log the action and run it if we are live
283285
msg = "{0}:\n\tSource: {1}\n\tDest: {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))
285287
if not args.dryrun:
286-
args.action.run(path, new_path)
288+
args.action["run"](path, new_path)
287289

288290
# After every batch completes, save the state and flush the log
289291
# TODO: modify the state to include a list of remaining files
@@ -368,19 +370,19 @@ def team_compare(team1, team2):
368370

369371

370372
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))
372374
matchups, team_strings = list(), list()
373375
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))
375377
composition = sorted(p.play_race[0].upper() for p in team.players)
376378
matchups.append("".join(composition))
377379
string = ", ".join(p.format(args.player_format) for p in team.players)
378380
team_strings.append(string)
379381

380-
return sc2reader.utils.AttributeDict(
382+
return dict(
381383
result=teams[0].result,
382384
length=replay.length,
383-
map=replay.map,
385+
map=replay.map_name.replace(":", ""),
384386
type=replay.type,
385387
date=replay.date.strftime(args.date_format),
386388
matchup="v".join(matchups),
@@ -412,7 +414,7 @@ def scan(args, state):
412414
depth=args.depth,
413415
followlinks=args.follow_links,
414416
)
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)
416418

417419

418420
def exit(msg, *args, **kwargs):
@@ -439,7 +441,7 @@ def reset(args):
439441

440442
def setup(args):
441443
args.team_compare, args.player_compare = create_compare_funcs(args)
442-
args.action = sc2reader.utils.AttributeDict(
444+
args.action = dict(
443445
type=args.action, run=shutil.copy if args.action == "COPY" else shutil.move
444446
)
445447
if not os.path.exists(args.source):
@@ -461,17 +463,17 @@ def setup(args):
461463

462464
args.log.write(f"Loading state from file: {data_file}\n")
463465
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:
465467
return pickle.load(file)
466468
else:
467-
return sc2reader.utils.AttributeDict(last_sync=0)
469+
return dict(last_sync=0)
468470

469471

470472
def save_state(state, args):
471-
state.last_sync = time.time()
473+
state["last_sync"] = time.time()
472474
data_file = os.path.join(args.dest, "sc2autosave.dat")
473475
if not args.dryrun:
474-
with open(data_file, "w") as file:
476+
with open(data_file, "wb") as file:
475477
pickle.dump(state, file)
476478
else:
477479
args.log.write(f"Writing state to file: {data_file}\n")

0 commit comments

Comments
 (0)