Skip to content

Commit 7ec1ea3

Browse files
committed
Improve sc2printer --help and functionality.
Closes #110.
1 parent 3819bad commit 7ec1ea3

File tree

2 files changed

+58
-35
lines changed

2 files changed

+58
-35
lines changed

sc2reader/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ def __init__(self, pid):
358358

359359
def __str__(self):
360360
if not self.is_ai:
361-
return '{0} - {1} - {2}/{3}/'.format(self.teamid, self.play_race, self.subregion, self.bnetid)
361+
return 'User {0}-S2-{1}-{2}'.format(self.region.upper(), self.subregion, self.bnetid)
362362
else:
363-
return '{0} - {1} - AI'.format(self.teamid, self.play_race)
363+
return 'AI ({0})'.format(self.play_race)
364364

365365
def __repr__(self):
366366
return str(self)

sc2reader/scripts/sc2printer.py

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
# -*- coding: utf-8 -*-
33

44
import os
5-
import sys
65
import argparse
76

87
import sc2reader
98
from sc2reader import utils
109
from sc2reader.exceptions import ReadError
1110

11+
1212
def printReplay(filepath, arguments):
13-
'''Prints summary information about SC2 replay file'''
13+
""" Prints summary information about SC2 replay file """
1414
try:
1515
replay = sc2reader.load_replay(filepath, debug=True)
1616

1717
if arguments.map:
1818
print " Map: {0}".format(replay.map_name)
1919
if arguments.length:
20-
print " Length: {0}".format(replay.length)
20+
print " Length: {0} minutes".format(replay.game_length)
2121
if arguments.date:
22-
print " Date: {0}".format(replay.date)
22+
print " Date: {0}".format(replay.start_time)
2323
if arguments.teams:
2424
lineups = [team.lineup for team in replay.teams]
2525
print " Teams: {0}".format("v".join(lineups))
2626
for team in replay.teams:
27-
print " Team {0}\t{1} ({2})".format(team.number,team.players[0].name,team.players[0].pick_race[0])
27+
print " Team {0}\t{1} ({2})".format(team.number, team.players[0].name, team.players[0].pick_race[0])
2828
for player in team.players[1:]:
29-
print " \t{0} ({1})".format(player.name,player.pick_race[0])
29+
print " \t{0} ({1})".format(player.name, player.pick_race[0])
3030
if arguments.messages:
3131
print " Messages:"
3232
for message in replay.messages:
@@ -44,7 +44,7 @@ def printReplay(filepath, arguments):
4444
print "\tPrevious Event: {0}".format(prev.name)
4545
print "\t\t"+prev.bytes.encode('hex')
4646
print "\tFollowing Bytes:"
47-
print "\t\t"+e.buffer.read_range(e.location,e.location+30).encode('hex')
47+
print "\t\t"+e.buffer.read_range(e.location, e.location+30).encode('hex')
4848
print "Error with '{0}': ".format(filepath)
4949
print e
5050
except TypeError as e:
@@ -56,38 +56,61 @@ def printReplay(filepath, arguments):
5656
print e
5757

5858

59-
6059
def printGameSummary(filepath, arguments):
6160
summary = sc2reader.load_game_summary(filepath)
62-
print "{0} minute {1} game played on {2}".format(summary.game_length, summary.real_type, summary.map_name)
63-
for p in summary.players:
64-
print("== {0} - {1}/{2} ==".format(p.play_race, p.region, p.bnetid if not p.is_ai else "AI"))
65-
for order in summary.build_orders[p.pid]:
66-
print(" {0:0>2}:{1:0>2} {2:<35} {3:0>2}/{4}".format(order.time / 60,
67-
order.time % 60,
68-
order.order,
69-
order.supply,
70-
order.total_supply))
61+
62+
if arguments.map:
63+
print " Map: {0}".format(summary.map_name)
64+
if arguments.length:
65+
print " Length: {0} minutes".format(summary.game_length)
66+
if arguments.date:
67+
print " Date: {0}".format(summary.start_time)
68+
if arguments.teams:
69+
lineups = [team.lineup for team in summary.teams]
70+
print " Teams: {0}".format("v".join(lineups))
71+
for team in summary.teams:
72+
print " Team {0}\t{1}".format(team.number, team.players[0])
73+
for player in team.players[1:]:
74+
print " \t{0}".format(player)
75+
if arguments.builds:
76+
for player in summary.players:
77+
print("\n== {0} ==\n".format(player))
78+
for order in summary.build_orders[player.pid]:
79+
msg = " {0:0>2}:{1:0>2} {2:<35} {3:0>2}/{4}"
80+
print(msg.format(order.time / 60, order.time % 60, order.order, order.supply, order.total_supply))
7181
print
7282

83+
7384
def main():
74-
parser = argparse.ArgumentParser(description='Prints basic information from SC2 replay files or directories.')
75-
parser.add_argument('paths', metavar='filename', type=str, nargs='+',
76-
help="Paths to one or more SC2Replay files or directories")
77-
parser.add_argument('--date', action="store_true", default=True,
78-
help="Print game date")
79-
parser.add_argument('--length', action="store_true", default=False,
80-
help="Print game duration mm:ss in game time (not real time)")
81-
parser.add_argument('--map', action="store_true", default=True,
82-
help="Print map name")
83-
parser.add_argument('--messages', action="store_true", default=False,
84-
help="Print in-game player chat messages")
85-
parser.add_argument('--teams', action="store_true", default=True,
86-
help="Print teams, their players, and the race matchup")
87-
parser.add_argument('--version', action="store_true", default=True,
88-
help="Print the release string as seen in game")
85+
parser = argparse.ArgumentParser(
86+
description="""Prints basic information from Starcraft II replay and
87+
game summary files or directories.""")
8988
parser.add_argument('--recursive', action="store_true", default=True,
90-
help="Recursively read through directories of replays")
89+
help="Recursively read through directories of Starcraft II files [default on]")
90+
91+
required = parser.add_argument_group('Required Arguments')
92+
required.add_argument('paths', metavar='filename', type=str, nargs='+',
93+
help="Paths to one or more Starcraft II files or directories")
94+
95+
shared_args = parser.add_argument_group('Shared Arguments')
96+
shared_args.add_argument('--date', action="store_true", default=True,
97+
help="Print game date [default on]")
98+
shared_args.add_argument('--length', action="store_true", default=False,
99+
help="Print game duration mm:ss in game time (not real time) [default off]")
100+
shared_args.add_argument('--map', action="store_true", default=True,
101+
help="Print map name [default on]")
102+
shared_args.add_argument('--teams', action="store_true", default=True,
103+
help="Print teams, their players, and the race matchup [default on]")
104+
105+
replay_args = parser.add_argument_group('Replay Options')
106+
replay_args.add_argument('--messages', action="store_true", default=False,
107+
help="Print in-game player chat messages [default off]")
108+
replay_args.add_argument('--version', action="store_true", default=True,
109+
help="Print the release string as seen in game [default on]")
110+
111+
s2gs_args = parser.add_argument_group('Game Summary Options')
112+
s2gs_args.add_argument('--builds', action="store_true", default=False,
113+
help="Print player build orders (first 64 items) [default off]")
91114

92115
arguments = parser.parse_args()
93116
for path in arguments.paths:

0 commit comments

Comments
 (0)