# Path: modules/get_banner.py
# def get_banner(game_name, url, banner_path, lib):
# 
#     banner_req = urllib_request(url)
# 
#     try:
# 
#         if not os.path.exists(banner_path):
#             os.makedirs(banner_path)
# 
#         banner_data = urllib_urlopen(banner_req).read()
#         banner_file = open(banner_path + '/' + game_name + '.jpg', 'wb')
#         banner_file.write(banner_data)
#         banner_file.close()
# 
#         pic_src = Image.open(banner_path + '/' + game_name + '.jpg')
#         pic = pic_src.resize((518, 240), PIL.Image.ANTIALIAS)
#         pic.save(banner_path + '/' + game_name + '.jpg')
# 
#         if lib == 'goglib':
# 
#             if not os.path.exists(banner_path + '/unavailable/'):
#                 os.makedirs(banner_path + '/unavailable/')
# 
#             new_pic = Image.open(banner_path + '/' + game_name + '.jpg')
#             pic_grey = new_pic.convert('L')
#             pic_grey.save(banner_path + '/unavailable/' + game_name + '.jpg')
# 
#     except urllib_urlerror as e:
#         print(e.reason)
#     except urllib_httperror as e:
#         print(e.code)
#         print(e.read())


import os, sys
    import sys
    from ConfigParser import ConfigParser as ConfigParser
    from configparser import ConfigParser as ConfigParser
from modules import get_banner
try:
except:


nebula_dir = sys.path[0]

def autosetup(lib, install_dir, game_name):

    parser = ConfigParser()

    if lib == 'goglib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/goglib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/goglib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/goglib/autosetup.ini'
    elif lib == 'mylib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/mylib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/mylib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/mylib/autosetup.ini'

    if os.path.exists(path_0):
        parser.read(path_0)
    else:
        parser.read(path_1)

    if (os.path.exists(install_dir + '/' + game_name)) and (parser.has_section(game_name)):

        if parser.has_option(game_name, 'image'):
            image = parser.get(game_name, 'image')
            if image != '':
                print("Downloading image")

# Path: modules/get_banner.py
# def get_banner(game_name, url, banner_path, lib):
# 
#     banner_req = urllib_request(url)
# 
#     try:
# 
#         if not os.path.exists(banner_path):
#             os.makedirs(banner_path)
# 
#         banner_data = urllib_urlopen(banner_req).read()
#         banner_file = open(banner_path + '/' + game_name + '.jpg', 'wb')
#         banner_file.write(banner_data)
#         banner_file.close()
# 
#         pic_src = Image.open(banner_path + '/' + game_name + '.jpg')
#         pic = pic_src.resize((518, 240), PIL.Image.ANTIALIAS)
#         pic.save(banner_path + '/' + game_name + '.jpg')
# 
#         if lib == 'goglib':
# 
#             if not os.path.exists(banner_path + '/unavailable/'):
#                 os.makedirs(banner_path + '/unavailable/')
# 
#             new_pic = Image.open(banner_path + '/' + game_name + '.jpg')
#             pic_grey = new_pic.convert('L')
#             pic_grey.save(banner_path + '/unavailable/' + game_name + '.jpg')
# 
#     except urllib_urlerror as e:
#         print(e.reason)
#     except urllib_httperror as e:
#         print(e.code)
#         print(e.read())


# Path: modules/autosetup.py
import os, sys
    import sys
    from ConfigParser import ConfigParser as ConfigParser
    from configparser import ConfigParser as ConfigParser
from modules import get_banner

try:
except:


nebula_dir = sys.path[0]

def autosetup(lib, install_dir, game_name):

    parser = ConfigParser()

    if lib == 'goglib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/goglib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/goglib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/goglib/autosetup.ini'
    elif lib == 'mylib':
        banners_dir = os.getenv('HOME') + '/.games_nebula/images/mylib/'
        path_0 = os.getenv('HOME') + '/.games_nebula/scripts/mylib/autosetup.ini'
        path_1 = nebula_dir + '/scripts/mylib/autosetup.ini'

    if os.path.exists(path_0):
        parser.read(path_0)
    else:
        parser.read(path_1)

    if (os.path.exists(install_dir + '/' + game_name)) and (parser.has_section(game_name)):

        if parser.has_option(game_name, 'image'):
            image = parser.get(game_name, 'image')
            if image != '':
                print("Downloading image")

                get_banner.get_banner(game_name, image, banners_dir, lib)