Skip to content

Commit 4a707e4

Browse files
committed
Fix: examples/sc2autosave.py update to Python 3
1 parent 609e1df commit 4a707e4

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
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: 15 additions & 11 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,9 @@ 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+
273+
274+
271275
path_parts = args.rename.format(**aspects).split("/")
272276
filename = path_parts.pop() + ".SC2Replay"
273277

@@ -281,9 +285,9 @@ def run(args):
281285

282286
# Log the action and run it if we are live
283287
msg = "{0}:\n\tSource: {1}\n\tDest: {2}\n"
284-
args.log.write(msg.format(args.action.type, source_path, dest_path))
288+
args.log.write(msg.format(args.action["type"], source_path, dest_path))
285289
if not args.dryrun:
286-
args.action.run(path, new_path)
290+
args.action["run"](path, new_path)
287291

288292
# After every batch completes, save the state and flush the log
289293
# TODO: modify the state to include a list of remaining files
@@ -368,16 +372,16 @@ def team_compare(team1, team2):
368372

369373

370374
def generate_aspects(args, replay):
371-
teams = sorted(replay.teams, args.team_compare)
375+
teams = sorted(replay.teams, key=cmp_to_key(args.team_compare))
372376
matchups, team_strings = list(), list()
373377
for team in teams:
374-
team.players = sorted(team.players, args.player_compare)
378+
team.players = sorted(team.players, key=cmp_to_key(args.player_compare))
375379
composition = sorted(p.play_race[0].upper() for p in team.players)
376380
matchups.append("".join(composition))
377381
string = ", ".join(p.format(args.player_format) for p in team.players)
378382
team_strings.append(string)
379383

380-
return sc2reader.utils.AttributeDict(
384+
return dict(
381385
result=teams[0].result,
382386
length=replay.length,
383387
map=replay.map,
@@ -412,7 +416,7 @@ def scan(args, state):
412416
depth=args.depth,
413417
followlinks=args.follow_links,
414418
)
415-
return filter(lambda f: os.path.getctime(f) > state.last_sync, files)
419+
return filter(lambda f: os.path.getctime(f) > state["last_sync"], files)
416420

417421

418422
def exit(msg, *args, **kwargs):
@@ -439,7 +443,7 @@ def reset(args):
439443

440444
def setup(args):
441445
args.team_compare, args.player_compare = create_compare_funcs(args)
442-
args.action = sc2reader.utils.AttributeDict(
446+
args.action = dict(
443447
type=args.action, run=shutil.copy if args.action == "COPY" else shutil.move
444448
)
445449
if not os.path.exists(args.source):
@@ -461,17 +465,17 @@ def setup(args):
461465

462466
args.log.write(f"Loading state from file: {data_file}\n")
463467
if os.path.isfile(data_file) and not args.reset:
464-
with open(data_file) as file:
468+
with open(data_file, "rb") as file:
465469
return pickle.load(file)
466470
else:
467-
return sc2reader.utils.AttributeDict(last_sync=0)
471+
return dict(last_sync=0)
468472

469473

470474
def save_state(state, args):
471-
state.last_sync = time.time()
475+
state["last_sync"] = time.time()
472476
data_file = os.path.join(args.dest, "sc2autosave.dat")
473477
if not args.dryrun:
474-
with open(data_file, "w") as file:
478+
with open(data_file, "wb") as file:
475479
pickle.dump(state, file)
476480
else:
477481
args.log.write(f"Writing state to file: {data_file}\n")

0 commit comments

Comments
 (0)