# 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

                            if tree_item.parent_id is not None:
                                if tree_item.parent_id in tree_items_new_indexes:
                                    tree_item.parent_id = tree_items_new_indexes[tree_item.parent_id]
                                else:
                                    parent_ahead = True

                        tree_item.save(using=using)
                        loaded_object_count += 1

                        if mode == 'append':
                            tree_items_new_indexes[orig_item_id] = tree_item.id
                            if parent_ahead:
                                parents_ahead.append(tree_item)

                    # Second pass is necessary for tree items being imported before their parents.
                    for tree_item in parents_ahead:
                        tree_item.parent_id = tree_items_new_indexes[tree_item.parent_id]
                        tree_item.save(using=using)

            except (SystemExit, KeyboardInterrupt):
                raise

            except Exception:
                fixture.close()

                self.stderr.write(
                    self.style.ERROR(
                        f"Fixture `{fixture_file}` import error: "
                        f"{''.join(traceback.format_exception(*sys.exc_info()))}\n")

# 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


                            if tree_item.parent_id is not None:
                                if tree_item.parent_id in tree_items_new_indexes:
                                    tree_item.parent_id = tree_items_new_indexes[tree_item.parent_id]
                                else:
                                    parent_ahead = True

                        tree_item.save(using=using)
                        loaded_object_count += 1

                        if mode == 'append':
                            tree_items_new_indexes[orig_item_id] = tree_item.id
                            if parent_ahead:
                                parents_ahead.append(tree_item)

                    # Second pass is necessary for tree items being imported before their parents.
                    for tree_item in parents_ahead:
                        tree_item.parent_id = tree_items_new_indexes[tree_item.parent_id]
                        tree_item.save(using=using)

            except (SystemExit, KeyboardInterrupt):
                raise

            except Exception:
                fixture.close()

                self.stderr.write(
                    self.style.ERROR(
                        f"Fixture `{fixture_file}` import error: "
                        f"{''.join(traceback.format_exception(*sys.exc_info()))}\n")

                )