# Path: giraffez/encrypt.py
# class Crypto(object):
#     def __init__(self, key, bs=16): 
#         self.key = hashlib.sha256(key).digest()
#         self.bs = bs
# 
#     def decrypt(self, enc):
#         enc = base64.b64decode(enc)
#         iv = enc[:self.bs]
#         cipher = AES.new(self.key, AES.MODE_CBC, iv)
#         return self.unpad(cipher.decrypt(enc[self.bs:])).decode("utf-8")
# 
#     def encrypt(self, raw):
#         raw = self.pad(raw).encode("utf-8")
#         iv = os.urandom(self.bs)
#         cipher = AES.new(self.key, AES.MODE_CBC, iv)
#         return base64.b64encode(iv + cipher.encrypt(raw))
# 
#     def pad(self, s):
#         return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
# 
#     def unpad(self, s):
#         return s[:-ord(s[len(s)-1:])]
# 
#     @classmethod
#     def from_key_file(cls, path):
#         with open(path, "rb") as f:
#             return cls(base64.b64decode(f.read()))
# 
# Path: giraffez/io.py
# def file_exists(path):
#     try:
#         with open(path):
#             return True
#     except (OSError, IOError):
#         return False
# 
# def file_permissions(path):
#     return os.stat(path).st_mode & 0o777
# 
# def home_file(filename):
#     return os.path.join(os.path.expanduser("~"), filename)
# 
# Path: giraffez/logging.py
# def run_once(f):
#     def wrapper(*args, **kwargs):
# def setup_logging():
#     def colorize(cls, color, s):
#     def blue(cls, s):
#     def green(cls, s):
#     def gray(cls, s):
#     def white(cls, s):
#     def disabled(cls, s):
#     def bold(cls, s):
#     def fail(cls, s):
# def highlight(s):
#     def __init__(self, fd=None, level=INFO):
#     def level(self):
#     def level(self, v):
#     def _write(self, args, level=None, console=False):
#     def write(self, *args, **kwargs):
#     def info(self, *args, **kwargs):
#     def verbose(self, *args, **kwargs):
#     def debug(self, *args, **kwargs):
#     def fatal(self, msg=""):
#     def __init__(self, fd=None, level=INFO):
#     def _write(self, args, level=None, console=True):
# CONSOLE_HEADER = "\033[95m"
# CONSOLE_BLUE = "\033[94m"
# CONSOLE_GREEN = "\033[92m"
# CONSOLE_GRAY = "\033[37m"
# CONSOLE_WHITE = "\033[97m"
# CONSOLE_WARNING = "\033[93m"
# CONSOLE_ENDC = "\033[0m"
# CONSOLE_FAIL = "\033[91m"
# CONSOLE_BOLD = "\033[1m"
# CONSOLE_UNDERLINE = "\033[4m" 
# CONSOLE_DISABLED = "\033[38;5;240m" 
# class colors(object):
# class Logger(object):
# class LockingLogger(Logger):


import os
import sys
import base64
import yaml
from .errors import *
from .encrypt import Crypto
from .io import file_exists, file_permissions, home_file
from .logging import log, colors
from ._compat import *
    giraffez config --set connections.db1.username <username>
    giraffez config --set connections.db1.password <password>"""

default_config = {
    "connections": {
        "default": "db1",
        "db1": {
            "host": None,
            "username": None,
            "password": None
        }
    },
    "colorful": True
}

def _get_config_file(conf=None):
    if conf is None:
        conf = home_file(".girafferc")
    else:
        conf = os.path.abspath(conf)
    if not file_exists(conf):
        raise ConfigNotFound(("Config file '{}' does not exist and credentials were not "
            "otherwise specified.").format(conf))
    return conf

def _get_key_file(key_file=None):
    if key_file is None:
        key_file = home_file(".giraffepg")
    else:
        key_file = os.path.abspath(key_file)

# Path: giraffez/encrypt.py
# class Crypto(object):
#     def __init__(self, key, bs=16): 
#         self.key = hashlib.sha256(key).digest()
#         self.bs = bs
# 
#     def decrypt(self, enc):
#         enc = base64.b64decode(enc)
#         iv = enc[:self.bs]
#         cipher = AES.new(self.key, AES.MODE_CBC, iv)
#         return self.unpad(cipher.decrypt(enc[self.bs:])).decode("utf-8")
# 
#     def encrypt(self, raw):
#         raw = self.pad(raw).encode("utf-8")
#         iv = os.urandom(self.bs)
#         cipher = AES.new(self.key, AES.MODE_CBC, iv)
#         return base64.b64encode(iv + cipher.encrypt(raw))
# 
#     def pad(self, s):
#         return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
# 
#     def unpad(self, s):
#         return s[:-ord(s[len(s)-1:])]
# 
#     @classmethod
#     def from_key_file(cls, path):
#         with open(path, "rb") as f:
#             return cls(base64.b64decode(f.read()))
# 
# Path: giraffez/io.py
# def file_exists(path):
#     try:
#         with open(path):
#             return True
#     except (OSError, IOError):
#         return False
# 
# def file_permissions(path):
#     return os.stat(path).st_mode & 0o777
# 
# def home_file(filename):
#     return os.path.join(os.path.expanduser("~"), filename)
# 
# Path: giraffez/logging.py
# def run_once(f):
#     def wrapper(*args, **kwargs):
# def setup_logging():
#     def colorize(cls, color, s):
#     def blue(cls, s):
#     def green(cls, s):
#     def gray(cls, s):
#     def white(cls, s):
#     def disabled(cls, s):
#     def bold(cls, s):
#     def fail(cls, s):
# def highlight(s):
#     def __init__(self, fd=None, level=INFO):
#     def level(self):
#     def level(self, v):
#     def _write(self, args, level=None, console=False):
#     def write(self, *args, **kwargs):
#     def info(self, *args, **kwargs):
#     def verbose(self, *args, **kwargs):
#     def debug(self, *args, **kwargs):
#     def fatal(self, msg=""):
#     def __init__(self, fd=None, level=INFO):
#     def _write(self, args, level=None, console=True):
# CONSOLE_HEADER = "\033[95m"
# CONSOLE_BLUE = "\033[94m"
# CONSOLE_GREEN = "\033[92m"
# CONSOLE_GRAY = "\033[37m"
# CONSOLE_WHITE = "\033[97m"
# CONSOLE_WARNING = "\033[93m"
# CONSOLE_ENDC = "\033[0m"
# CONSOLE_FAIL = "\033[91m"
# CONSOLE_BOLD = "\033[1m"
# CONSOLE_UNDERLINE = "\033[4m" 
# CONSOLE_DISABLED = "\033[38;5;240m" 
# class colors(object):
# class Logger(object):
# class LockingLogger(Logger):


# Path: giraffez/config.py
import os
import sys
import base64
import yaml
from .errors import *
from .encrypt import Crypto
from .io import file_exists, file_permissions, home_file
from .logging import log, colors
from ._compat import *

    giraffez config --set connections.db1.username <username>
    giraffez config --set connections.db1.password <password>"""

default_config = {
    "connections": {
        "default": "db1",
        "db1": {
            "host": None,
            "username": None,
            "password": None
        }
    },
    "colorful": True
}

def _get_config_file(conf=None):
    if conf is None:
        conf = home_file(".girafferc")
    else:
        conf = os.path.abspath(conf)
    if not file_exists(conf):
        raise ConfigNotFound(("Config file '{}' does not exist and credentials were not "
            "otherwise specified.").format(conf))
    return conf

def _get_key_file(key_file=None):
    if key_file is None:
        key_file = home_file(".giraffepg")
    else:
        key_file = os.path.abspath(key_file)

    if not file_exists(key_file):