# 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/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')


from collections import defaultdict
from django.core import serializers
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError
from django.core.management.color import no_style
from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
from sitetree.compat import CommandOption, options_getter
from sitetree.utils import get_tree_model, get_tree_item_model
import sys
                import traceback
        help='Import only tree items data into tree with given alias.'),
))


class Command(BaseCommand):

    option_list = get_options()

    help = 'Loads sitetrees from fixture in JSON format into database.'
    args = '[fixture_file fixture_file ...]'

    def add_arguments(self, parser):
        parser.add_argument('args', metavar='fixture', nargs='+', help='Fixture files.')
        get_options(parser.add_argument)

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

        using = options.get('database', DEFAULT_DB_ALIAS)
        mode = options.get('mode', 'append')
        items_into_tree = options.get('items_into_tree', None)

        if items_into_tree is not None:
            try:
                items_into_tree = MODEL_TREE_CLASS.objects.get(alias=items_into_tree)
            except ObjectDoesNotExist:
                raise CommandError(
                    f'Target tree aliased `{items_into_tree}` does not exist. Please create it before import.')
            else:
                mode = 'append'


# 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/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/management/commands/sitetreeload.py
from collections import defaultdict
from django.core import serializers
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError
from django.core.management.color import no_style
from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
from sitetree.compat import CommandOption, options_getter
from sitetree.utils import get_tree_model, get_tree_item_model
import sys
                import traceback

        help='Import only tree items data into tree with given alias.'),
))


class Command(BaseCommand):

    option_list = get_options()

    help = 'Loads sitetrees from fixture in JSON format into database.'
    args = '[fixture_file fixture_file ...]'

    def add_arguments(self, parser):
        parser.add_argument('args', metavar='fixture', nargs='+', help='Fixture files.')
        get_options(parser.add_argument)

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

        using = options.get('database', DEFAULT_DB_ALIAS)
        mode = options.get('mode', 'append')
        items_into_tree = options.get('items_into_tree', None)

        if items_into_tree is not None:
            try:
                items_into_tree = MODEL_TREE_CLASS.objects.get(alias=items_into_tree)
            except ObjectDoesNotExist:
                raise CommandError(
                    f'Target tree aliased `{items_into_tree}` does not exist. Please create it before import.')
            else:
                mode = 'append'


        connection = connections[using]