def update_local(): """Adds a table to the database, adding an entry for each application found in the searchpath.""" # Open database connection. with sqlite3.connect(options.get_database()) as db: db.row_factory = sqlite3.Row # Create table from scratch to hold list of all installed PNDs. # Drops it first so no old entries get left behind. # TODO: Yes, there are probably more efficient ways than dropping # the whole thing, whatever, I'll get to it. db.execute('Drop Table If Exists "%s"' % LOCAL_TABLE) create_table(db, LOCAL_TABLE) # Find PND files on searchpath. searchpath = ':'.join(options.get_searchpath()) search = libpnd.disco_search(searchpath, None) if not search: raise ValueError("Your install of libpnd isn't behaving right! pnd_disco_search has returned null.") # If at least one PND is found, add each to the database. # Note that disco_search returns the path to each *application*. PNDs with # multiple apps will therefore be returned multiple times. Process any # such PNDs only once. n = libpnd.box_get_size(search) done = set() if n > 0: node = libpnd.box_get_head(search) path = libpnd.box_get_key(node) try: update_local_file(path, db) except Exception as e: warnings.warn("Could not process %s: %s" % (path, repr(e))) done.add(path) for i in xrange(n-1): node = libpnd.box_get_next(node) path = libpnd.box_get_key(node) if path not in done: try: update_local_file(path, db) except Exception as e: warnings.warn("Could not process %s: %s" % (path, repr(e))) done.add(path) db.commit()
def get_searchpath_full(): paths = [] for p in options.get_searchpath(): paths.extend(glob.iglob(p)) return paths