Rename and refactor utility method

This commit is contained in:
Ferit Yiğit BALABAN 2022-04-03 02:50:21 +03:00
parent 5c1871bb1d
commit 46f26b19d5
No known key found for this signature in database
GPG Key ID: BB8494BA65A90842

View File

@ -60,10 +60,16 @@ def read_setup():
SETTINGS[key] = value 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 iterator = len(text) - 1
buffer = '' buffer = ''
while text[iterator] != '/': while text[iterator] != char:
buffer += text[iterator] buffer += text[iterator]
iterator -= 1 iterator -= 1
return text.removesuffix(buffer[::-1]) return text.removesuffix(buffer[::-1])
@ -87,12 +93,8 @@ def print_settings():
count += 1 count += 1
def prclr(text, color):
cprint(text, color, end='')
def grab_dotfiles(): 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']) code, output = proc(f"git clone {SETTINGS['REMOTE_REPOSITORY']}", SETTINGS['DOTFILES_REPOSITORY'])
return code == 0, code return code == 0, code
@ -145,7 +147,7 @@ def commit_then_push():
def main(): def main():
global WHEREAMI global WHEREAMI
WHEREAMI = remove_from_left_until_slash(sys.argv[0]) WHEREAMI = rrem(sys.argv[0], '/')
read_setup() read_setup()
SETTINGS['DOTFILES_REPOSITORY'] = os.path.expandvars(SETTINGS['DOTFILES_REPOSITORY']) SETTINGS['DOTFILES_REPOSITORY'] = os.path.expandvars(SETTINGS['DOTFILES_REPOSITORY'])
SETTINGS['LOCAL_CONFIG'] = os.path.expandvars(SETTINGS['LOCAL_CONFIG']) SETTINGS['LOCAL_CONFIG'] = os.path.expandvars(SETTINGS['LOCAL_CONFIG'])