Remove setup_file, add deploy_list.json

This commit is contained in:
Ferit Yiğit BALABAN 2023-02-09 14:05:36 +03:00
parent 454d1a3870
commit 7de29c4333

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# Ferit Yiğit BALABAN <f@fybx.dev>, 2022 # Ferit Yiğit BALABAN <f@fybx.dev>, 2023
# #
import os.path import os.path
from subprocess import run from subprocess import run
@ -11,16 +11,17 @@ from termcolor import colored, cprint
# Modify SETTINGS dictionary to set runtime variables # Modify SETTINGS dictionary to set runtime variables
# Access values in dictionary using pre-defined names # Access values in dictionary using pre-defined names
SETTINGS = { SETTINGS = {
'DOTFILES_REPOSITORY': '$HOME/repos/dotfiles', 'URL_REPO': 'https://github.com/fybx/dotfiles',
'REMOTE_REPOSITORY': 'https://github.com/fybx/dotfiles', 'DIR_REPO': '$HOME/repos/dotfiles',
'LOCAL_CONFIG': '$HOME/.config', 'DIR_CONF': '$HOME/.config',
'SETUP_FILE': 'same-directory' 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json',
} }
WHEREAMI = '$HOME/scripts' WHEREAMI = '$HOME/scripts'
VER = 'v1.7' VER = 'v1.8'
WER = 'v1.1' WER = 'v1.1'
help_message = f''' help_message = f'''
dotman {VER} dotfiles manager by fyb dotman {VER} dotfiles manager by ferityigitbalaban
Unrecognized keys are ignored. If every key supplied is unrecognized, Unrecognized keys are ignored. If every key supplied is unrecognized,
this have the same effect as calling dotman without any key. this have the same effect as calling dotman without any key.
@ -35,6 +36,10 @@ Keys:
''' '''
DL_FILES = []
DL_DIRS = []
def get_nth_key(n: int, d: dict[str, str]): def get_nth_key(n: int, d: dict[str, str]):
c = 0 c = 0
for k in d.keys(): for k in d.keys():
@ -50,18 +55,25 @@ def read_file(path: str):
return content return content
def read_setup(): def read_deploy_list():
path = SETTINGS['SETUP_FILE'] """
lines = read_file(f'{WHEREAMI}setup.dtm') if path == 'same-directory' else read_file(os.path.expandvars(path)) Reads file from SETTINGS.F_DEPLOY to get list of directories and files to deploy
lines = [line.strip() for line in lines if not line.startswith('#') and line.replace(' ', '') != ''] """
for line in lines: path_deploy_list = SETTINGS['F_DEPLOY']
key = line.split(':', 1)[0].rstrip() if os.path.exists(path_deploy_list):
value = line.split(':', 1)[1].lstrip() with open(path_deploy_list, 'r') as f:
SETTINGS[key] = value file = f.read()
f.close()
dict_deploy_list = json.loads(file)
DL_FILES = dict_deploy_list['files']
DL_DIRS = dict_deploy_list['dirs']
def write_setup(): def create_deploy_list():
path = f'{WHEREAMI}setup.dtm' if SETTINGS['SETUP_FILE'] == 'same-directory' else os.path.expandvars(SETTINGS['SETUP_FILE']) """
Creates the default deploy_list.json in path SETTINGS.F_DEPLOY
"""
default = {}
def rrem(text: str, char: str): def rrem(text: str, char: str):