WIP: adding functions to use index

This commit is contained in:
JohnE 2015-12-28 23:50:10 -08:00
parent b6c6e0f600
commit a39dad4f18
1 changed files with 26 additions and 3 deletions

View File

@ -37,6 +37,8 @@ class FingerprintIndex:
logging.info("No index file found, creating index now...")
self.createIndex(fp_dir)
self.db_conn = sql.connect(fq_fpidx)
self.cur = self.db_conn.cursor()
except:
if self.db_conn:
self.db_conn.close()
@ -64,20 +66,41 @@ class FingerprintIndex:
logging.info("Successfully created index table")
self.__populateIndex(fp_dir)
logging.info("Successfully populated the index")
except Exception as e:
raise FingerprintIndexWrite("Error creating an index file\n{}".format(e))
except Exception as ex:
raise FingerprintIndexWrite("Error creating an index file\n{}".format(ex))
finally:
if self.db_conn:
self.db_conn.close()
self.db_conn = None
#
def qDatabaseMD5(self, md5_db):
try:
rows = self.cur.execute('''
SELECT md5_list, fp_list, fp_count
FROM md5_all
WHERE md5_db=?
''', [md5_db])
except Exception as ex:
logging.error(ex)
#
def qTableMD5(self, md5_table):
try:
rows = self.cur.execute('''
SELECT fp_list, fp_count
FROM md5_tables
WHERE md5_table=?
''', [md5_table])
except Exception as ex:
logging.error(ex)
#
def __populateIndex(self, fp_dir):
""" read each file, pull md5, add row to database """
failCount = 0
finCount = 0
try:
self.cur = self.db_conn.cursor()
db = FingerprintDB()
files = os.listdir(fp_dir)
for file in files: