def index_count(index_file=config.vulndb_bin_index): """ Method to return the number of indexed items :param index_file: Index DB file :return: Count of the index """ return len(storage.stream_read(index_file))
def list_all(db): """Method to return all data :param db: db instance :return: List of data stored """ return storage.stream_read(db["db_file"])
def test_create(test_vuln_data): with tempfile.NamedTemporaryFile(delete=False) as fp: data = storage.store(test_vuln_data, db_file=fp.name) assert data fp.flush() datas = storage.stream_read(db_file=fp.name) assert len(datas) > len(test_vuln_data) fp.close()
def get(db_file=config.vulndb_bin_file, index_file=config.vulndb_bin_index): """Get database instance :param db_file: DB file :param index_file: Index file """ global index_data index_data = build_index(storage.stream_read(index_file)) return {"db_file": db_file, "index_file": index_file}
def store(db, datas): """Store data in the table :param table: Table instance :param datas: Data list to store :return: Stored packed documents """ global index_data, vendor_index_data docs = storage.store(datas, db_file=db["db_file"], index_file=db["index_file"]) # Re-read the index index_data, vendor_index_data = build_index(storage.stream_read(db["index_file"])) return docs
def index_count(index_file=config.vulndb_bin_index): return len(storage.stream_read(index_file))