Skip to content

Commit a5108a6

Browse files
committed
Adds initial s2gs support via load_summary.
1 parent 6b540c2 commit a5108a6

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

sc2reader/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
load_replay = __defaultSC2Reader.load_replay
2727
load_maps = __defaultSC2Reader.load_maps
2828
load_map = __defaultSC2Reader.load_map
29+
load_summaries = __defaultSC2Reader.load_summaries
30+
load_summary = __defaultSC2Reader.load_summary
2931

3032
configure = __defaultSC2Reader.configure
3133
reset = __defaultSC2Reader.reset

sc2reader/factories.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sc2reader import exceptions
1515
from sc2reader import utils
1616
from sc2reader import log_utils
17-
from sc2reader.resources import Replay, Map
17+
from sc2reader.resources import Replay, Map, Summary
1818

1919
class SC2Factory(object):
2020
"""
@@ -175,6 +175,40 @@ def load_resource(self, resource, options=None, **new_options):
175175

176176
return (resource, resource_name)
177177

178+
def load_summaries(self, gs, options=None, **new_options):
179+
"""
180+
Loads a collection of replays. See load_resources for detailed parameter
181+
documentation.
182+
183+
:rtype: generator(:class:`Map`)
184+
"""
185+
for s in self.load_resources(gs, self.load_summary, options=options, **new_options):
186+
yield s
187+
188+
def load_summary(self, summary_file, options=None, **new_options):
189+
"""
190+
Loads the specified summary using the current factory settings with the
191+
specified overrides.
192+
193+
:param summary_file: An open file object or path/url to a single file
194+
195+
:param None options: When options are passed directly into the options
196+
parameter the current factory settings are ignored and only the
197+
specified options are used during replay load.
198+
199+
:param new_options: Options values to override current factory settings
200+
while loading this map.
201+
202+
:rtype: :class:`Replay`
203+
"""
204+
options = options or utils.merged_dict(self.options, new_options)
205+
resource, name = self.load_resource(summary_file, options=options)
206+
s = Summary(resource, name, **options)
207+
208+
# Load summary procedure here!
209+
#
210+
211+
return s
178212

179213
def load_maps(self, maps, options=None, **new_options):
180214
"""

sc2reader/resources.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22

3+
import zlib
34
import hashlib
45
from datetime import datetime
56
from StringIO import StringIO
@@ -23,7 +24,6 @@ def __init__(self, file_object, filename=None, **options):
2324
self.filehash = hashlib.sha256(file_object.read()).hexdigest()
2425
file_object.seek(0)
2526

26-
2727
class Replay(Resource):
2828

2929
#: Fully qualified filename of the replay file represented.
@@ -394,4 +394,18 @@ def read_game_strings(self):
394394
elif parts[0] == 'DocInfo/Author':
395395
self.author = parts[1]
396396
elif parts[0] == 'DocInfo/DescLong':
397-
self.description = parts[1]
397+
self.description = parts[1]
398+
399+
class Summary(Resource):
400+
url_template = 'http://{0}.depot.battle.net:1119/{1}.s2ma'
401+
402+
def __init__(self, summary_file, filename=None, **options):
403+
super(Summary, self).__init__(summary_file, filename,**options)
404+
self.data = zlib.decompress(summary_file.read()[16:])
405+
self.parts = list()
406+
buffer = utils.ReplayBuffer(self.data)
407+
while buffer.left:
408+
part = buffer.read_data_struct()
409+
print str(part)+"\n\n\n"
410+
self.parts.append(buffer.read_data_struct())
411+
print len(self.parts)

0 commit comments

Comments
 (0)