From 466cf0b3410bf019f16b89c87b6840c91e7eccfb Mon Sep 17 00:00:00 2001 From: lxnay Date: Tue, 27 May 2008 17:20:37 +0000 Subject: [PATCH] Entropy/Database Interface/Socket Interface/Server Interface: - since database_checksum() output (using python hash()) is strictly dependant on Python releases and arches, add an option to use md5 instead git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@2001 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- libraries/entropy.py | 50 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/libraries/entropy.py b/libraries/entropy.py index 43d723e34..c84e9c2c8 100644 --- a/libraries/entropy.py +++ b/libraries/entropy.py @@ -6014,7 +6014,7 @@ class RepoInterface: mydbconn.commitChanges() # now verify if both checksums match result = False - mychecksum = mydbconn.database_checksum(do_order = True, strict = False) + mychecksum = mydbconn.database_checksum(do_order = True, strict = False, strings = True) if checksum == mychecksum: result = True else: @@ -15429,7 +15429,7 @@ class RepositorySocketServerInterface(SocketHostInterface): dbpath = self.get_database_path(repository, arch, product) dbconn = self.HostInterface.open_db(dbpath) - mychecksum = dbconn.database_checksum(do_order = True, strict = False) + mychecksum = dbconn.database_checksum(do_order = True, strict = False, strings = True) myids = dbconn.listAllIdpackages() foreign_idpackages = set(foreign_idpackages) @@ -15606,7 +15606,7 @@ class RepositorySocketServerInterface(SocketHostInterface): mydb.createAllIndexes() mydb.commitChanges() self.updateProgress( - str(mydb.database_checksum()), + str(mydb.database_checksum(do_order = True, strict = False, strings = True)), importance = 1, type = "info" ) @@ -22230,8 +22230,8 @@ class EntropyDatabaseInterface: columns.append(row[1]) return columns - def database_checksum(self, do_order = False, strict = True): - # primary keys are now autoincrement + def database_checksum(self, do_order = False, strict = True, strings = False): + idpackage_order = '' category_order = '' license_order = '' @@ -22242,20 +22242,48 @@ class EntropyDatabaseInterface: license_order = ' order by license' flags_order = ' order by chost' + def do_update_md5(m, cursor): + mydata = cursor.fetchall() + for record in mydata: + for item in record: + m.update(str(item)) + + if strings: + import md5 + m = md5.new() + self.cursor.execute('select idpackage,atom,name,version,versiontag,revision,branch,slot,etpapi,trigger from baseinfo'+idpackage_order) - a_hash = hash(tuple(self.cursor.fetchall())) + if strings: + do_update_md5(m,self.cursor) + else: + a_hash = hash(tuple(self.cursor.fetchall())) self.cursor.execute('select idpackage,description,homepage,download,size,digest,datecreation from extrainfo'+idpackage_order) - b_hash = hash(tuple(self.cursor.fetchall())) + if strings: + do_update_md5(m,self.cursor) + else: + b_hash = hash(tuple(self.cursor.fetchall())) self.cursor.execute('select category from categories'+category_order) - c_hash = hash(tuple(self.cursor.fetchall())) + if strings: + do_update_md5(m,self.cursor) + else: + c_hash = hash(tuple(self.cursor.fetchall())) d_hash = '0' e_hash = '0' if strict: self.cursor.execute('select * from licenses'+license_order) - d_hash = hash(tuple(self.cursor.fetchall())) + if strings: + do_update_md5(m,self.cursor) + else: + d_hash = hash(tuple(self.cursor.fetchall())) self.cursor.execute('select * from flags'+flags_order) - e_hash = hash(tuple(self.cursor.fetchall())) - return str(a_hash)+":"+str(b_hash)+":"+str(c_hash)+":"+str(d_hash)+":"+str(e_hash) + if strings: + do_update_md5(m,self.cursor) + else: + e_hash = hash(tuple(self.cursor.fetchall())) + if strings: + return m.hexdigest() + else: + return str(a_hash)+":"+str(b_hash)+":"+str(c_hash)+":"+str(d_hash)+":"+str(e_hash) ########################################################