Sort entries inside the link file by location
This commit is contained in:
parent
361f06f58f
commit
8e039fc032
|
@ -1,5 +1,5 @@
|
|||
from logging import Logger, getLogger
|
||||
from typing import Final, Mapping, Optional, Sequence, Union
|
||||
from typing import Final, List, Mapping, Optional, Sequence, Union, cast
|
||||
|
||||
from pydantic import ValidationError
|
||||
from yaml import YAMLError, safe_dump, safe_load
|
||||
|
@ -56,11 +56,14 @@ class Loader:
|
|||
)
|
||||
return None
|
||||
|
||||
ledger = {"command": schema.ledger.command, "location": ldgr_loc.inner}
|
||||
elements: Final[List[TElem]] = []
|
||||
ledger: Final[TLdgr] = {
|
||||
"command": schema.ledger.command,
|
||||
"location": ldgr_loc.inner,
|
||||
}
|
||||
|
||||
elements = []
|
||||
for elem in schema.elements:
|
||||
elem_loc = make_path(self.args.root, elem.location)
|
||||
for element in schema.elements:
|
||||
elem_loc = make_path(self.args.root, element.location)
|
||||
if not elem_loc.exists or not elem_loc.folder:
|
||||
self._log.error(
|
||||
"element location not found or no folder [%s]",
|
||||
|
@ -68,20 +71,25 @@ class Loader:
|
|||
)
|
||||
return None
|
||||
|
||||
checks = [check.value for check in elem.checks]
|
||||
checks = [check.value for check in element.checks]
|
||||
missing = [
|
||||
check.value
|
||||
for check in Checks.always()
|
||||
if check.value not in checks
|
||||
]
|
||||
elements.append(
|
||||
{
|
||||
"location": elem_loc.inner,
|
||||
"checks": [fl for at in [missing, checks] for fl in at],
|
||||
}
|
||||
)
|
||||
elem: TElem = {
|
||||
"location": elem_loc.inner,
|
||||
"checks": [fl for at in [missing, checks] for fl in at],
|
||||
}
|
||||
elements.append(elem)
|
||||
|
||||
return {"elements": elements, "ledger": ledger}
|
||||
def _order(element: TElem) -> str:
|
||||
return cast(str, element.get("location", ""))
|
||||
|
||||
return {
|
||||
"elements": sorted(elements, key=_order),
|
||||
"ledger": ledger,
|
||||
}
|
||||
|
||||
def dump(self, content: TConf) -> bool:
|
||||
loc = clean_path(self.args.link, folder=False)
|
||||
|
|
Reference in New Issue