forked from Mirror/pmbootstrap
config: workdir: make chroots_outdated() return a list (MR 2344)
This can be used to build nicer log messages. For funsies let's try out @overload as well. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
95d68d8854
commit
62fa40e104
1 changed files with 20 additions and 6 deletions
|
@ -8,7 +8,7 @@ dir."""
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional, overload
|
||||||
|
|
||||||
import pmb.config
|
import pmb.config
|
||||||
import pmb.config.pmaports
|
import pmb.config.pmaports
|
||||||
|
@ -40,34 +40,48 @@ def chroot_save_init(suffix: Chroot):
|
||||||
cfg.write(handle)
|
cfg.write(handle)
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def chroots_outdated() -> list[Chroot]:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def chroots_outdated(chroot: Chroot) -> bool:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
def chroots_outdated(chroot: Optional[Chroot] = None):
|
def chroots_outdated(chroot: Optional[Chroot] = None):
|
||||||
"""Check if init dates from workdir.cfg indicate that any chroot is
|
"""Check if init dates from workdir.cfg indicate that any chroot is
|
||||||
outdated.
|
outdated.
|
||||||
|
|
||||||
:param suffix: only check a specific chroot suffix
|
:param suffix: only check a specific chroot suffix
|
||||||
|
|
||||||
:returns: True if any of the chroots are outdated and should be zapped,
|
:returns: A list of all outdated chroots if chroot is None, if a specific
|
||||||
|
chroot is given, instead it returns True if the chroot is outdated,
|
||||||
False otherwise
|
False otherwise
|
||||||
"""
|
"""
|
||||||
# Skip if workdir.cfg doesn't exist
|
# Skip if workdir.cfg doesn't exist
|
||||||
path = get_context().config.work / "workdir.cfg"
|
path = get_context().config.work / "workdir.cfg"
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return False
|
return False if chroot else []
|
||||||
|
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read(path)
|
cfg.read(path)
|
||||||
key = "chroot-init-dates"
|
key = "chroot-init-dates"
|
||||||
if key not in cfg:
|
if key not in cfg:
|
||||||
return False
|
return False if chroot else []
|
||||||
|
|
||||||
|
outdated: list[Chroot] = []
|
||||||
date_outdated = time.time() - pmb.config.chroot_outdated
|
date_outdated = time.time() - pmb.config.chroot_outdated
|
||||||
for cfg_suffix in cfg[key]:
|
for cfg_suffix in cfg[key]:
|
||||||
if chroot and cfg_suffix != str(chroot):
|
if chroot and cfg_suffix != str(chroot):
|
||||||
continue
|
continue
|
||||||
date_init = int(cfg[key][cfg_suffix])
|
date_init = int(cfg[key][cfg_suffix])
|
||||||
if date_init <= date_outdated:
|
if date_init <= date_outdated:
|
||||||
return True
|
if chroot:
|
||||||
return False
|
return True
|
||||||
|
outdated.append(Chroot.from_str(cfg_suffix))
|
||||||
|
return False if chroot else outdated
|
||||||
|
|
||||||
|
|
||||||
def chroot_check_channel(chroot: Chroot) -> bool:
|
def chroot_check_channel(chroot: Chroot) -> bool:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue