"""
fourGet is script that works with hashes of git projects.
You can create 'aliases' to reuse projects under other pseudonyms or hashes.
When author changed his nickname of renamed project it can be noted here as well.
When we now about name changes, git project can be easily reused.
Alias and Pseudonyms will be stored at ~/.local/4g/aliases.db sqlite database.
"""

import hashlib, os, sys

from pathlib import Path

home = Path.home()
fourHome = home / ".local/share/4g/home"
# DB with all aliases to reuse git sources
fourAliases = fourHome / "aliases.db"
# Git Sources or local git projects
fourSources = fourHome / "src"
projects = home / "Projects" / "4g"

def mkdirs(dir):
    try:
        os.makedirs(str(dir))
    except:
        pass

mkdirs(fourSources)
mkdirs(projects)

print(str(fourHome))

def hashedString(s, hashTool="sha256"):
    h = hashlib.new(hashTool)
    h.update(s.encode()) # give a encoded string. Makes the String to the Hash 
    return h.hexdigest() # Return the Hash

def hashForgySource(url, hashTool="md5"):
    urlHash = hashedString(url, hashTool)
    gitName = url.split("/")[-1]
    return f"{gitName}@{urlHash}"

