From 5ca6f877204d66b8e2d40fdbb2d217840766aca2 Mon Sep 17 00:00:00 2001 From: smittytone Date: Tue, 26 Feb 2019 08:50:04 +0000 Subject: [PATCH] Add comment-line remover Accessed by _load_config_file() --- gitup/config.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gitup/config.py b/gitup/config.py index 0e1e069..51cb4f0 100644 --- a/gitup/config.py +++ b/gitup/config.py @@ -37,8 +37,27 @@ def _load_config_file(config_path=None): except IOError: return [] paths = [path.decode("utf8").strip() for path in paths] + paths = _strip_comment_lines(paths) return [path for path in paths if path] +def _strip_comment_lines(paths): + """Remove any lines starting with #.""" + i = 0 + while i < len(paths): + path = paths[i] + removed_comment = False + for j in range(0, len(path)): + path_char = path[j] + if path_char == " ": + continue + if path_char == "#": + removed_comment = True + paths.pop(i) + break + if removed_comment is False: + i = i + 1 + return paths + def _save_config_file(bookmarks, config_path=None): """Save the bookmarks list to the given config file.""" run_migrations()