11import os
22
3+ try :
4+ from collections import OrderedDict
5+ except ImportError :
6+ from ordereddict import OrderedDict
7+ except ImportError :
8+ from sys import exit
9+ exit ("OrderedDict required: Upgrade to python2.7 or `pip install ordereddict`" )
10+
311from mpyq import MPQArchive
4- import config
5- from objects import Replay
612from utils import ReplayBuffer , LITTLE_ENDIAN
13+ from objects import Replay
14+ from processors import *
15+ from readers import *
16+
17+ __version__ = "0.3.0"
18+
19+ #Library configuration and constants
20+ FULL = 1
21+ PARTIAL = 2
22+ CUSTOM = 3
23+
24+ FILES_FULL = ['replay.initData' ,'replay.details' ,'replay.attributes.events' ,'replay.message.events' ,'replay.game.events' ]
25+ FILES_PARTIAL = ['replay.initData' ,'replay.details' ,'replay.attributes.events' ,'replay.message.events' ]
726
27+ PROCESSORS_FULL = [
28+ PeopleProcessor (),
29+ AttributeProcessor (),
30+ TeamsProcessor (),
31+ MessageProcessor (),
32+ RecorderProcessor (),
33+ EventProcessor (),
34+ ApmProcessor (),
35+ ResultsProcessor ()
36+ ]
37+
38+ PROCESSORS_PARTIAL = [
39+ PeopleProcessor (),
40+ AttributeProcessor (),
41+ TeamsProcessor (),
42+ MessageProcessor (),
43+ RecorderProcessor (),
44+ ]
45+ READERS = OrderedDict ([
46+ ('replay.initData' , [ReplayInitDataReader ()]),
47+ ('replay.details' , [ReplayDetailsReader ()]),
48+ ('replay.attributes.events' , [AttributeEventsReader_17326 (), AttributeEventsReader ()]),
49+ ('replay.message.events' , [MessageEventsReader ()]),
50+ ('replay.game.events' , [GameEventsReader ()]),
51+ ])
52+
853def read_header (file ):
954 buffer = ReplayBuffer (file )
1055
@@ -25,17 +70,16 @@ def read_header(file):
2570 return data [1 ],data [3 ]
2671
2772class SC2Reader (object ):
28-
29- def __init__ (self , parse = config .FULL , directory = "" , processors = [], debug = False , files = None ):
73+ def __init__ (self , parse = FULL , directory = "" , processors = [], debug = False , files = None ):
3074 #Check that arguments are consistent with expectations up front
3175 #Easier to debug issues this way
32- if parse == config . FULL :
33- files = config . FILES_FULL
34- processors = config . PROCESSORS_FULL + processors
35- elif parse == config . PARTIAL :
36- files = config . FILES_PARTIAL
37- processors = config . PROCESSORS_PARTIAL + processors
38- elif parse == config . CUSTOM :
76+ if parse == FULL :
77+ files = FILES_FULL
78+ processors = PROCESSORS_FULL + processors
79+ elif parse == PARTIAL :
80+ files = FILES_PARTIAL
81+ processors = PROCESSORS_PARTIAL + processors
82+ elif parse == CUSTOM :
3983 if not files :
4084 raise ValueError ("Custom parsing requires specification the files arguments" )
4185 else :
@@ -74,7 +118,7 @@ def read(self, location):
74118 archive = MPQArchive (location ,listfile = False )
75119
76120 #Extract and Parse the relevant files based on parse level
77- for file ,readers in config . READERS .iteritems ():
121+ for file ,readers in READERS .iteritems ():
78122 if file in self .files :
79123 for reader in readers :
80124 if reader .reads (replay .build ):
@@ -92,6 +136,7 @@ def read(self, location):
92136 def configure (self ,** options ):
93137 self .__dict__ .update (options )
94138
139+
95140#Prepare the lightweight interface
96141__defaultSC2Reader = SC2Reader ()
97142
@@ -100,6 +145,3 @@ def configure(**options):
100145
101146def read (location ):
102147 return __defaultSC2Reader .read (location )
103-
104- __all__ = [read ,config ,SC2Reader ]
105- __version__ = "0.3.0"
0 commit comments