From 35e0d2f74fd0abfaaf16bf3075b78be46786a285 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@cd1c1023-2f26-0410-ae45-c471fc1f0318> Date: Sat, 10 Nov 2007 11:14:07 +0000 Subject: [PATCH] genial way to handle smart packages gentoo compatibility git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@648 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- client/equo | 2 +- client/equoTools.py | 44 ++++++++++++++++++++++++++++++-------- libraries/databaseTools.py | 25 ++++++++++++++++++++++ libraries/entropyTools.py | 26 ++++++++++++++++------ libraries/smartTools.py | 11 +++++++++- 5 files changed, 91 insertions(+), 17 deletions(-) diff --git a/client/equo b/client/equo index 29f25f903..cb40f243d 100644 --- a/client/equo +++ b/client/equo @@ -90,7 +90,7 @@ def print_help(): print_info(" \t\tUnpack and run applications") print_info(" \t\t"+darkgreen("application")+red("\t\t generate a smart application for the provided atoms (experimental)")) print_info(" \t\t\t"+red("--empty")+"\t\t set all dependencies as unsatisfied") - print_info(" \t\tA .tbz2 package that can contain multiple packages (breaks Gentoo compatibility)") + print_info(" \t\tA .tbz2 package that can contain multiple packages (Gentoo compatible)") print_info(" \t\t"+darkgreen("package")+red("\t\t generate a smart package for the provided atoms")) print_info(" \t"+blue("database")+brown("\t handle installed packages database")) diff --git a/client/equoTools.py b/client/equoTools.py index 52698ce80..d9f8b2272 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -29,7 +29,7 @@ from entropyConstants import * from clientConstants import * from outputTools import * from remoteTools import downloadData, getOnlineContent -from entropyTools import unpackGzip, unpackBzip2, compareMd5, bytesIntoHuman, askquestion, getRandomNumber, isjustname, dep_getkey, compareVersions as entropyCompareVersions, filterDuplicatedEntries, extractDuplicatedEntries, uncompressTarBz2, extractXpak, applicationLockCheck, countdown, isRoot, spliturl, remove_tag, dep_striptag, md5sum, allocateMaskedFile, istextfile, isnumber, extractEdb, getNewerVersion, getNewerVersionTag +from entropyTools import unpackGzip, unpackBzip2, compareMd5, bytesIntoHuman, askquestion, getRandomNumber, isjustname, dep_getkey, compareVersions as entropyCompareVersions, filterDuplicatedEntries, extractDuplicatedEntries, uncompressTarBz2, extractXpak, applicationLockCheck, countdown, isRoot, spliturl, remove_tag, dep_striptag, md5sum, allocateMaskedFile, istextfile, isnumber, extractEdb, getNewerVersion, getNewerVersionTag, unpackXpak from databaseTools import etpDatabase, openRepositoryDatabase, openClientDatabase, openGenericDatabase, fetchRepositoryIfNotAvailable import triggerTools import confTools @@ -1568,8 +1568,28 @@ def installPackageIntoGentooDatabase(infoDict,packageFile): shutil.rmtree(extractPath) else: os.makedirs(extractPath) - xpakstatus = extractXpak(packageFile,extractPath) - if extractXpak != None: + + smartpackage = False + if infoDict['repository'].endswith(".tbz2"): + smartpackage = etpRepositories[infoDict['repository']]['smartpackage'] + + if (smartpackage): + # we need to get the .xpak from database + xdbconn = openRepositoryDatabase(infoDict['repository']) + xpakdata = xdbconn.retrieveXpakMetadata(infoDict['idpackage']) + if xpakdata: + # save into a file + f = open(extractPath+".xpak","wb") + f.write(xpakdata) + f.flush() + f.close() + xpakstatus = unpackXpak(extractPath+".xpak",extractPath) + else: + xpakstatus = None + xdbconn.closeDB() + else: + xpakstatus = extractXpak(packageFile,extractPath) + if xpakstatus != None: if not os.path.isdir(portDbDir+infoDict['category']): os.makedirs(portDbDir+infoDict['category']) destination = portDbDir+infoDict['category']+"/"+infoDict['name']+"-"+infoDict['version'] @@ -2003,7 +2023,7 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False return 1,-1 branches = (etpConst['branch'],) # FIXME: this will be automatically handled - updateList = [] + updateList = set() fineList = set() removedList = set() syncRepositories() @@ -2022,14 +2042,12 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False slot = clientDbconn.retrieveSlot(idpackage) atomkey = category+"/"+name # search in the packages - # FIXME: is it useful to do two atomMatch ?? match = atomMatch(atom) if match[0] == -1: # atom has been changed, or removed? tainted = True else: # not changed, is the revision changed? adbconn = openRepositoryDatabase(match[1]) arevision = adbconn.retrieveRevision(match[0]) - #print atom,"<-->",adbconn.retrieveAtom(match[0]) adbconn.closeDB() if revision != arevision: tainted = True @@ -2042,11 +2060,16 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False mdbconn = openRepositoryDatabase(matchresults[1]) matchatom = mdbconn.retrieveAtom(matchresults[0]) mdbconn.closeDB() - #print green("match: ")+str(matchresults[0]) - updateList.append([matchatom,matchresults]) + updateList.add([matchatom,matchresults]) else: removedList.add(idpackage) - #print red("not match: ")+str(atom) + # look for packages that would match key with any slot (for eg, gcc updates), slot changes handling + matchresults = atomMatch(atomkey, matchBranches = branches) + if matchresults[0] != -1: + mdbconn = openRepositoryDatabase(matchresults[1]) + matchatom = mdbconn.retrieveAtom(matchresults[0]) + mdbconn.closeDB() + updateList.add([matchatom,matchresults]) else: fineList.add(idpackage) @@ -2137,9 +2160,12 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, etpRepositories[basefile]['pkgpath'] = os.path.realpath(pkg) # extra info added etpRepositories[basefile]['configprotect'] = set() etpRepositories[basefile]['configprotectmask'] = set() + etpRepositories[basefile]['smartpackage'] = False # extra info added mydbconn = openGenericDatabase(dbfile) # read all idpackages myidpackages = mydbconn.listAllIdpackages() # all branches admitted from external files + if len(myidpackages) > 1: + etpRepositories[basefile]['smartpackage'] = True for myidpackage in myidpackages: foundAtoms.append([pkg,(int(myidpackage),basefile)]) mydbconn.closeDB() diff --git a/libraries/databaseTools.py b/libraries/databaseTools.py index ed5053657..799e2ccfa 100644 --- a/libraries/databaseTools.py +++ b/libraries/databaseTools.py @@ -3050,6 +3050,31 @@ class etpDatabase: break return sane + def createXpakTable(self): + self.cursor.execute('CREATE TABLE xpakdata ( idpackage INTEGER PRIMARY KEY, data BLOB );') + self.commitChanges() + + def storeXpakMetadata(self, idpackage, blob): + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"storeXpakMetadata: called.") + self.cursor.execute( + 'INSERT into xpakdata VALUES ' + '(?,?)', ( int(idpackage), buffer(blob), ) + ) + self.commitChanges() + + def retrieveXpakMetadata(self, idpackage): + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"retrieveXpakMetadata: called.") + try: + self.cursor.execute('SELECT data from xpakdata where idpackage = "'+str(idpackage)+'"') + mydata = self.cursor.fetchone() + if not mydata: + return "" + else: + return mydata[0] + except: + return "" + pass + # # FIXME: remove these when 1.0 will be out # diff --git a/libraries/entropyTools.py b/libraries/entropyTools.py index 9fe8d82e7..584f80cd9 100644 --- a/libraries/entropyTools.py +++ b/libraries/entropyTools.py @@ -144,23 +144,37 @@ def extractXpak(tbz2file,tmpdir = None): entropyLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"extractXpak: called -> "+tbz2file) # extract xpak content xpakpath = suckXpak(tbz2file, etpConst['packagestmpdir']) - + return unpackXpak(xpakpath,tmpdir) + +def readXpak(tbz2file): + xpakpath = suckXpak(tbz2file, etpConst['entropyunpackdir']) + f = open(xpakpath,"rb") + f.seek(0,2) + size = f.tell() + f.seek(0) + data = f.read(size) + f.close() + os.remove(xpakpath) + return data + +def unpackXpak(xpakfile, tmpdir = None): try: import xpak + import shutil if tmpdir is None: - tmpdir = etpConst['packagestmpdir']+"/"+os.path.basename(tbz2file)[:-5]+"/" + tmpdir = etpConst['packagestmpdir']+"/"+os.path.basename(xpakfile)[:-5]+"/" if os.path.isdir(tmpdir): - spawnCommand("rm -rf "+tmpdir) + shutil.rmtree(tmpdir,True) os.makedirs(tmpdir) - xpakdata = xpak.getboth(xpakpath) + xpakdata = xpak.getboth(xpakfile) xpak.xpand(xpakdata,tmpdir) try: - os.remove(xpakpath) + os.remove(xpakfile) except: pass - return tmpdir except: return None + return tmpdir def suckXpak(tbz2file, outputpath): entropyLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"suckXpak: called -> "+tbz2file+" and "+outputpath) diff --git a/libraries/smartTools.py b/libraries/smartTools.py index 635fea689..dc1a32c31 100644 --- a/libraries/smartTools.py +++ b/libraries/smartTools.py @@ -124,6 +124,7 @@ def smartpackagegenerator(matchedPackages): dbfile = unpackdir+"/db/merged.db" mergeDbconn = openGenericDatabase(dbfile, dbname = "client") mergeDbconn.initializeDatabase() + mergeDbconn.createXpakTable() tmpdbfile = dbfile+"--readingdata" for package in matchedPackages: print_info(darkgreen(" * ")+brown(matchedAtoms[package]['atom'])+": "+red("collecting Entropy metadata")) @@ -131,10 +132,18 @@ def smartpackagegenerator(matchedPackages): # read db and add data to mergeDbconn mydbconn = openGenericDatabase(tmpdbfile) idpackages = mydbconn.listAllIdpackages() + for myidpackage in idpackages: data = mydbconn.getPackageData(myidpackage) + if len(idpackages) == 1: + # just a plain package that would like to become smart + xpakdata = entropyTools.readXpak(etpConst['entropyworkdir']+"/"+matchedAtoms[package]['download']) + else: + xpakdata = mydbconn.retrieveXpakMetadata(myidpackage) # already a smart package # add - mergeDbconn.handlePackage(etpData = data, forcedRevision = matchedAtoms[package]['revision']) # get the original rev + idpk, rev, y, status = mergeDbconn.handlePackage(etpData = data, forcedRevision = matchedAtoms[package]['revision']) # get the original rev + del y + mergeDbconn.storeXpakMetadata(idpk,xpakdata) mydbconn.closeDB() os.remove(tmpdbfile)