Advertisement
cwchen

query Debian package for a file

Dec 26th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. def query_pkg(raw_file):
  2.     """
  3.    Query which Debian package raw_file belongs.
  4.    Use dlocate(1) instead of dpkg(1) for fast search
  5.    If dlocate is not installed, fall back to dpkg(1)
  6.    Return None if the query fails.
  7.    """
  8.          
  9.     with open(os.devnull, "w") as fnull:
  10.         program = dlocate_installed()
  11.  
  12.         try:
  13.             result = subprocess.check_output(["dlocate", "-S", raw_file],
  14.                                              stderr=fnull)
  15.         except subprocess.CalledProcessError:
  16.             pass
  17.  
  18.         try:
  19.             return result.split(':')[0]                                        
  20.         except UnboundLocalError:
  21.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement