From 7736404c3040701093bbb3d7575a4a46b05dacb7 Mon Sep 17 00:00:00 2001 From: JohnE Date: Thu, 10 Dec 2015 12:48:13 -0800 Subject: [PATCH] WIP: problem inserting a row into database, troubleshooting --- libs/fingerprint.py | 11 +++++------ libs/fingerprint_index.py | 31 ++++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libs/fingerprint.py b/libs/fingerprint.py index 88c388f..bd2a83f 100644 --- a/libs/fingerprint.py +++ b/libs/fingerprint.py @@ -149,18 +149,17 @@ class FingerprintDB: dbmd5 = jsonData['db-metadata-md5'] all_tables = tb.keys() for table_name in all_tables: - print "[[ Table <" + table_name + "> imported ]]" + #logging.info("[[ Table <" + table_name + "> imported ]]") newTable = TableSchema() newTable.importTable(table_name, tb[table_name], dbmt[table_name], dbht[table_name]) tables[table_name] = newTable - except Exception, e: + self.tables_json = tables + self.db_hash = dbmd5 + self.table_hashes = dbht + except Exception as e: logging.error("ERROR: problem loading json file: " + file_json + e) - self.tables_json = tables - self.db_hash = dbmd5 - self.table_hashes = dbht - # def __DBMD5Compare(self): pass diff --git a/libs/fingerprint_index.py b/libs/fingerprint_index.py index 6b79dba..523890a 100644 --- a/libs/fingerprint_index.py +++ b/libs/fingerprint_index.py @@ -52,20 +52,19 @@ class FingerprintIndex: md5_list TEXT, file_name TEXT); ''') - logging.info("Successfully created index table") + logging.info("Successfully created index table") + self.__populateIndex(fp_dir) + logging.info("Successfully populated the index") except: - raise FingerprintIndexWrite("Error creating an index file") + raise FingerprintIndexWrite("Error creating an index file") finally: if self.db_conn: self.db_conn.close() self.db_conn = None - self.__populateIndex(fp_dir) - - + # def __populateIndex(self, fp_dir): - # - # read each file, pull md5, add row to database + """ read each file, pull md5, add row to database """ failCount = 0 finCount = 0 try: @@ -75,12 +74,13 @@ class FingerprintIndex: for file in files: try: fq_file = fp_dir + os.path.sep + file - print ("importJson file=={}".format(fq_file)) + # print ("importJson file=={}".format(fq_file)) db.importJson(fq_file) - print("db_hash=={}".format(db.db_hash)) - print("table_hashes={}".format(db.table_hashes)) + self.__insertRecord(db.db_hash, db.table_hashes.values(), file) + # print("db_hash=={}".format(db.db_hash)) + # print("table_hashes={}".format(db.table_hashes)) #md5_all = __createMD5Index(dbht) - + return finCount = finCount+1 except: failCount = failCount+1 @@ -88,17 +88,18 @@ class FingerprintIndex: pass logging.info("Completed populating the index. Completed: {} Failed: {} ".format(str(finCount), str(failCount))) - - # def __insertRecord(self, md5_all, md5_list, filename): try: + logging.info("INSERT INTO md5_index VALUES(?, ?, ?): {}; {}; {}".format(md5_all, md5_list, filename)) self.db_conn.execute( ''' INSERT INTO md5_index VALUES(?, ?, ?) ''', md5_all, md5_list, filename) - except: - pass + except Exception as e: + print e + logging.error("Error inserting a row") + raise FingerprintIndexWrite("Error inserting a row") # def __checkIntegrity(self):