MOD: added db-metadata-md5 to the fingerprint. it is a md5 sum of a concatenation of each table md5 sum

This commit is contained in:
JohnE 2015-11-19 02:04:21 -08:00
parent dd653d60d7
commit 9a0c1a9439
1 changed files with 33 additions and 8 deletions

View File

@ -107,14 +107,20 @@ class FingerprintDB:
finally: finally:
fh.close() fh.close()
except Exception, ex: except Exception, ex:
print ex logging.error(ex)
raise FingerprintWrite("Problem writing the fingerprint to a file") raise FingerprintWrite("Problem writing the fingerprint to a file")
# import fingerprint from a json file # import fingerprint from a json file
def importJson(self, filejson): def importJson(self, filejson):
""" import fingerprint from a json file """ """ 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): def compareDB(self, filejson):
@ -147,7 +153,7 @@ class FingerprintDB:
print "ERROR: problem loading json file: " + file_json print "ERROR: problem loading json file: " + file_json
print e print e
return tables return (tables, dbht)
def __DBMD5Compare(self): def __DBMD5Compare(self):
@ -218,7 +224,7 @@ class FingerprintDB:
def __FuzzyTable(): def __FuzzyTable():
return return
#
def __openDB(self, filein): def __openDB(self, filein):
conn = sqlite3.connect(filein) conn = sqlite3.connect(filein)
cur = conn.cursor() cur = conn.cursor()
@ -234,7 +240,7 @@ class FingerprintDB:
self.tables[newTable.name()] = newTable self.tables[newTable.name()] = newTable
return return
#
def debugFingerprint(self): def debugFingerprint(self):
if self.tables: if self.tables:
myDict = self.tables myDict = self.tables
@ -242,15 +248,14 @@ class FingerprintDB:
myDict = self.tablesJson myDict = self.tablesJson
else: else:
return return
#
keys = myDict.keys() keys = myDict.keys()
for key in keys: for key in keys:
print "[[ TABLE: <" + key + "> ]]" print "[[ TABLE: <" + key + "> ]]"
tableDef = myDict[key] tableDef = myDict[key]
#print str(tableDef.SQLstr())
tableDef.toJSON() tableDef.toJSON()
#
def __writeFingerprint(self, filehandle): def __writeFingerprint(self, filehandle):
ahash = {} ahash = {}
thash = {} thash = {}
@ -260,6 +265,7 @@ class FingerprintDB:
ahash['_file-metadata'] = mhash ahash['_file-metadata'] = mhash
ahash['db-metadata'] = dmhash ahash['db-metadata'] = dmhash
ahash['db-metadata-hashes'] = shash ahash['db-metadata-hashes'] = shash
ahash['db-metadata-md5'] = None
ahash['tables'] = thash ahash['tables'] = thash
try: try:
@ -283,8 +289,27 @@ class FingerprintDB:
dmhash[table] = self.tables[table].SQLstr() dmhash[table] = self.tables[table].SQLstr()
shash[table] = self.tables[table].sqlStrHash shash[table] = self.tables[table].sqlStrHash
ahash['db-metadata-md5'] = self.__createMD5Index(shash)
json.dump(ahash, filehandle, sort_keys=True, indent=4) 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): def setAppName(self, name):
self.app_name = name self.app_name = name