# Path: xdfile/utils.py
# def log(s, minverbose=0, severity='INFO'):
#     # This can be made in more Python way
#     if g_logfp.isatty(): # Colors only for atty term
#         if severity.lower() == 'warning':
#             s = bcolors.WARNING + s + bcolors.ENDC
#         if severity.lower() == 'error':
#             s = bcolors.FAIL + s + bcolors.ENDC
# 
#     if g_logfp:
#         g_logfp.write("%s: %s\n" % (severity.upper(), s))
#     g_logs.append("%s: [%s] %s" % (g_currentProgress or g_scriptname, severity.upper(), s))
# 
# def info(_s, _m=0):
#     log(_s, minverbose=_m, severity='info')
# 
# def debug(s):
#     if g_args.debug:
#         print(" " + s)
# 
# def error(_s, _m=0):
#     log(_s, minverbose=_m, severity='error')


import os
import boto3
    import urllib.request
    import urllib.parse
from xdfile.utils import log, info, debug, error



boto3.set_stream_logger('botocore')

def xd_send_email(destaddr, fromaddr='admin@xd.saul.pw', subject='', body=''):
    client = boto3.client('ses', region_name=os.environ['REGION'])
    info("sending email to %s (subject '%s')" % (destaddr, subject))
    try:
        response = client.send_email(
                Source=fromaddr,
                Destination= {'ToAddresses': [ destaddr ] },
                Message={ 'Subject': { 'Data': subject },
                'Body': { 'Text': { 'Data': body } } })
        return response
    except Exception as e:
        error("xd_send_email(): %s" % str(e))
        return None


def create_merge_request():
    parms = {
        'id': '',
        'source_branch': '',
        'target_branch': '',
        'title': '',
    }

    url = 'https://gitlab.com/projects/:id/merge_requests'
    r = urllib.request.urlopen(url, urllib.parse.urlencode(parms))

# Path: xdfile/utils.py
# def log(s, minverbose=0, severity='INFO'):
#     # This can be made in more Python way
#     if g_logfp.isatty(): # Colors only for atty term
#         if severity.lower() == 'warning':
#             s = bcolors.WARNING + s + bcolors.ENDC
#         if severity.lower() == 'error':
#             s = bcolors.FAIL + s + bcolors.ENDC
# 
#     if g_logfp:
#         g_logfp.write("%s: %s\n" % (severity.upper(), s))
#     g_logs.append("%s: [%s] %s" % (g_currentProgress or g_scriptname, severity.upper(), s))
# 
# def info(_s, _m=0):
#     log(_s, minverbose=_m, severity='info')
# 
# def debug(s):
#     if g_args.debug:
#         print(" " + s)
# 
# def error(_s, _m=0):
#     log(_s, minverbose=_m, severity='error')


# Path: xdfile/cloud.py
import os
import boto3
    import urllib.request
    import urllib.parse
from xdfile.utils import log, info, debug, error




boto3.set_stream_logger('botocore')

def xd_send_email(destaddr, fromaddr='admin@xd.saul.pw', subject='', body=''):
    client = boto3.client('ses', region_name=os.environ['REGION'])
    info("sending email to %s (subject '%s')" % (destaddr, subject))
    try:
        response = client.send_email(
                Source=fromaddr,
                Destination= {'ToAddresses': [ destaddr ] },
                Message={ 'Subject': { 'Data': subject },
                'Body': { 'Text': { 'Data': body } } })
        return response
    except Exception as e:
        error("xd_send_email(): %s" % str(e))
        return None


def create_merge_request():
    parms = {
        'id': '',
        'source_branch': '',
        'target_branch': '',
        'title': '',
    }

    url = 'https://gitlab.com/projects/:id/merge_requests'
    r = urllib.request.urlopen(url, urllib.parse.urlencode(parms))

    info('create_merge_request POST: %s' % r.getcode())