Last active
August 29, 2015 14:27
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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