import os
import sys
import collections
import glob

import configparser
import argparse

NAME = 'LAF-Fabric'
VERSION = '4.8.4'
APIREF = 'http://laf-fabric.readthedocs.org/en/latest/texts/API-reference.html'
DEFAULT_DATA_DIR = 'laf-fabric-data'
MAIN_CFG = 'laf-fabric.cfg'
ALL_PARTS = ['monad', 'section', 'lingo']

class Settings:
    ''' Stores configuration information from the main configuration file and the command line.
        
        Defines an extra function in order to get the items in a section as a dictionary,
        without getting the DEFAULT items as wel
    '''
    _myconfig = {
        'my_name':              NAME,
        'version':              VERSION,
    }
    _env_def = {
        'my_name':              '{my_name}',
        'version':              '{version}',
        'template_dir':         '{script_dir}/templates',
        'xml_dir':              '{script_dir}/xml',
        'source':               '{source}',
        'meta_info':            '{data_dir}/{source}/config/main.cfg',
        'feature_info':         '{data_dir}/{source}/config/ObjectsFeaturesValues.txt',
        'feature_plain_info':   '{data_dir}/{source}/config/ObjectsFeatures.csv',
        'object_info':          '{data_dir}/{source}/config/Objects.txt',
        'raw_emdros_dir':       '{data_dir}/{source}/raw',
        'source_data':          '{data_dir}/{source}/mql/{source}',
        'query_dst_dir':        '{data_dir}/{source}/mql',
        'result_dir':           '{data_dir}/{source}/laf',
        'annot_hdr':            '{data_dir}/{source}/laf/{source}',
        'primary_text':         '{data_dir}/{source}/laf/{source}.txt',
        'primary_hdr_txt':      '{data_dir}/{source}/laf/{source}.txt.hdr',
        'resource_hdr_txt':     '{data_dir}/{source}/laf/{source}.hdr',
        'monad_index':          '{data_dir}/{source}/laf/{source}.lst',
        'decl_dst_dir':         '{data_dir}/{source}/decl',

    }
    _metaconfig = {
        'my_name':              NAME,
        'version':              VERSION,
        'ISOcatprefix':         'http://www.isocat.org/datcat/DC-',
        'DANSpidprefix':        'http://persistent-identifier/?identifier=',
    }
    _meta_def = {
        'my_name':              '{my_name}',
        'version':              '{version}',
        'source':               '{source}',
        'ISOcatprefix':         '{ISOcatprefix}',
        'DANSpidprefix':        '{DANSpidprefix}',
        'danspid_act':          '{DANSpidprefix}{danspid_urn}',
        'publicationdate':      '{publicationdate}',
        'danspid_urn':          '{danspid_urn}',
        'annot_method':         'conversion script {my_name} {version}',
        'annot_resp':           '{annot_resp}',
        'primary':              '{primary}',
        'trailer':              '{trailer}',
        'verse_newline':        '{verse_newline}',
        'annot_space_def':      '{annot_space_def}',
        'prim_creator':         '{prim_creator}',
        'res_creator':          '{res_creator}',
        'prim_title':           '{prim_title}',
        'res_title':            '{res_title}',
        'prim_source_title':    '{prim_source_title}',
        'prim_source_author':   '{prim_source_author}',
        'prim_source_publisher':'{prim_source_publisher}',
        'prim_source_date':     '{prim_source_date}',