def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        default=False,
                        help="increase output verbosity")
    args = parser.parse_args()
    logging.basicConfig(
        level=logging.DEBUG if args.verbose else logging.WARNING,
        stream=sys.stdout)

    global columns_name_tree_by_entity
    columns_name_tree_by_entity = collections.OrderedDict(
        (entity, columns_name_tree) for entity, columns_name_tree in (
            (entity1, cleanup_tree(entity1, columns_name_tree1)) for entity1,
            columns_name_tree1 in columns_name_tree_by_entity.iteritems())
        if columns_name_tree is not None)
    placed_columns_name = set(
        column_name
        for columns_name_tree in columns_name_tree_by_entity.itervalues()
        for column_name in iter_placed_tree(columns_name_tree))

    for name, column in tax_benefit_system.column_by_name.iteritems():
        if not is_valid_input_column(column):
            continue
        if name in placed_columns_name:
            continue
        placed_columns_name.add(name)
        entity_children = columns_name_tree_by_entity.setdefault(
            column.entity,
            collections.OrderedDict()).setdefault('children', [])
        if entity_children and entity_children[-1].get('label') == u'Autres':
            last_entity_child = entity_children[-1]
        else:
            last_entity_child = collections.OrderedDict(label=u'Autres')
            entity_children.append(last_entity_child)
        last_entity_child.setdefault('children', []).append(name)

    datatrees_module_path = os.path.join(os.path.dirname(model.__file__),
                                         'datatrees.py')
    with open(datatrees_module_path, 'w') as datatree_file:
        datatree_file.write('''\
# -*- coding: utf-8 -*-

import collections


columns_name_tree_by_entity = collections.OrderedDict([
''')
        for entity in ('ind', 'fam', 'foy', 'men'):
            datatree_file.write('    ({}, '.format(
                pretty_printer.pformat(entity)))
            write_tree(datatree_file, columns_name_tree_by_entity[entity])
            datatree_file.write('),\n')
        datatree_file.write('    ])\n')
    return 0
def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity")
    args = parser.parse_args()
    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)

    global columns_name_tree_by_entity
    columns_name_tree_by_entity = collections.OrderedDict(
        (entity, columns_name_tree)
        for entity, columns_name_tree in (
            (entity1, cleanup_tree(entity1, columns_name_tree1))
            for entity1, columns_name_tree1 in columns_name_tree_by_entity.iteritems()
            )
        if columns_name_tree is not None
        )
    placed_columns_name = set(
        column_name
        for columns_name_tree in columns_name_tree_by_entity.itervalues()
        for column_name in iter_placed_tree(columns_name_tree)
        )

    for name, column in tax_benefit_system.column_by_name.iteritems():
        if not is_valid_input_column(column):
            continue
        if name in placed_columns_name:
            continue
        placed_columns_name.add(name)
        entity_children = columns_name_tree_by_entity.setdefault(column.entity, collections.OrderedDict()).setdefault(
            'children', [])
        if entity_children and entity_children[-1].get('label') == u'Autres':
            last_entity_child = entity_children[-1]
        else:
            last_entity_child = collections.OrderedDict(label = u'Autres')
            entity_children.append(last_entity_child)
        last_entity_child.setdefault('children', []).append(name)

    datatrees_module_path = os.path.join(os.path.dirname(model.__file__), 'datatrees.py')
    with open(datatrees_module_path, 'w') as datatree_file:
        datatree_file.write('''\
# -*- coding: utf-8 -*-

import collections


columns_name_tree_by_entity = collections.OrderedDict([
''')
        for entity in ('ind', 'fam', 'foy', 'men'):
            datatree_file.write('    ({}, '.format(pretty_printer.pformat(entity)))
            write_tree(datatree_file, columns_name_tree_by_entity[entity])
            datatree_file.write('),\n')
        datatree_file.write('    ])\n')
    return 0
def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity")
    args = parser.parse_args()
    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)

    global columns_name_tree_by_entity
    columns_name_tree_by_entity = collections.OrderedDict(
        (entity, columns_name_tree)
        for entity, columns_name_tree in (
            (entity1, cleanup_tree(entity1, columns_name_tree1))
            for entity1, columns_name_tree1 in columns_name_tree_by_entity.iteritems()
            )
        if columns_name_tree is not None
        )
    placed_columns_name = set(
        column_name
        for columns_name_tree in columns_name_tree_by_entity.itervalues()
        for column_name in iter_placed_tree(columns_name_tree)
        )

    for name, column in tax_benefit_system.column_by_name.iteritems():
        if not is_valid_input_column(column):
            continue
        if name in placed_columns_name:
            continue
        placed_columns_name.add(name)
        entity_children = columns_name_tree_by_entity.setdefault(column.entity, collections.OrderedDict()).setdefault(
            'children', [])
        if entity_children and entity_children[-1].get('label') == u'Autres':
            last_entity_child = entity_children[-1]
        else:
            last_entity_child = collections.OrderedDict(label = u'Autres')
            entity_children.append(last_entity_child)
        last_entity_child.setdefault('children', []).append(name)

    datatrees_module_path = os.path.join(os.path.dirname(model.__file__), 'datatrees.py')
    with open(datatrees_module_path, 'w') as datatree_file:
        datatree_file.write('''\
# -*- coding: utf-8 -*-


# OpenFisca -- A versatile microsimulation software
# By: OpenFisca Team <*****@*****.**>
#
# Copyright (C) 2011, 2012, 2013, 2014, 2015 OpenFisca Team
# https://github.com/openfisca
#
# This file is part of OpenFisca.
#
# OpenFisca is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OpenFisca is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import collections


columns_name_tree_by_entity = collections.OrderedDict([
''')
        for entity in ('ind', 'fam', 'foy', 'men'):
            datatree_file.write('    ({}, '.format(pretty_printer.pformat(entity)))
            write_tree(datatree_file, columns_name_tree_by_entity[entity])
            datatree_file.write('),\n')
        datatree_file.write('    ])\n')
    return 0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        default=False,
                        help="increase output verbosity")
    args = parser.parse_args()
    logging.basicConfig(
        level=logging.DEBUG if args.verbose else logging.WARNING,
        stream=sys.stdout)

    global columns_name_tree_by_entity
    columns_name_tree_by_entity = collections.OrderedDict(
        (entity, columns_name_tree) for entity, columns_name_tree in (
            (entity1, cleanup_tree(entity1, columns_name_tree1)) for entity1,
            columns_name_tree1 in columns_name_tree_by_entity.iteritems())
        if columns_name_tree is not None)
    placed_columns_name = set(
        column_name
        for columns_name_tree in columns_name_tree_by_entity.itervalues()
        for column_name in iter_placed_tree(columns_name_tree))

    for name, column in tax_benefit_system.column_by_name.iteritems():
        if not is_valid_input_column(column):
            continue
        if name in placed_columns_name:
            continue
        placed_columns_name.add(name)
        entity_children = columns_name_tree_by_entity.setdefault(
            column.entity,
            collections.OrderedDict()).setdefault('children', [])
        if entity_children and entity_children[-1].get('label') == u'Autres':
            last_entity_child = entity_children[-1]
        else:
            last_entity_child = collections.OrderedDict(label=u'Autres')
            entity_children.append(last_entity_child)
        last_entity_child.setdefault('children', []).append(name)

    datatrees_module_path = os.path.join(os.path.dirname(model.__file__),
                                         'datatrees.py')
    with open(datatrees_module_path, 'w') as datatree_file:
        datatree_file.write('''\
# -*- coding: utf-8 -*-


# OpenFisca -- A versatile microsimulation software
# By: OpenFisca Team <*****@*****.**>
#
# Copyright (C) 2011, 2012, 2013, 2014, 2015 OpenFisca Team
# https://github.com/openfisca
#
# This file is part of OpenFisca.
#
# OpenFisca is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OpenFisca is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import collections


columns_name_tree_by_entity = collections.OrderedDict([
''')
        for entity in ('ind', 'fam', 'foy', 'men'):
            datatree_file.write('    ({}, '.format(
                pretty_printer.pformat(entity)))
            write_tree(datatree_file, columns_name_tree_by_entity[entity])
            datatree_file.write('),\n')
        datatree_file.write('    ])\n')
    return 0