# Path: static_aid/config.py
# ROOT = realpath(curdir)
# CONFIG_DEFAULTS_FILE_PATH = join(ROOT, 'local_settings.default')
#     ROOT = realpath(join(dirname(__file__), '..'))
#     CONFIG_DEFAULTS_FILE_PATH = join(ROOT, 'local_settings.default')
# CONFIG_FILE_PATH = join(ROOT, 'local_settings.cfg')
# SAMPLE_DATA_DIR = join(ROOT, 'data')
# SITE_SRC_DIR = join(ROOT, 'site')
# BUILD_DIR = join(ROOT, 'build')
# DATA_DIR = join(BUILD_DIR, 'data')
# STAGING_DIR = join(BUILD_DIR, 'staging')
# RAW_DATA_DIR = join(BUILD_DIR, 'raw')
# SITE_BUILD_DIR = join(BUILD_DIR, 'site')  # must match 'dest' settings in Gruntfile.js
# TEMP_DIR = join(BUILD_DIR, 'tmp')
# PID_FILE_PATH = join(TEMP_DIR, 'daemon.pid')
# OBJECT_CACHE_DIR = join(TEMP_DIR, 'object_cache')
# ROW_FETCH_LIMIT = 100
# def _configSection(section):
# def _stringToBoolean(string):
# def _stringToList(string):
# 
# Path: static_aid/utils.py
# def bytes_label(size):
# def create_directory(path):
# def load_json(path):
# def remove_file_or_dir(path):


from os import listdir
from os.path import exists, join, splitext
from shutil import copyfile, copytree
from datetime import datetime
from static_aid import config, utils
from argparse import ArgumentParser

def create_sitemap(uri_list):
    """Creates a sitemap based on a list of URIs."""
    with open(config.sitemap, 'w') as s:
        s.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
        s.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n")
        for uri in uri_list:
            s.write("<url>\n")
            s.write("<loc>{}</loc>\n".format(uri))
            s.write("<lastmod>{}</lastmod>\n".format(str(datetime.now().isoformat())))
            s.write("</url>\n")
        s.write("</urlset>\n")


def create_site_config():
    """Creates a configuration file for the site."""
    with open((join(config.STAGING_DIR, '_config.yml')), 'w+') as yaml:
        for i in config.site:
            if config.site[i]:
                yaml.write(i)
                yaml.write(": ")
                yaml.write(config.site[i])
                yaml.write("\n")


def create_initial_structure(embedded):
    """Creates the initial structure for the staged site."""
    utils.remove_file_or_dir(config.STAGING_DIR)
    utils.create_directory(config.BUILD_DIR)


# Path: static_aid/config.py
# ROOT = realpath(curdir)
# CONFIG_DEFAULTS_FILE_PATH = join(ROOT, 'local_settings.default')
#     ROOT = realpath(join(dirname(__file__), '..'))
#     CONFIG_DEFAULTS_FILE_PATH = join(ROOT, 'local_settings.default')
# CONFIG_FILE_PATH = join(ROOT, 'local_settings.cfg')
# SAMPLE_DATA_DIR = join(ROOT, 'data')
# SITE_SRC_DIR = join(ROOT, 'site')
# BUILD_DIR = join(ROOT, 'build')
# DATA_DIR = join(BUILD_DIR, 'data')
# STAGING_DIR = join(BUILD_DIR, 'staging')
# RAW_DATA_DIR = join(BUILD_DIR, 'raw')
# SITE_BUILD_DIR = join(BUILD_DIR, 'site')  # must match 'dest' settings in Gruntfile.js
# TEMP_DIR = join(BUILD_DIR, 'tmp')
# PID_FILE_PATH = join(TEMP_DIR, 'daemon.pid')
# OBJECT_CACHE_DIR = join(TEMP_DIR, 'object_cache')
# ROW_FETCH_LIMIT = 100
# def _configSection(section):
# def _stringToBoolean(string):
# def _stringToList(string):
# 
# Path: static_aid/utils.py
# def bytes_label(size):
# def create_directory(path):
# def load_json(path):
# def remove_file_or_dir(path):


# Path: static_aid/make_pages.py
from os import listdir
from os.path import exists, join, splitext
from shutil import copyfile, copytree
from datetime import datetime
from static_aid import config, utils
from argparse import ArgumentParser


def create_sitemap(uri_list):
    """Creates a sitemap based on a list of URIs."""
    with open(config.sitemap, 'w') as s:
        s.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
        s.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n")
        for uri in uri_list:
            s.write("<url>\n")
            s.write("<loc>{}</loc>\n".format(uri))
            s.write("<lastmod>{}</lastmod>\n".format(str(datetime.now().isoformat())))
            s.write("</url>\n")
        s.write("</urlset>\n")


def create_site_config():
    """Creates a configuration file for the site."""
    with open((join(config.STAGING_DIR, '_config.yml')), 'w+') as yaml:
        for i in config.site:
            if config.site[i]:
                yaml.write(i)
                yaml.write(": ")
                yaml.write(config.site[i])
                yaml.write("\n")


def create_initial_structure(embedded):
    """Creates the initial structure for the staged site."""
    utils.remove_file_or_dir(config.STAGING_DIR)
    utils.create_directory(config.BUILD_DIR)


    copytree(config.SITE_SRC_DIR, config.STAGING_DIR)