1414from sc2reader import exceptions
1515from sc2reader import utils
1616from sc2reader import log_utils
17- from sc2reader .resources import Replay , Map , Summary
17+ from sc2reader .resources import Replay , Map , GameSummary , MatchInfo , MatchHistory
1818
1919class SC2Factory (object ):
2020 """
@@ -133,8 +133,12 @@ def load_resources(self, resources, resource_loader, options=None, **new_options
133133 if re .match (r'https?://' ,resources ):
134134 yield resource_loader (resources , options = options )
135135 else :
136- for resource in utils .get_replay_files (resources , ** options ):
137- yield resource_loader (resource , options = options )
136+ for resource in utils .get_files (resources , ** options ):
137+ try :
138+ yield resource_loader (resource , options = options )
139+ except Exception as e :
140+ print "\n \n \n FAILURE!!!\n \n \n "
141+ yield None
138142
139143 # File like object?
140144 elif hasattr (resources ,'read' ):
@@ -175,17 +179,17 @@ def load_resource(self, resource, options=None, **new_options):
175179
176180 return (resource , resource_name )
177181
178- def load_summaries (self , gs , options = None , ** new_options ):
182+ def load_game_summaries (self , gs , options = None , ** new_options ):
179183 """
180- Loads a collection of replays . See load_resources for detailed parameter
184+ Loads a collection of game summaries . See load_resources for detailed parameter
181185 documentation.
182186
183- :rtype: generator(:class:`Map `)
187+ :rtype: generator(:class:`GameSummary `)
184188 """
185- for s in self .load_resources (gs , self .load_summary , options = options , ** new_options ):
189+ for s in self .load_resources (gs , self .load_game_summary , options = options , extensions = [ '.s2gs' ] , ** new_options ):
186190 yield s
187191
188- def load_summary (self , summary_file , options = None , ** new_options ):
192+ def load_game_summary (self , summary_file , options = None , ** new_options ):
189193 """
190194 Loads the specified summary using the current factory settings with the
191195 specified overrides.
@@ -199,16 +203,87 @@ def load_summary(self, summary_file, options=None, **new_options):
199203 :param new_options: Options values to override current factory settings
200204 while loading this map.
201205
202- :rtype: :class:`Replay `
206+ :rtype: :class:`GameSummary `
203207 """
204208 options = options or utils .merged_dict (self .options , new_options )
205209 resource , name = self .load_resource (summary_file , options = options )
206- s = Summary (resource , name , ** options )
210+ s2gs = GameSummary (resource , name , ** options )
211+
212+ # Load summary procedure here!
213+ #
214+
215+ return s2gs
216+
217+ def load_match_infos (self , infos , options = None , ** new_options ):
218+ """
219+ Loads a collection of MatchInfos. See load_resources for detailed
220+ parameter documentation.
221+
222+ :rtype: generator(:class:`MatchInfo`)
223+ """
224+ for s2mi in self .load_resources (infos , self .load_match_info , options = options , extensions = ['.s2mi' ], ** new_options ):
225+ yield s2mi
226+
227+ def load_match_info (self , info_file , options = None , ** new_options ):
228+ """
229+ Loads the specified match info using the current factory settings with
230+ the specified overrides.
231+
232+ :param info_file: An open file object or path/url to a single file
233+
234+ :param None options: When options are passed directly into the options
235+ parameter the current factory settings are ignored and only the
236+ specified options are used during replay load.
237+
238+ :param new_options: Options values to override current factory settings
239+ while loading this map.
240+
241+ :rtype: :class:`MatchInfo`
242+ """
243+ options = options or utils .merged_dict (self .options , new_options )
244+ resource , name = self .load_resource (info_file , options = options )
245+ s2mi = MatchInfo (resource , name , ** options )
246+
247+ # Load summary procedure here!
248+ #
249+
250+ return s2mi
251+
252+ def load_match_histories (self , histories , options = None , ** new_options ):
253+ """
254+ Loads a collection of match history files. See load_resources for
255+ detailed parameter documentation.
256+
257+ :rtype: generator(:class:`MatchHistory`)
258+ """
259+ for s2mh in self .load_resources (histories , self .load_match_history , options = options , extensions = ['.s2mh' ], ** new_options ):
260+ yield s2mh
261+
262+ def load_match_history (self , history_file , options = None , ** new_options ):
263+ """
264+ Loads the specified match info using the current factory settings with
265+ the specified overrides.
266+
267+ :param history_file: An open file object or path/url to a single file
268+
269+ :param None options: When options are passed directly into the options
270+ parameter the current factory settings are ignored and only the
271+ specified options are used during replay load.
272+
273+ :param new_options: Options values to override current factory settings
274+ while loading this map.
275+
276+ :rtype: :class:`MatchHistory`
277+ """
278+ options = options or utils .merged_dict (self .options , new_options )
279+ resource , name = self .load_resource (history_file , options = options )
280+ print name
281+ s2mh = MatchHistory (resource , name , ** options )
207282
208283 # Load summary procedure here!
209284 #
210285
211- return s
286+ return s2mh
212287
213288 def load_maps (self , maps , options = None , ** new_options ):
214289 """
@@ -217,7 +292,7 @@ def load_maps(self, maps, options=None, **new_options):
217292
218293 :rtype: generator(:class:`Map`)
219294 """
220- for m in self .load_resources (maps , self .load_map , options = options , ** new_options ):
295+ for m in self .load_resources (maps , self .load_map , options = options , extensions = [ '.s2ma' ], ** new_options ):
221296 yield m
222297
223298 def load_map (self , map_file , options = None , ** new_options ):
@@ -253,7 +328,7 @@ def load_replays(self, replays, options=None, **new_options):
253328
254329 :rtype: generator(:class:`Replay`)
255330 """
256- for r in self .load_resources (replays , self .load_replay , options = options , ** new_options ):
331+ for r in self .load_resources (replays , self .load_replay , options = options , extensions = [ '.sc2replay' ], ** new_options ):
257332 yield r
258333
259334 def load_replay (self , replay_file , options = None , ** new_options ):
0 commit comments