gitstats: Check for empty diffs
[git-stats.git] / src / git_stats / config.py
blob45ffe3664cb513120e1941ddb2367e624b89840b
1 #!/usr/bin/env python
3 import os
5 def read(path="config"):
6 """Reads in the specified file
8 The file is expected to have the following format:
9 .*
10 [GitStats]\n
11 key = value
12 key2 = value2
16 Args:
17 path: The location of the file to read in
19 Returns: A dictionary with the key:value pairs specified in the file.
20 """
22 config = {}
24 if not os.path.isfile(path):
25 return config
27 file = open(path)
28 lines = file.readlines()
30 # Find our verse
31 pos = lines.index("[GitStats]\n")
33 # Kick off the header
34 pos += 1
35 lines = lines[pos:]
37 for line in lines:
38 # Remove spaces and newlines
39 stripline = line.lstrip().rstrip()
41 if stripline == line or not stripline:
42 break
44 # Extract the key:value pair
45 splitline = stripline.split(' = ')
46 key = splitline[0].rstrip()
47 value = splitline[1].lstrip()
49 config[key] = value
51 return config
53 if __name__ == '__main__':
54 result = read()
56 for key, value in result.iteritems():
57 print(key + ": " + value)