From b06b5ae4c44da4d269e63aacad01a886be7972fc Mon Sep 17 00:00:00 2001 From: JohnE Date: Tue, 23 Feb 2016 12:12:04 -0800 Subject: [PATCH] WIP: __readDatabase() --- dbfp.py | 4 +++- libs/fingerprint.py | 18 +++++++++++++++--- libs/fingerprint_index.py | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dbfp.py b/dbfp.py index ab9de47..d656102 100644 --- a/dbfp.py +++ b/dbfp.py @@ -70,7 +70,8 @@ def compareFingerprintDir(file_in, fp_dir): fp.openIndex(fp_dir) # search for fingerprints with exact database match - fp_ret = fp.findFP(db.getMD5DB()) + # fp_ret = fp.findFP(db.getMD5DB()) + fp_ret = None if (fp_ret): print "Database matche(s) found" print "RESULTS:" @@ -80,6 +81,7 @@ def compareFingerprintDir(file_in, fp_dir): print # search for fingerprints with similar tables else: + logging.info("Searching for md5 tables: {}".format(db.getMD5Tables())) fp_list = fp.findFPTables(db.getMD5Tables()) results = [] for fp in fp_list: diff --git a/libs/fingerprint.py b/libs/fingerprint.py index 54bbe35..92517bc 100644 --- a/libs/fingerprint.py +++ b/libs/fingerprint.py @@ -74,13 +74,16 @@ class FingerprintDB: self.__readDatabase() # concat all the table create statements, then md5 self.__createMD5DB() - except Exception, ex: + except Exception as ex: logging.error(ex) return -3 # create and index of table hashes self.table_hashes = {} + print "*****" + print self.tables for key in self.tables.keys(): + print self.tables[key] self.table_hashes[key] = self.tables[key].hash() # flag is used to determine if the class has data @@ -275,12 +278,21 @@ class FingerprintDB: # read a sqlite database by parsing the create table strings # sqlmaster = "SELECT name, sql FROM sqlite_master WHERE type='table'" def __readDatabase(self): - for row in self.cur.execute(self.sqlmaster): + rows = self.cur.execute(self.sqlmaster) + row = self.cur.fetchone() + if (not row): + raise Exception + + newTable = TableSchema() + newTable.loadTable(row[0], row[1]) + self.table_names.append(newTable.name()) + self.tables[newTable.name()] = newTable + + for row in rows: newTable = TableSchema() newTable.loadTable(row[0], row[1]) self.table_names.append(newTable.name()) self.tables[newTable.name()] = newTable - return # def debugFingerprint(self): diff --git a/libs/fingerprint_index.py b/libs/fingerprint_index.py index 8ee52ee..209724a 100644 --- a/libs/fingerprint_index.py +++ b/libs/fingerprint_index.py @@ -82,8 +82,8 @@ class FingerprintIndex: # return an a list of json fingerprint files to open def findFPTables(self, md5_tables): + retval = {} for md5_table in md5_tables: - retval = {} rows = self.__qTableMD5(md5_table) for row in rows: fp_list = row[0]