8 def readAll(convert_camel_case
=True):
9 """Reads all config files and returns the result
11 When a value is read in multiple times the one read in
12 the last is used. The following files are tried in the
22 path
= os
.path
.expanduser(path
)
26 path
= os
.path
.join(repo
.wd
, '.git', 'config')
29 paths
.append("config")
34 if not os
.path
.isfile(path
):
37 config
= read(path
, convert_camel_case
)
39 for key
, value
in config
.iteritems():
44 def _readVerse(verse
, config
, convert_camel_case
):
45 """Reads in a verse from a config file and stores the result in config
49 # Remove spaces and newlines
50 stripline
= line
.lstrip().rstrip()
52 if stripline
== line
.rstrip() or not stripline
:
55 # Extract the key:value pair
56 splitline
= stripline
.split(' = ')
57 key
= splitline
[0].rstrip()
58 value
= splitline
[1].lstrip()
60 # Try to convert to a number
76 if convert_camel_case
and key
.lower() != key
:
90 def read(path
, convert_camel_case
=True):
91 """Reads in the specified file
93 Understands 'True', 'False', 'None' and integer values.
94 All camelCase keys are converted to dashed_form.
95 The file is expected to have the following format:
99 <any unindented or empty line>
103 path: The location of the file to read in
105 Returns: A dictionary with the key:value pairs specified in the file.
111 lines
= file.readlines()
116 pos
= lines
.index("[GitStats]\n")
120 # Kick off the header
124 _readVerse(lines
, config
, convert_camel_case
)
128 if __name__
== '__main__':
131 print("convert_camel_case is ON:")
132 for key
, value
in result
.iteritems():
133 print(str(key
) + ": " + str(value
))
135 result
= readAll(False)
138 print("convertCamelCase is OFF:")
139 for key
, value
in result
.iteritems():
140 print(str(key
) + ": " + str(value
))