import re
import sys

import apt
import yaml

debs = apt.Cache()

root = { "packages": dict() }
out = root["packages"]

for i in sys.argv[1:]:
   (deb, spack) = i.split(":")
   deb_v = debs[deb].installed.version
   spack_v = re.search(r"^([0-9]+:)?([0-9.]+)([-+].+)$", deb_v)[2]
   print(  "found %s version %s -> %s %s"
         % (deb, deb_v, spack, spack_v), file=sys.stderr)
   out[spack] = { "buildable": False,
                  "externals": [ { "spec": "%s@%s" % (spack, spack_v),
                                   "prefix": "/usr" } ] }

yaml.dump(root, stream=sys.stdout)