# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


import datetime
import os
import core.globals
from interface.messages import print_error, print_info
# This file is part of REXT
# core.io.py - Input / Output utils, for writing files and databases
# Author: Ján Trenčanský
# License: GNU GPL v3



# FIXME: If minute changes between two writes of one module, this will create two directories
def writefile(stream, filename):
    dirpath = "output/" + core.globals.active_script + "_" + datetime.datetime.today().strftime('%Y-%b-%d-%H:%M')
    try:
        if not os.path.exists(dirpath):
            os.mkdir(dirpath)
        open(dirpath + "/" + filename, 'wb').write(stream)
        return dirpath
    except OSError:
        print_error("Unable to create directory")


def writetextfile(text, filename):
    dirpath = "output/" + core.globals.active_script + "_" + datetime.datetime.today().strftime('%Y-%b-%d-%H:%M')
    try:
        if not os.path.exists(dirpath):
            os.mkdir(dirpath)
        open(dirpath + "/" + filename, 'w').write(text)
        return dirpath
    except OSError:

# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


# Path: core/io.py
import datetime
import os
import core.globals
from interface.messages import print_error, print_info

# This file is part of REXT
# core.io.py - Input / Output utils, for writing files and databases
# Author: Ján Trenčanský
# License: GNU GPL v3



# FIXME: If minute changes between two writes of one module, this will create two directories
def writefile(stream, filename):
    dirpath = "output/" + core.globals.active_script + "_" + datetime.datetime.today().strftime('%Y-%b-%d-%H:%M')
    try:
        if not os.path.exists(dirpath):
            os.mkdir(dirpath)
        open(dirpath + "/" + filename, 'wb').write(stream)
        return dirpath
    except OSError:
        print_error("Unable to create directory")


def writetextfile(text, filename):
    dirpath = "output/" + core.globals.active_script + "_" + datetime.datetime.today().strftime('%Y-%b-%d-%H:%M')
    try:
        if not os.path.exists(dirpath):
            os.mkdir(dirpath)
        open(dirpath + "/" + filename, 'w').write(text)
        return dirpath
    except OSError:

        print_error("Unable to create directory")