Skip to content

Instantly share code, notes, and snippets.

@dhke
Last active August 29, 2015 14:27
Show Gist options
  • Save dhke/eff8d046fa3a3a1bcab6 to your computer and use it in GitHub Desktop.
Save dhke/eff8d046fa3a3a1bcab6 to your computer and use it in GitHub Desktop.
FreeBSD pkg: find all files that are not associated with a package (not registered in the package database)
#! /usr/bin/env python2
import os
import re
import shlex
import subprocess
import sys
from contextlib import closing
from sqlite3 import dbapi2 as sqlite
PKG_DB = '/var/db/pkg/local.sqlite'
DIRS = ['/usr/local']
n = 0
with sqlite.connect(PKG_DB) as pkg_db, closing(pkg_db.cursor()) as dbc:
for dir in DIRS:
for dirpath, dirnames, filenames in os.walk(dir):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
dbc.execute('SELECT package_id FROM files WHERE path = ?', (filepath, ))
row = dbc.fetchone()
if not row:
print filepath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment