<commit_before>#! /usr/bin/env python3

from pathlib import Path
import sys
name="name"
target="target"

files=[
    {name:"config_files/bash_aliases",   target:"~/.bash_aliases"},
    {name:"config_files/bash_ps1",       target:"~/.bash_ps1"},
    {name:"config_files/vimrc",          target:"~/.vim/vimrc"},
    {name:"config_files/vim-build",          target:"~/.local/bin/vim-build"},
    {name:"config_files/vim_packages",   target:"~/.vim/vim_packages"},
    {name:"config_files/inputrc",        target:"~/.inputrc"},
    {name:"config_files/screenrc",        target:"~/.screenrc"},
    {name:"config_files/tmux.conf",      target:"~/.tmux.conf"},
    {name:"config_giles/global_makefile",target:"~/.global_makefile"},
    ]

def link(filename, target):
    target_path = Path(target).expanduser()
    source_path = Path(filename).expanduser()
    if (not source_path.exists()):
        print("[%16s] -> [%s] Not linked. Source missing" %(source_path, target_path))
        return
    if (target_path.exists()):
        print("[%16s] -> [%s] Not linked. Target exists" %(source_path, target_path))
        return
    if (target_path.is_symlink()):
        print("[%16s] -> [%s] Target exist and is symlink" %(source_path, target_path))
        if (query_yes_no("Remove and remake? ")):
            target_path.unlink()
            print("[%16s] -> [%s] Target old link removed" %(source_path, target_path))
        else:
            return
    if (not target_path.parent.exists()):
        print("[%16s] -> [%s] Creating missing parent directory" %(source_path, target_path))
        target_path.parent.mkdir(parents=True);
    target_path.symlink_to(source_path.resolve())
    print("[%16s] -> [%s] symlink created successfully" %(source_path, target_path))
    

def query_yes_no(question, default="yes"):
    """Ask a yes/no question via raw_input() and return their answer.
    
    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "no" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "no".
    code source: http://code.activestate.com/recipes/577058/
    """
    valid = {"yes":"yes",   "y":"yes",  "ye":"yes",
             "no":"no",     "n":"no"}
    valid_true = {"yes":"yes",   "y":"yes",  "ye":"yes"}
    if default == None:
        prompt = " [y/n] "<commit_msg>Added version check to linkall<commit_after>#! /usr/bin/env python3

from pathlib import Path
import sys
if sys.version_info[0] < 3 or sys.version_info[1] < 5:
    raise "Must be greater than or equal to Python 3.5 to run this script"
name="name"
target="target"

files=[
    {name:"config_files/bash_aliases",   target:"~/.bash_aliases"},
    {name:"config_files/bash_ps1",       target:"~/.bash_ps1"},
    {name:"config_files/vimrc",          target:"~/.vim/vimrc"},
    {name:"config_files/vim-build",          target:"~/.local/bin/vim-build"},
    {name:"config_files/vim_packages",   target:"~/.vim/vim_packages"},
    {name:"config_files/inputrc",        target:"~/.inputrc"},
    {name:"config_files/screenrc",        target:"~/.screenrc"},
    {name:"config_files/tmux.conf",      target:"~/.tmux.conf"},
    {name:"config_giles/global_makefile",target:"~/.global_makefile"},
    ]

def link(filename, target):
    target_path = Path(target).expanduser()
    source_path = Path(filename).expanduser()
    if (not source_path.exists()):
        print("[%16s] -> [%s] Not linked. Source missing" %(source_path, target_path))
        return
    if (target_path.exists()):
        print("[%16s] -> [%s] Not linked. Target exists" %(source_path, target_path))
        return
    if (target_path.is_symlink()):
        print("[%16s] -> [%s] Target exist and is symlink" %(source_path, target_path))
        if (query_yes_no("Remove and remake? ")):
            target_path.unlink()
            print("[%16s] -> [%s] Target old link removed" %(source_path, target_path))
        else:
            return
    if (not target_path.parent.exists()):
        print("[%16s] -> [%s] Creating missing parent directory" %(source_path, target_path))
        target_path.parent.mkdir(parents=True);
    target_path.symlink_to(source_path.resolve())
    print("[%16s] -> [%s] symlink created successfully" %(source_path, target_path))


def query_yes_no(question, default="yes"):
    """Ask a yes/no question via raw_input() and return their answer.

    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "no" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "no".
    code source: http://code.activestate.com/recipes/577058/
    """
    valid = {"yes":"yes",   "y":"yes",  "ye":"yes",
             "no":"no",     "n":"no"}
    valid_true = {"yes":"yes",   "y":"yes",  "ye":"yes"}
    if default == None:
        prompt = " [y/n] "
{'fraction_non_alphanumeric': 0.1711229946524064, 'fraction_numerical': 0.009506833036244802, 'mean_word_length': 3.139344262295082, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6661359', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1654, 'n_words': 392}