# 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/make_pages.py
# def make_pages(category):
#     """Makes pages for files in a given category
# 
#     ex: families > agents/families/
#     """
#     page_uris = []
#     source_data_dir = join(config.DATA_DIR, config.destinations[category])
#     if exists(source_data_dir):
#         page_data_dir = utils.create_directory(join(config.STAGING_DIR, category))
# 
#         for filename in [f for f in listdir(source_data_dir) if f.endswith(".json")]:
#             data = utils.load_json(join(source_data_dir, filename))
# 
#             identifier = splitext(filename)[0]
#             if data.get("jsonmodel_type") == 'archival_object':
#                 title = clean_note_content(data["display_string"])
#             else:
#                 title = clean_note_content(data["title"])
# 
#             raw_description = []
#             notes = data.get('notes', [])
#             for note in notes:
#                 noteType = note.get('type')
#                 if noteType in DESCRIPTION_NOTE_TYPES:
#                     note = clean_note_content(get_note_content(note))
#                     if len(note) > 200:
#                         note = note[:197] + '...'
#                     raw_description.append('<p>%s</p>' % note)
# 
#             with open(join(page_data_dir, "{}.html".format(identifier)), 'w+') as new_file:
#                 new_file.write("---\nlayout: %s\n" % category)
#                 new_file.write("title: \"%s\"\n" % title)
#                 new_file.write("id: %s\n" % identifier)
#                 new_file.write("type: %s\n" % category)
#                 new_file.write("permalink: %s/%s/\n" % (category, identifier))
#                 new_file.write("description: \"%s\"\n" % ''.join(raw_description))
#                 new_file.write("---")
# 
#             page_uris.append("{}/{}/{}".format(config.site["url"], category, identifier))
#     return page_uris
# 
# 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 isdir, isfile, join
from shutil import rmtree
from static_aid import config, make_pages, utils
#!/usr/bin/env python3



def setup():
    utils.remove_file_or_dir(config.STAGING_DIR)


def test_make_pages():
    make_pages.main()
    assert isdir(config.STAGING_DIR), "{} must exist".format(config.STAGING_DIR)
    assert isfile(join(config.STAGING_DIR, '_config.yml')), "{} must exist".format(join(config.STAGING_DIR, '_config.yml'))
    assert isfile(join(config.STAGING_DIR, config.sitemap)), "{} must exist".format(join(config.STAGING_DIR, config.sitemap))
    for k, v in config.destinations.items():
        assert isdir(join(config.STAGING_DIR, k)), "{} must exist".format(join(config.STAGING_DIR, k))
        # some objects have an index.html file, others do not.
        expected = (len(listdir(join(config.DATA_DIR, v))) + 1
                    if k not in ['breadcrumbs', 'subjects', 'trees']
                    else len(listdir(join(config.DATA_DIR, v))))
        assert len(listdir(join(config.STAGING_DIR, k))) == expected, "The correct number of files should be generated"


def teardown():

# 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/make_pages.py
# def make_pages(category):
#     """Makes pages for files in a given category
# 
#     ex: families > agents/families/
#     """
#     page_uris = []
#     source_data_dir = join(config.DATA_DIR, config.destinations[category])
#     if exists(source_data_dir):
#         page_data_dir = utils.create_directory(join(config.STAGING_DIR, category))
# 
#         for filename in [f for f in listdir(source_data_dir) if f.endswith(".json")]:
#             data = utils.load_json(join(source_data_dir, filename))
# 
#             identifier = splitext(filename)[0]
#             if data.get("jsonmodel_type") == 'archival_object':
#                 title = clean_note_content(data["display_string"])
#             else:
#                 title = clean_note_content(data["title"])
# 
#             raw_description = []
#             notes = data.get('notes', [])
#             for note in notes:
#                 noteType = note.get('type')
#                 if noteType in DESCRIPTION_NOTE_TYPES:
#                     note = clean_note_content(get_note_content(note))
#                     if len(note) > 200:
#                         note = note[:197] + '...'
#                     raw_description.append('<p>%s</p>' % note)
# 
#             with open(join(page_data_dir, "{}.html".format(identifier)), 'w+') as new_file:
#                 new_file.write("---\nlayout: %s\n" % category)
#                 new_file.write("title: \"%s\"\n" % title)
#                 new_file.write("id: %s\n" % identifier)
#                 new_file.write("type: %s\n" % category)
#                 new_file.write("permalink: %s/%s/\n" % (category, identifier))
#                 new_file.write("description: \"%s\"\n" % ''.join(raw_description))
#                 new_file.write("---")
# 
#             page_uris.append("{}/{}/{}".format(config.site["url"], category, identifier))
#     return page_uris
# 
# 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/tests/test_make_pages.py
from os import listdir
from os.path import isdir, isfile, join
from shutil import rmtree
from static_aid import config, make_pages, utils

#!/usr/bin/env python3



def setup():
    utils.remove_file_or_dir(config.STAGING_DIR)


def test_make_pages():
    make_pages.main()
    assert isdir(config.STAGING_DIR), "{} must exist".format(config.STAGING_DIR)
    assert isfile(join(config.STAGING_DIR, '_config.yml')), "{} must exist".format(join(config.STAGING_DIR, '_config.yml'))
    assert isfile(join(config.STAGING_DIR, config.sitemap)), "{} must exist".format(join(config.STAGING_DIR, config.sitemap))
    for k, v in config.destinations.items():
        assert isdir(join(config.STAGING_DIR, k)), "{} must exist".format(join(config.STAGING_DIR, k))
        # some objects have an index.html file, others do not.
        expected = (len(listdir(join(config.DATA_DIR, v))) + 1
                    if k not in ['breadcrumbs', 'subjects', 'trees']
                    else len(listdir(join(config.DATA_DIR, v))))
        assert len(listdir(join(config.STAGING_DIR, k))) == expected, "The correct number of files should be generated"


def teardown():

    utils.remove_file_or_dir(config.STAGING_DIR)