import re,sys,subprocess,os
pk={}
for s in ("noble","noble-updates"):
    for blk in open(f"Packages.{s}",encoding="utf8").read().split("\n\n"):
        m=re.search(r"^Package: (.+)$",blk,re.M); f=re.search(r"^Filename: (.+)$",blk,re.M)
        if m and f: pk[m.group(1)]=(f.group(1),re.search(r"^Depends: (.+)$",blk,re.M))
want=["libsecret-1-dev","libglib2.0-dev"]; seen=set()
skip={"libc6","libc6-dev","libgcc-s1","python3","python3:any","pkgconf","pkg-config","libglib2.0-dev-bin","libglib2.0-bin","libglib2.0-data","gir1.2-secret-1","gir1.2-glib-2.0","gir1.2-glib-2.0-dev","libgirepository-2.0-dev","libsecret-common"}
while want:
    p=want.pop()
    if p in seen or p in skip or p not in pk: continue
    seen.add(p); fn,dep=pk[p]
    out="debs/"+os.path.basename(fn)
    if not os.path.exists(out): subprocess.check_call(["curl","-fsSL","-o",out,"http://ports.ubuntu.com/ubuntu-ports/"+fn])
    subprocess.check_call(["dpkg-deb","-x",out,"root"])
    if dep:
        for d in dep.group(1).split(","):
            want.append(d.split("|")[0].strip().split(" ")[0].split(":")[0])
print(sorted(seen))
