# Path: project_generator/project.py
# class ProjectWorkspace:
# class ProjectTemplate:
# class Project:
#     def __init__(self, name, projects, settings, workspace_settings):
#     def generate(self, tool, copied=False, copy=False):
#     def build(self, tool, **kwargs):
#     def clean(self, tool):
#     def _get_common_data_template():
#     def _get_tool_specific_data_template():
#     def get_project_template(name="Default", output_type='exe', debugger=None, build_dir='build'):
#     def __init__(self, name, project_dicts, settings, workspace_name=None):
#     def _list_elim_none(list_to_clean):
#     def _dict_elim_none(dic_to_clean):
#     def _set_project_attributes(self, key_value, destination, source):
#     def _set_internal_common_data(self):
#     def _set_internal_tool_data(self, tool_keywords):
#     def _process_include_files(self, files, use_group_name = 'default'):
#     def _process_source_files(self, files, use_group_name='default'):
#     def _validate_tools(self, tool):
#     def _generate_output_dir(settings, path):
#     def _get_tool_data(self, key, tool_keywords):
#     def _get_tool_sources(self, tool_keywords):
#     def _get_tool_includes(self, tool_keywords):
#     def _set_output_dir_path(self, tool, copied):
#     def _fill_export_dict(self, tool, copied=False):
#     def _copy_sources_to_generated_destination(self):
#     def clean(self, tool):
#     def generate(self, tool, copied=False, copy=False):
#     def build(self, tool, **kwargs):
#     def get_generated_project_files(self, tool):


import os
import yaml
import logging
import bisect
from collections import defaultdict
from .project import FILES_EXTENSIONS
                    data_dict.append(os.path.normpath(os.path.join(relpath, filename)))
    if section == "sources":
        return dict(data_dict)
    l = list(set(data_dict))
    l.sort()
    return l

def _generate_file(filename,data):
    logger.debug('Writing the following to %s:\n%s' % (filename, yaml.dump(data)))
    file = os.path.join(os.getcwd(), filename)
    if os.path.isfile(file):
        os.remove(file)
    try:
        with open(file, 'w+') as f:
            f.write(yaml.dump(data, default_flow_style=False))
    except:
        logger.error("Unable to open %s for writing!" % file)
        return -1
    logger.info("Wrote to file %s" % file)

    return 0


def create_yaml(directory, project_name, board,output_dir):
    # lay out what the common section a project yaml file will look like
    # The value mapped to by each key are the file extensions that will help us get valid files for each section
    logger.debug("Project name: %s, Target: %s"%(project_name,board))
    common_section = {
        'linker_file': FILES_EXTENSIONS['linker_file'],
        'sources': FILES_EXTENSIONS['source_files_c'] + FILES_EXTENSIONS['source_files_cpp'] +

# Path: project_generator/project.py
# class ProjectWorkspace:
# class ProjectTemplate:
# class Project:
#     def __init__(self, name, projects, settings, workspace_settings):
#     def generate(self, tool, copied=False, copy=False):
#     def build(self, tool, **kwargs):
#     def clean(self, tool):
#     def _get_common_data_template():
#     def _get_tool_specific_data_template():
#     def get_project_template(name="Default", output_type='exe', debugger=None, build_dir='build'):
#     def __init__(self, name, project_dicts, settings, workspace_name=None):
#     def _list_elim_none(list_to_clean):
#     def _dict_elim_none(dic_to_clean):
#     def _set_project_attributes(self, key_value, destination, source):
#     def _set_internal_common_data(self):
#     def _set_internal_tool_data(self, tool_keywords):
#     def _process_include_files(self, files, use_group_name = 'default'):
#     def _process_source_files(self, files, use_group_name='default'):
#     def _validate_tools(self, tool):
#     def _generate_output_dir(settings, path):
#     def _get_tool_data(self, key, tool_keywords):
#     def _get_tool_sources(self, tool_keywords):
#     def _get_tool_includes(self, tool_keywords):
#     def _set_output_dir_path(self, tool, copied):
#     def _fill_export_dict(self, tool, copied=False):
#     def _copy_sources_to_generated_destination(self):
#     def clean(self, tool):
#     def generate(self, tool, copied=False, copy=False):
#     def build(self, tool, **kwargs):
#     def get_generated_project_files(self, tool):


# Path: project_generator/init_yaml.py
import os
import yaml
import logging
import bisect
from collections import defaultdict
from .project import FILES_EXTENSIONS

                    data_dict.append(os.path.normpath(os.path.join(relpath, filename)))
    if section == "sources":
        return dict(data_dict)
    l = list(set(data_dict))
    l.sort()
    return l

def _generate_file(filename,data):
    logger.debug('Writing the following to %s:\n%s' % (filename, yaml.dump(data)))
    file = os.path.join(os.getcwd(), filename)
    if os.path.isfile(file):
        os.remove(file)
    try:
        with open(file, 'w+') as f:
            f.write(yaml.dump(data, default_flow_style=False))
    except:
        logger.error("Unable to open %s for writing!" % file)
        return -1
    logger.info("Wrote to file %s" % file)

    return 0


def create_yaml(directory, project_name, board,output_dir):
    # lay out what the common section a project yaml file will look like
    # The value mapped to by each key are the file extensions that will help us get valid files for each section
    logger.debug("Project name: %s, Target: %s"%(project_name,board))
    common_section = {
        'linker_file': FILES_EXTENSIONS['linker_file'],
        'sources': FILES_EXTENSIONS['source_files_c'] + FILES_EXTENSIONS['source_files_cpp'] +

                   FILES_EXTENSIONS['source_files_s'] + FILES_EXTENSIONS['source_files_obj'],