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 read(path
, convert_camel_case
=True):
45 """Reads in the specified file
47 Understands 'True', 'False', 'None' and integer values.
48 All camelCase keys are converted to dashed_form.
49 The file is expected to have the following format:
53 <any unindented or empty line>
57 path: The location of the file to read in
59 Returns: A dictionary with the key:value pairs specified in the file.
65 lines
= file.readlines()
69 pos
= lines
.index("[GitStats]\n")
78 # Remove spaces and newlines
79 stripline
= line
.lstrip().rstrip()
81 if stripline
== line
.rstrip() or not stripline
:
84 # Extract the key:value pair
85 splitline
= stripline
.split(' = ')
86 key
= splitline
[0].rstrip()
87 value
= splitline
[1].lstrip()
89 # Try to convert to a number
105 if convert_camel_case
and key
.lower() != key
:
120 if __name__
== '__main__':
123 print("convert_camel_case is ON:")
124 for key
, value
in result
.iteritems():
125 print(str(key
) + ": " + str(value
))
127 result
= readAll(False)
130 print("convertCamelCase is OFF:")
131 for key
, value
in result
.iteritems():
132 print(str(key
) + ": " + str(value
))