From a569c53eac56906e9df9e97a18a4765ffd9e9069 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Tue, 15 Jul 2008 17:58:59 +0200 Subject: [PATCH] gitstats: Teach config.py to read multiple verses When there are multiple GitStats verses in one file we should read them all as one. This commit does so. --- src/git_stats/config.py | 72 +++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/git_stats/config.py b/src/git_stats/config.py index e64d301..75724dc 100644 --- a/src/git_stats/config.py +++ b/src/git_stats/config.py @@ -41,40 +41,11 @@ def readAll(convert_camel_case=True): return result -def read(path, convert_camel_case=True): - """Reads in the specified file - - Understands 'True', 'False', 'None' and integer values. - All camelCase keys are converted to dashed_form. - The file is expected to have the following format: - .* - [GitStats]\n - [key = value\n]* - - .* - - Args: - path: The location of the file to read in - - Returns: A dictionary with the key:value pairs specified in the file. +def _readVerse(verse, config, convert_camel_case): + """Reads in a verse from a config file and stores the result in config """ - config = {} - - file = open(path) - lines = file.readlines() - - # Find our verse - try: - pos = lines.index("[GitStats]\n") - except ValueError: - return config - - # Kick off the header - pos += 1 - lines = lines[pos:] - - for line in lines: + for line in verse: # Remove spaces and newlines stripline = line.lstrip().rstrip() @@ -115,6 +86,43 @@ def read(path, convert_camel_case=True): config[key] = value + +def read(path, convert_camel_case=True): + """Reads in the specified file + + Understands 'True', 'False', 'None' and integer values. + All camelCase keys are converted to dashed_form. + The file is expected to have the following format: + .* + [GitStats]\n + [key = value\n]* + + .* + + Args: + path: The location of the file to read in + + Returns: A dictionary with the key:value pairs specified in the file. + """ + + config = {} + + file = open(path) + lines = file.readlines() + + while True: + # Find our verse + try: + pos = lines.index("[GitStats]\n") + except ValueError: + return config + + # Kick off the header + pos += 1 + lines = lines[pos:] + + _readVerse(lines, config, convert_camel_case) + return config if __name__ == '__main__': -- 2.11.4.GIT