import os
import re
from mako.template import Template
from mako.lookup import TemplateLookup
from colorama import Fore, Back, Style

def comment(str):
    print(Fore.GREEN + str + Fore.RESET )

class Generator:
    def __init__(self, package_dir, out_dir = ""):
        self.template_dir = os.path.join(package_dir, 'templates')
        self.out_dir  = out_dir
        self.out_file = None

    def outputs(self, filename):
        self.out_file = open(os.path.join(self.out_dir, filename), 'w')
        return self

    def prints(self):
        self.out_file = None
        return self

    def template(self, templ, **kwargs):
        out = Template(filename=os.path.join(self.template_dir,  templ + '.tmp')).render(**kwargs)
        if self.out_file:
            self.out_file.write(out)
        else:
            print(out)

def convert_size_to_bytes(size):
    bytes = int(re.findall(r'\d+', size)[0])
    if 'MB' in size:
        return bytes * 1024 * 1024
    elif 'KB' in size:
        return bytes * 1024
    else:
        return bytes

