From 46f26b19d51bf799eb7747c1ed52f3a93a1ad911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sun, 3 Apr 2022 02:50:21 +0300 Subject: [PATCH] Rename and refactor utility method --- dotman.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/dotman.py b/dotman.py index 0635109..cc550a0 100755 --- a/dotman.py +++ b/dotman.py @@ -60,10 +60,16 @@ def read_setup(): SETTINGS[key] = value -def remove_from_left_until_slash(text): +def rrem(text: str, char: str): + """ + Remove characters from right until character supplied with char + :param text: Where to remove characters from + :param char: Which character to stop removing at + :return: Returns text with all characters until specified character removed + """ iterator = len(text) - 1 buffer = '' - while text[iterator] != '/': + while text[iterator] != char: buffer += text[iterator] iterator -= 1 return text.removesuffix(buffer[::-1]) @@ -87,12 +93,8 @@ def print_settings(): count += 1 -def prclr(text, color): - cprint(text, color, end='') - - def grab_dotfiles(): - os.mkdir(remove_from_left_until_slash(SETTINGS['DOTFILES_REPOSITORY'])) + os.mkdir(rrem(SETTINGS['DOTFILES_REPOSITORY'], '/')) code, output = proc(f"git clone {SETTINGS['REMOTE_REPOSITORY']}", SETTINGS['DOTFILES_REPOSITORY']) return code == 0, code @@ -145,7 +147,7 @@ def commit_then_push(): def main(): global WHEREAMI - WHEREAMI = remove_from_left_until_slash(sys.argv[0]) + WHEREAMI = rrem(sys.argv[0], '/') read_setup() SETTINGS['DOTFILES_REPOSITORY'] = os.path.expandvars(SETTINGS['DOTFILES_REPOSITORY']) SETTINGS['LOCAL_CONFIG'] = os.path.expandvars(SETTINGS['LOCAL_CONFIG'])