diff --git a/libs/fingerprint.py b/libs/fingerprint.py index e1974bc..73ad1a2 100644 --- a/libs/fingerprint.py +++ b/libs/fingerprint.py @@ -107,14 +107,20 @@ class FingerprintDB: finally: fh.close() except Exception, ex: - print ex + logging.error(ex) raise FingerprintWrite("Problem writing the fingerprint to a file") # import fingerprint from a json file def importJson(self, filejson): """ import fingerprint from a json file """ - self.tablesJson = self.__importJsonDBSchema(filejson) + (self.tablesJson, dummy) = self.__importJsonDBSchema(filejson) + + # + def importJsonIndex(self): + """ import fingerprint from a json file, return the MD5 sums """ + (dummy, dbht) = self.__importJsonDBSchema(filejson) + return dbht # def compareDB(self, filejson): @@ -147,7 +153,7 @@ class FingerprintDB: print "ERROR: problem loading json file: " + file_json print e - return tables + return (tables, dbht) def __DBMD5Compare(self): @@ -218,7 +224,7 @@ class FingerprintDB: def __FuzzyTable(): return - + # def __openDB(self, filein): conn = sqlite3.connect(filein) cur = conn.cursor() @@ -234,7 +240,7 @@ class FingerprintDB: self.tables[newTable.name()] = newTable return - + # def debugFingerprint(self): if self.tables: myDict = self.tables @@ -242,15 +248,14 @@ class FingerprintDB: myDict = self.tablesJson else: return - + # keys = myDict.keys() for key in keys: print "[[ TABLE: <" + key + "> ]]" tableDef = myDict[key] - #print str(tableDef.SQLstr()) tableDef.toJSON() - + # def __writeFingerprint(self, filehandle): ahash = {} thash = {} @@ -260,6 +265,7 @@ class FingerprintDB: ahash['_file-metadata'] = mhash ahash['db-metadata'] = dmhash ahash['db-metadata-hashes'] = shash + ahash['db-metadata-md5'] = None ahash['tables'] = thash try: @@ -283,8 +289,27 @@ class FingerprintDB: dmhash[table] = self.tables[table].SQLstr() shash[table] = self.tables[table].sqlStrHash + ahash['db-metadata-md5'] = self.__createMD5Index(shash) + json.dump(ahash, filehandle, sort_keys=True, indent=4) + # + def __createMD5Index(self, dbht): + retval = "hieeee!!!" + concat_str = "" + try: + bitchasskeys = dbht.keys() + bitchasskeys.sort() + for key in bitchasskeys: + concat_str += dbht[key] + m = hashlib.md5() + m.update(concat_str) + retval = m.hexdigest() + except Exception, ex: + logging.error(ex) + raise FingerprintMD5("Problem creating a MD5 sum") + return retval + # def setAppName(self, name): self.app_name = name