#!/usr/bin/python3
from kiwi.install import WindowsInstallApp
import logging
import logging.handlers
import sys
import configparser
import urllib.request
from urllib.error import HTTPError, URLError

config_url = 'http://10.10.200.1/linux/kiwi/kiwi.conf'
config_timeout=0.1

logger = logging.getLogger()
logger.setLevel(logging.INFO)

fh = logging.FileHandler('/tmp/kiwi-install.log')
logger.addHandler(fh)

configdata = None

try:
    configdata = urllib.request.urlopen(config_url, timeout=config_timeout).read().decode('UTF-8')
except (HTTPError, URLError):
    logger.warning('Unable to fetch config file from URL {}'.format(config_url))
except socket.timeout:
    logger.warning('Socket timed out while trying to fetch config')

config = configparser.ConfigParser()
config.read_string(configdata)

app = WindowsInstallApp(config)
