#!/usr/bin/env python3

"""
See the help message (--help).
"""

from pycman import config
from os.path import exists
import argparse


parser = argparse.ArgumentParser(description='List all packages with missing installed files.')
parser.add_argument(
  '-c', '--config', metavar='<path>', default='/etc/pacman.conf',
  help='Pacman configuration file'
)

def main(args=None):
  args = parser.parse_args(args)
  h = config.init_with_config(args.config)
  db = h.get_localdb()

  for pkg in db.pkgcache:
    for path in pkg.files:
      path = '/' + path[0]
      if not exists(path):
        print(pkg.name, path)

if __name__ == '__main__':
  try:
    main()
  except (KeyboardInterrupt, BrokenPipeError):
    pass
