AnP/Python/Managers/IndexesManager.py

46 lines
1.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Self, Any
from Interfaces.Application.AnPInterface import AnPInterface
from Utils.Checks import Check
class IndexesManager:
def __init__(self:Self, anp:AnPInterface) -> None:
self.anp:AnPInterface = anp
self.__indexes:list[str] = [""]
self.update()
def update(self:Self) -> None:
key:str
for key in ("default_indexes", "indexes"):
self.add(self.anp.settings.get(key))
def reset(self:Self) -> None:
self.__indexes = []
self.update()
def add(self:Self, inputs:Any|None) -> None:
if Check.is_array(inputs):
item:Any|None
for item in inputs:
self.add(item)
elif (
Check.is_string(inputs) and
(inputs := inputs.strip()) and
inputs not in self.__indexes
):
self.__indexes.append(inputs)
def get(self:Self) -> list[str]:
return [*self.__indexes]