Skip to content

Commit 02adf48

Browse files
committed
Adds a verbose option to the configuration and updates/improves the corresponding documentation
1 parent e2af918 commit 02adf48

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

docs/source/usage.rst

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,31 @@ Basic Usage
77
-------------
88

99
The sc2reader package itself can be configured and used to read replay files
10-
right out of the box! This lightweight approach to usage provides sane default
11-
options so no configuration is necessary for most normal usage. Read accepts
12-
either a file or a directory and returns either a single replay or a list of
13-
replays as the result.
10+
right out of the box! This lightweight approach to usage provides default
11+
options for full replay parsing so no configuration is necessary for normal use.
12+
13+
The ``configure`` function can be used to change this default configuration for
14+
all future package reads. The options, where supplied, will overwrite the
15+
default values. The ``read`` function takes a location, either file or
16+
directory, and returns a single replay or a list of replays respectively.
1417

1518
::
1619

1720
import sc2reader
1821
19-
#default configuration provided
2022
sc2reader.configure(**options)
2123
replay = sc2reader.read(file)
24+
25+
Alternatively, you can also pass options directly to the read function. This
26+
causes sc2reader to do a one off read with the given options, leaving the
27+
defaults unchanged.
28+
29+
::
30+
31+
import sc2reader
2232
33+
sc2reader.read(file,**options)
34+
2335
If you prefer a class based approach or want to have several different
2436
configurations on hand try the above approach. Just initialize the SC2Reader
2537
with the desired options (sane defaults provided) and use it just like you
@@ -34,31 +46,39 @@ of the documentation will use this class based approach.
3446
reader = SC2Reader(**options)
3547
replay = reader.read(file)
3648

37-
These two top level interfaces should remain fairly stable in the near to mid
49+
These three top level interfaces should remain fairly stable in the near to mid
3850
future.
3951

4052

4153
Options
4254
-----------
4355

4456
SC2Reader behavior can be configured with a number of options which can either
45-
be specified individually by keyword argument or packaged into a dictionary::
57+
be specified individually by keyword argument or packaged into a dictionary.
4658

47-
import sc2reader
59+
::
60+
61+
import sc2reader
62+
from sc2reader import SC2Reader, PARTIAL
4863
64+
#Its often cleaner to package the options into a dict first
4965
options = dict(
50-
'processors': [PostProcessor],
51-
'parse': sc2reader.PARTIAL,
52-
'directory':'C:\Users\Me\Documents...',
66+
processors=[ExamplePostProcessor],
67+
parse=PARTIAL,
68+
directory='C:\Users\Me\Documents...',
5369
)
54-
55-
reader = SC2Reader(processors=[PostProcessor],parse=sc2reader.PARTIAL)
56-
sc2reader.config(**options)
57-
70+
71+
#The various different configuration methods
72+
reader = SC2Reader(processors=[PostProcessor],parse=PARTIAL)
73+
sc2reader.read(location,**options)
74+
sc2reader.configure(**options)
75+
5876
Options currently available are described below:
5977

6078
.. option:: processors
6179

80+
*Default: []*
81+
6282
Specifies a list of processors to apply to the replay object after it is
6383
constructed but before it is returned::
6484
@@ -75,11 +95,15 @@ Options currently available are described below:
7595

7696
.. option:: directory
7797

98+
*Default: ""*
99+
78100
Specifies the directory in which the files to be read reside (defaults to
79101
None). Does a basic `os.path.join` with the file names as passed in.
80102

81103
.. option:: parse
82104

105+
*Default: FULL*
106+
83107
Three parse levels are provided for general convenience:
84108

85109
* ``FULL`` parse will parse through all available files and produce the
@@ -89,4 +113,9 @@ Options currently available are described below:
89113
* ``CUSTOM`` parse allows a user with intimate knowledge of sc2reader to
90114
hand build their own parse style.
91115

92-
116+
.. option:: verbose
117+
118+
*Default: False*
119+
120+
The verbose option can be used to get a detailed readout of the replay
121+
parsing progress. **Experimental Option**

sc2reader/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def read_header(file):
112112
return data[1],data[3]
113113

114114
class SC2Reader(object):
115-
def __init__(self, parse="FULL", directory="", processors=[], debug=False, files=None):
115+
def __init__(self, parse="FULL", directory="", processors=[], debug=False, files=None, verbose=False):
116116
#Sanitize the parse level
117117
parse = parse.upper()
118118
if parse not in ("FULL","PARTIAL","CUSTOM"):
@@ -128,7 +128,9 @@ def read(self, location):
128128
if self.directory:
129129
location = os.path.join(self.directory,location)
130130
if not os.path.exists(location):
131-
raise ValueError("Location must exist")
131+
raise ValueError("Path `%s` cannot be found" % location)
132+
133+
if self.verbose: print "Reading: %s" % location
132134

133135
#If its a directory, read each subfile/directory and combine the lists
134136
if os.path.isdir(location):
@@ -168,5 +170,8 @@ def configure(self,**options):
168170
def configure(**options):
169171
__defaultSC2Reader.configure(options)
170172

171-
def read(location):
172-
return __defaultSC2Reader.read(location)
173+
def read(location, **options):
174+
if options:
175+
return SC2Reader(**options).read(location)
176+
else:
177+
return __defaultSC2Reader.read(location)

0 commit comments

Comments
 (0)