rewritten dependency sorting function
git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@518 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
+68
-46
@@ -553,7 +553,7 @@ def getDependencies(packageInfo):
|
||||
'''
|
||||
installed_depcache = {}
|
||||
repo_test_depcache = {}
|
||||
def filterSatisfiedDependencies(dependencies):
|
||||
def filterSatisfiedDependencies(dependencies, deepdeps = False):
|
||||
|
||||
unsatisfiedDeps = []
|
||||
satisfiedDeps = []
|
||||
@@ -564,6 +564,16 @@ def filterSatisfiedDependencies(dependencies):
|
||||
if (clientDbconn != -1):
|
||||
for dependency in dependencies:
|
||||
|
||||
### conflict
|
||||
if dependency.startswith("!"):
|
||||
testdep = dependency[1:]
|
||||
xmatch = clientDbconn.atomMatch(testdep)
|
||||
if xmatch[0] != -1:
|
||||
unsatisfiedDeps.append(dependency)
|
||||
else:
|
||||
satisfiedDeps.append(dependency)
|
||||
continue
|
||||
|
||||
### caching
|
||||
repo_cached = repo_test_depcache.get(dependency)
|
||||
if repo_cached:
|
||||
@@ -618,14 +628,18 @@ def filterSatisfiedDependencies(dependencies):
|
||||
installed_depcache[dependency]['installedRev'] = installedRev
|
||||
installed_depcache[dependency]['rc'] = rc
|
||||
|
||||
if rc[0] != -1:
|
||||
cmp = compareVersions([repo_pkgver,repo_pkgtag,repo_pkgrev],[installedVer,installedTag,installedRev])
|
||||
#print repo_pkgver+"<-->"+installedVer
|
||||
#print cmp
|
||||
if cmp != 0:
|
||||
#print dependency
|
||||
unsatisfiedDeps.append(dependency)
|
||||
satisfiedDeps.append(dependency)
|
||||
if (rc[0] != -1):
|
||||
if (deepdeps):
|
||||
cmp = compareVersions([repo_pkgver,repo_pkgtag,repo_pkgrev],[installedVer,installedTag,installedRev])
|
||||
#print repo_pkgver+"<-->"+installedVer
|
||||
#print cmp
|
||||
if cmp != 0:
|
||||
#print dependency
|
||||
unsatisfiedDeps.append(dependency)
|
||||
else:
|
||||
satisfiedDeps.append(dependency)
|
||||
else:
|
||||
satisfiedDeps.append(dependency)
|
||||
else:
|
||||
#print " ----> "+dependency+" NOT installed."
|
||||
unsatisfiedDeps.append(dependency)
|
||||
@@ -641,47 +655,65 @@ def filterSatisfiedDependencies(dependencies):
|
||||
'''
|
||||
def generateDependencyTree(atomInfo, emptydeps = False, deepdeps = False):
|
||||
|
||||
print ":::: enter ::::"
|
||||
|
||||
treecache = {}
|
||||
unsatisfiedDeps = getDependencies(atomInfo)
|
||||
remainingDeps = set(unsatisfiedDeps[:]) # needed [:] ?
|
||||
unsatisfiedDeps, xxx = filterSatisfiedDependencies(unsatisfiedDeps, deepdeps = deepdeps)
|
||||
dependenciesNotFound = []
|
||||
treeview = []
|
||||
tree = {}
|
||||
treedepth = 0 # in tree[0] are the conflicts
|
||||
tree[0] = []
|
||||
conflicts = set()
|
||||
depsOk = False
|
||||
|
||||
clientDbconn = openClientDatabase()
|
||||
if (clientDbconn == -1):
|
||||
return [],-1
|
||||
|
||||
while (not depsOk):
|
||||
while 1:
|
||||
treedepth += 1
|
||||
tree[treedepth] = [] # do not use set(), will scramble the order
|
||||
for undep in unsatisfiedDeps:
|
||||
|
||||
passed = treecache.get(undep,None)
|
||||
if passed:
|
||||
try:
|
||||
remainingDeps.remove(undep)
|
||||
except:
|
||||
pass
|
||||
continue
|
||||
tree[treedepth] = []
|
||||
|
||||
for undep in unsatisfiedDeps:
|
||||
|
||||
passed = treecache.get(undep,None) # already analyzed
|
||||
if passed:
|
||||
continue
|
||||
|
||||
# Handling conflicts
|
||||
if undep.startswith("!"):
|
||||
myconflict = undep[1:]
|
||||
# look if the package is installed
|
||||
xmatch = clientDbconn.atomMatch(myconflict)
|
||||
if xmatch[0] != -1:
|
||||
#print "---"
|
||||
#print clientDbconn.retrieveAtom(xmatch[0])
|
||||
#print undep
|
||||
#print "---"
|
||||
conflicts.add(xmatch[0])
|
||||
remainingDeps.remove(undep) # no conflict
|
||||
xmatch = clientDbconn.atomMatch(undep[1:])
|
||||
conflicts.add(xmatch[0])
|
||||
continue
|
||||
|
||||
atom = atomMatch(undep)
|
||||
|
||||
# handle dependencies not found
|
||||
if atom[0] == -1:
|
||||
dependenciesNotFound.append(undep)
|
||||
continue
|
||||
|
||||
# add to the tree level
|
||||
tree[treedepth].append(undep)
|
||||
treecache[undep] = True
|
||||
|
||||
if (not tree[treedepth]):
|
||||
print darkgreen("satisfied: ")+str(tree[treedepth])
|
||||
break
|
||||
else:
|
||||
print red("not satisfied: ")+str(tree[treedepth])
|
||||
# cycle again, load unsatisfiedDeps
|
||||
unsatisfiedDeps = []
|
||||
for dep in tree[treedepth]:
|
||||
atom = atomMatch(dep)
|
||||
deps = getDependencies(atom)
|
||||
if (not emptydeps):
|
||||
deps, xxx = filterSatisfiedDependencies(deps, deepdeps = deepdeps) #FIXME add deepdeps
|
||||
unsatisfiedDeps += deps[:]
|
||||
|
||||
'''
|
||||
for undep in unsatisfiedDeps:
|
||||
|
||||
# obtain its dependencies
|
||||
atom = atomMatch(undep)
|
||||
@@ -709,19 +741,6 @@ def generateDependencyTree(atomInfo, emptydeps = False, deepdeps = False):
|
||||
unsatisfied, satisfied = filterSatisfiedDependencies([undep])
|
||||
if (unsatisfied):
|
||||
tree[treedepth].append(undep)
|
||||
else: # if package is found installed with the same ver, also check for revision
|
||||
# FIXME: this is just a workaround for now, I'll need to rethink this
|
||||
myrev = clientDbconn.retrieveRevision(xmatch[0])
|
||||
myver = clientDbconn.retrieveVersion(xmatch[0])
|
||||
#mytag = clientDbconn.retrieveVersionTag(xmatch[0])
|
||||
repoconn = openRepositoryDatabase(atom[1])
|
||||
availrev = repoconn.retrieveRevision(atom[0])
|
||||
availver = repoconn.retrieveVersion(atom[0])
|
||||
#availtag = repoconn.retrieveVersionTag(atom[0])
|
||||
repoconn.closeDB()
|
||||
|
||||
if (myver == availver) and (myrev != availrev):
|
||||
tree[treedepth].append(undep)
|
||||
else:
|
||||
tree[treedepth].append(undep)
|
||||
treecache[undep] = True
|
||||
@@ -736,6 +755,8 @@ def generateDependencyTree(atomInfo, emptydeps = False, deepdeps = False):
|
||||
depsOk = True
|
||||
else:
|
||||
depsOk = False
|
||||
'''
|
||||
|
||||
|
||||
closeClientDatabase(clientDbconn)
|
||||
|
||||
@@ -1585,7 +1606,7 @@ def database(options):
|
||||
print_info(red(" Depends caching table regenerated successfully."))
|
||||
|
||||
|
||||
def printPackageInfo(idpackage,dbconn, clientSearch = False, strictOutput = False, quiet = False):
|
||||
def printPackageInfo(idpackage, dbconn, clientSearch = False, strictOutput = False, quiet = False):
|
||||
# now fetch essential info
|
||||
pkgatom = dbconn.retrieveAtom(idpackage)
|
||||
|
||||
@@ -1624,6 +1645,7 @@ def printPackageInfo(idpackage,dbconn, clientSearch = False, strictOutput = Fals
|
||||
clientDbconn = openClientDatabase()
|
||||
if (clientDbconn != -1):
|
||||
pkginstalled = clientDbconn.atomMatch(dep_getkey(pkgatom), matchSlot = pkgslot)
|
||||
print pkginstalled
|
||||
if (pkginstalled[1] == 0):
|
||||
idx = pkginstalled[0]
|
||||
# found
|
||||
|
||||
@@ -111,7 +111,7 @@ def searchInstalledPackages(packages, idreturn = False, quiet = False):
|
||||
if (idreturn):
|
||||
dataInfo.append(idpackage)
|
||||
else:
|
||||
printPackageInfo(idpackage,clientDbconn, clientSearch = True, quiet = quiet)
|
||||
printPackageInfo(idpackage, clientDbconn, clientSearch = True, quiet = quiet)
|
||||
|
||||
closeClientDatabase(clientDbconn)
|
||||
|
||||
|
||||
@@ -3104,9 +3104,12 @@ class etpDatabase:
|
||||
cached = self.matchCache.get(atom)
|
||||
if cached:
|
||||
# check if matchSlot and multiMatch were the same
|
||||
if (matchSlot == cached['matchSlot']) and (multiMatch == cached['multiMatch']):
|
||||
if (matchSlot == cached['matchSlot']) \
|
||||
and (multiMatch == cached['multiMatch']) \
|
||||
and (caseSensitive == cached['caseSensitive']) \
|
||||
and (matchBranches == cached['matchBranches']):
|
||||
return cached['result']
|
||||
|
||||
|
||||
# check for direction
|
||||
strippedAtom = entropyTools.dep_getcpv(atom)
|
||||
if atom.endswith("*"):
|
||||
@@ -3202,6 +3205,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,2
|
||||
return -1,2
|
||||
|
||||
@@ -3241,6 +3246,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,3
|
||||
return -1,3 # error, cannot use directions when not specifying version
|
||||
|
||||
@@ -3297,6 +3304,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
@@ -3312,6 +3321,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
@@ -3330,6 +3341,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = similarPackages,0
|
||||
return similarPackages,0
|
||||
|
||||
@@ -3349,6 +3362,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = newerPackage[0],0
|
||||
return newerPackage[0],0
|
||||
|
||||
@@ -3387,11 +3402,14 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
versions = []
|
||||
multiMatchList = []
|
||||
_dbpkginfo = []
|
||||
for x in dbpkginfo:
|
||||
if (matchSlot != None):
|
||||
mslot = self.retrieveSlot(x[0])
|
||||
@@ -3400,6 +3418,8 @@ class etpDatabase:
|
||||
if (multiMatch):
|
||||
multiMatchList.append(x[0])
|
||||
versions.append(x[1])
|
||||
_dbpkginfo.append(x)
|
||||
dbpkginfo = _dbpkginfo
|
||||
|
||||
if (multiMatch):
|
||||
return multiMatchList,0
|
||||
@@ -3408,6 +3428,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
@@ -3426,6 +3448,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = similarPackages,0
|
||||
return similarPackages,0
|
||||
|
||||
@@ -3445,6 +3469,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = newerPackage[0],0
|
||||
return newerPackage[0],0
|
||||
|
||||
@@ -3452,15 +3478,20 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
else:
|
||||
|
||||
#print foundIDs
|
||||
|
||||
# not set, just get the newer version, matching slot choosen if matchSlot != None
|
||||
versionIDs = []
|
||||
#print foundIDs
|
||||
multiMatchList = []
|
||||
_foundIDs = []
|
||||
for list in foundIDs:
|
||||
if (matchSlot == None):
|
||||
versionIDs.append(self.retrieveVersion(list[1]))
|
||||
@@ -3473,6 +3504,8 @@ class etpDatabase:
|
||||
versionIDs.append(self.retrieveVersion(list[1]))
|
||||
if (multiMatch):
|
||||
multiMatchList.append(list[1])
|
||||
_foundIDs.append(list)
|
||||
foundIDs = _foundIDs
|
||||
|
||||
if (multiMatch):
|
||||
return multiMatchList,0
|
||||
@@ -3481,6 +3514,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
@@ -3506,6 +3541,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = newerPackage[1],0
|
||||
return newerPackage[1],0
|
||||
|
||||
@@ -3514,6 +3551,8 @@ class etpDatabase:
|
||||
self.matchCache[atom] = {}
|
||||
self.matchCache[atom]['matchSlot'] = matchSlot
|
||||
self.matchCache[atom]['multiMatch'] = multiMatch
|
||||
self.matchCache[atom]['caseSensitive'] = caseSensitive
|
||||
self.matchCache[atom]['matchBranches'] = matchBranches
|
||||
self.matchCache[atom]['result'] = -1,1
|
||||
return -1,1
|
||||
|
||||
Reference in New Issue
Block a user