# Path: sitetree/utils.py
# def get_tree_model() -> Type['TreeBase']:
#     """Returns the Tree model, set for the project."""
#     return get_model_class('MODEL_TREE')
# 
# def get_tree_item_model() -> Type['TreeItemBase']:
#     """Returns the TreeItem model, set for the project."""
#     return get_model_class('MODEL_TREE_ITEM')
# 
# Path: sitetree/compat.py
# class CommandOption:
#     """Command line option wrapper."""
# 
#     def __init__(self, *args, **kwargs):
#         self.args = args
#         self.kwargs = kwargs
# 
# def options_getter(command_options):
#     """Compatibility function to get rid of optparse in management commands after Django 1.10.
# 
#     :param tuple command_options: tuple with `CommandOption` objects.
# 
#     """
#     def get_options(option_func: Callable = None):
#         from optparse import make_option
# 
#         func = option_func or make_option
#         options = tuple([func(*option.args, **option.kwargs) for option in command_options])
# 
#         return [] if option_func is None else options
# 
#     return get_options


from django.core import serializers
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS
from sitetree.utils import get_tree_model, get_tree_item_model
from sitetree.compat import CommandOption, options_getter

get_options = options_getter((
    CommandOption(
        '--indent', default=None, dest='indent', type=int,
        help='Specifies the indent level to use when pretty-printing output.'),

    CommandOption('--items_only', action='store_true', dest='items_only', default=False,
         help='Export tree items only.'),

    CommandOption('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
         help='Nominates a specific database to export fixtures from. Defaults to the "default" database.'),
))


class Command(BaseCommand):

    option_list = get_options()
    help = 'Output sitetrees from database as a fixture in JSON format.'
    args = '[tree_alias tree_alias ...]'

    def add_arguments(self, parser):
        parser.add_argument('args', metavar='tree', nargs='*', help='Tree aliases.', default=[])
        get_options(parser.add_argument)

    def handle(self, *aliases, **options):

        indent = options.get('indent', None)
        using = options.get('database', DEFAULT_DB_ALIAS)
        items_only = options.get('items_only', False)


# Path: sitetree/utils.py
# def get_tree_model() -> Type['TreeBase']:
#     """Returns the Tree model, set for the project."""
#     return get_model_class('MODEL_TREE')
# 
# def get_tree_item_model() -> Type['TreeItemBase']:
#     """Returns the TreeItem model, set for the project."""
#     return get_model_class('MODEL_TREE_ITEM')
# 
# Path: sitetree/compat.py
# class CommandOption:
#     """Command line option wrapper."""
# 
#     def __init__(self, *args, **kwargs):
#         self.args = args
#         self.kwargs = kwargs
# 
# def options_getter(command_options):
#     """Compatibility function to get rid of optparse in management commands after Django 1.10.
# 
#     :param tuple command_options: tuple with `CommandOption` objects.
# 
#     """
#     def get_options(option_func: Callable = None):
#         from optparse import make_option
# 
#         func = option_func or make_option
#         options = tuple([func(*option.args, **option.kwargs) for option in command_options])
# 
#         return [] if option_func is None else options
# 
#     return get_options


# Path: sitetree/management/commands/sitetreedump.py
from django.core import serializers
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS
from sitetree.utils import get_tree_model, get_tree_item_model
from sitetree.compat import CommandOption, options_getter


get_options = options_getter((
    CommandOption(
        '--indent', default=None, dest='indent', type=int,
        help='Specifies the indent level to use when pretty-printing output.'),

    CommandOption('--items_only', action='store_true', dest='items_only', default=False,
         help='Export tree items only.'),

    CommandOption('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
         help='Nominates a specific database to export fixtures from. Defaults to the "default" database.'),
))


class Command(BaseCommand):

    option_list = get_options()
    help = 'Output sitetrees from database as a fixture in JSON format.'
    args = '[tree_alias tree_alias ...]'

    def add_arguments(self, parser):
        parser.add_argument('args', metavar='tree', nargs='*', help='Tree aliases.', default=[])
        get_options(parser.add_argument)

    def handle(self, *aliases, **options):

        indent = options.get('indent', None)
        using = options.get('database', DEFAULT_DB_ALIAS)
        items_only = options.get('items_only', False)


        objects = []