# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer
                        # visible.
                        and not int(rep['ReputationFlags[0]']) & 0x2
                    )
                ):
                    return

            if not children:
                self.wt_faction[int(rep['ID'])] = rep

            for row in children:
                _recurse_rep(int(row['ID']), level + 1)

        _recurse_rep(0)

    def register_old_factions(self):
        for cat in self.factions:
            for item in cat['factions']:
                self.id_to_old_faction[int(item['id'])] = item

    def get_faction(self, faction_id: int):
        if int(faction_id) not in self.wt_faction:
            return None
        name = self.wt_faction[int(faction_id)]['Name_lang']
        return {
            'id': int(faction_id),
            'name': name,
        }

    def fix_missing_faction(self, faction_id: int):
        faction = self.get_faction(faction_id)

# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


# Path: dataimporter/factions.py
from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer

                        # visible.
                        and not int(rep['ReputationFlags[0]']) & 0x2
                    )
                ):
                    return

            if not children:
                self.wt_faction[int(rep['ID'])] = rep

            for row in children:
                _recurse_rep(int(row['ID']), level + 1)

        _recurse_rep(0)

    def register_old_factions(self):
        for cat in self.factions:
            for item in cat['factions']:
                self.id_to_old_faction[int(item['id'])] = item

    def get_faction(self, faction_id: int):
        if int(faction_id) not in self.wt_faction:
            return None
        name = self.wt_faction[int(faction_id)]['Name_lang']
        return {
            'id': int(faction_id),
            'name': name,
        }

    def fix_missing_faction(self, faction_id: int):
        faction = self.get_faction(faction_id)

        changelog(