From 5ca6f877204d66b8e2d40fdbb2d217840766aca2 Mon Sep 17 00:00:00 2001 From: smittytone Date: Tue, 26 Feb 2019 08:50:04 +0000 Subject: [PATCH 1/2] 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() From da701bc09b1c3911cd7c3707276af3cc52357541 Mon Sep 17 00:00:00 2001 From: smittytone Date: Tue, 26 Feb 2019 12:17:11 +0000 Subject: [PATCH 2/2] Remove comment finder Put it in a better place... --- gitup/config.py | 19 ------------------- gitup/update.py | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/gitup/config.py b/gitup/config.py index 51cb4f0..0e1e069 100644 --- a/gitup/config.py +++ b/gitup/config.py @@ -37,27 +37,8 @@ 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() diff --git a/gitup/update.py b/gitup/update.py index 051ef00..123fff7 100644 --- a/gitup/update.py +++ b/gitup/update.py @@ -21,6 +21,7 @@ BOLD = Style.BRIGHT BLUE = Fore.BLUE + BOLD GREEN = Fore.GREEN + BOLD RED = Fore.RED + BOLD +CYAN = Fore.CYAN + BOLD YELLOW = Fore.YELLOW + BOLD RESET = Style.RESET_ALL @@ -256,11 +257,17 @@ def _dispatch(base_path, callback, args): Repo(base) valid = [base] except exc.NoSuchPathError: - paths = glob(base) - if not paths: - print(ERROR, BOLD + base, "doesn't exist!") + if is_comment(base): + comment = get_comment(base) + if len(comment) > 0: + print(CYAN + BOLD + comment) return - valid = _collect(paths, max_depth) + else: + paths = glob(base) + if not paths: + print(ERROR, BOLD + base, "doesn't exist!") + return + valid = _collect(paths, max_depth) except exc.InvalidGitRepositoryError: if not os.path.isdir(base) or args.max_depth == 0: print(ERROR, BOLD + base, "isn't a repository!") @@ -276,6 +283,27 @@ def _dispatch(base_path, callback, args): for name, path in sorted(paths): callback(Repo(path), name, args) +def is_comment(path): + """Does the line start with a # symbol?""" + cs = path.lstrip() + if cs[0] == "#": + return True + return False + +def get_comment(path): + """Return the string minus the comment symbol.""" + rs = "" + cs = path.lstrip() + if len(cs) > 0: + for j in range(0, len(cs)): + c = cs[j] + if c == "#" and len(rs) == 0: + continue + rs = rs + c + if len(rs) > 0: + rs = rs.lstrip() + return rs + def update_bookmarks(bookmarks, args): """Loop through and update all bookmarks.""" if not bookmarks: