From 4ce9d576aa4d5adbbfa7a58af629e92a6191c9ad Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@cd1c1023-2f26-0410-ae45-c471fc1f0318> Date: Fri, 18 Jan 2008 20:23:42 +0000 Subject: [PATCH] fixed reagent database query tools - NOT THIS ONE, WAIT THE NEXT ONE git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1066 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- client/text_query.py | 125 ++++++++++++++++++++++++-------------- libraries/reagentTools.py | 14 ++--- 2 files changed, 85 insertions(+), 54 deletions(-) diff --git a/client/text_query.py b/client/text_query.py index 0d8c01b29..74b5460ed 100644 --- a/client/text_query.py +++ b/client/text_query.py @@ -93,11 +93,16 @@ def query(options): -def searchInstalledPackages(packages, idreturn = False, dbconn = None): +def searchInstalledPackages(packages, idreturn = False, dbconn = None, EquoConnection = None): - global Equo - if Equo == None: - Equo = EquoInterface() + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() if (not idreturn) and (not etpUi['quiet']): print_info(brown(" @@ ")+darkgreen("Searching...")) @@ -132,11 +137,16 @@ def searchInstalledPackages(packages, idreturn = False, dbconn = None): return 0 -def searchBelongs(files, idreturn = False, dbconn = None): +def searchBelongs(files, idreturn = False, dbconn = None, EquoConnection = None): - global Equo - if Equo == None: - Equo = EquoInterface() + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() if (not idreturn) and (not etpUi['quiet']): print_info(darkred(" @@ ")+darkgreen("Belong Search...")) @@ -172,7 +182,7 @@ def searchBelongs(files, idreturn = False, dbconn = None): elif (etpUi['quiet']): print clientDbconn.retrieveAtom(idpackage) else: - printPackageInfo(idpackage, clientDbconn, clientSearch = True) + printPackageInfo(idpackage, clientDbconn, clientSearch = True, EquoConnection = EquoConnection) if (not idreturn) and (not etpUi['quiet']): print_info(blue(" Keyword: ")+bold("\t"+xfile)) print_info(blue(" Found: ")+bold("\t"+str(len(result)))+red(" entries")) @@ -183,11 +193,16 @@ def searchBelongs(files, idreturn = False, dbconn = None): -def searchDepends(atoms, idreturn = False, dbconn = None): +def searchDepends(atoms, idreturn = False, dbconn = None, EquoConnection = None): - global Equo - if Equo == None: - Equo = EquoInterface() + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() if (not idreturn) and (not etpUi['quiet']): print_info(darkred(" @@ ")+darkgreen("Depends Search...")) @@ -215,9 +230,9 @@ def searchDepends(atoms, idreturn = False, dbconn = None): dataInfo.add(idpackage) else: if (etpUi['verbose']): - printPackageInfo(idpackage, dbconn, clientSearch = True) + printPackageInfo(idpackage, dbconn, clientSearch = True, EquoConnection = EquoConnection) else: - printPackageInfo(idpackage, dbconn, clientSearch = True, strictOutput = True) + printPackageInfo(idpackage, dbconn, clientSearch = True, strictOutput = True, EquoConnection = EquoConnection) # print info if (not idreturn) and (not etpUi['quiet']): print_info(blue(" Keyword: ")+bold("\t"+atom)) @@ -236,11 +251,17 @@ def searchDepends(atoms, idreturn = False, dbconn = None): return dataInfo return 0 -def searchNeeded(atoms, idreturn = False, dbconn = None): +def searchNeeded(atoms, idreturn = False, dbconn = None, EquoConnection = None): + + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() - global Equo - if Equo == None: - Equo = EquoInterface() if (not idreturn) and (not etpUi['quiet']): print_info(darkred(" @@ ")+darkgreen("Needed Search...")) @@ -272,11 +293,17 @@ def searchNeeded(atoms, idreturn = False, dbconn = None): return dataInfo return 0 -def searchEclass(eclasses, idreturn = False, dbconn = None): +def searchEclass(eclasses, idreturn = False, dbconn = None, EquoConnection = None): + + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() - global Equo - if Equo == None: - Equo = EquoInterface() if (not idreturn) and (not etpUi['quiet']): print_info(darkred(" @@ ")+darkgreen("Eclass Search...")) @@ -300,9 +327,9 @@ def searchEclass(eclasses, idreturn = False, dbconn = None): print myatom else: if (etpUi['verbose']): - printPackageInfo(idpackage, clientDbconn, clientSearch = True) + printPackageInfo(idpackage, clientDbconn, clientSearch = True, EquoConnection = EquoConnection) else: - printPackageInfo(idpackage, clientDbconn, clientSearch = True, strictOutput = True) + printPackageInfo(idpackage, clientDbconn, clientSearch = True, strictOutput = True, EquoConnection = EquoConnection) if (not etpUi['quiet']): print_info(blue(" Found: ")+bold("\t"+str(len(matches)))+red(" packages")) @@ -310,11 +337,7 @@ def searchEclass(eclasses, idreturn = False, dbconn = None): return dataInfo return 0 -def searchFiles(atoms, idreturn = False, dbconn = None): - - global Equo - if Equo == None: - Equo = EquoInterface() +def searchFiles(atoms, idreturn = False, dbconn = None, EquoConnection = None): if (not idreturn) and (not etpUi['quiet']): print_info(darkred(" @@ ")+darkgreen("Files Search...")) @@ -323,7 +346,7 @@ def searchFiles(atoms, idreturn = False, dbconn = None): results = searchInstalledPackages(atoms, idreturn = True) clientDbconn = Equo.clientDbconn else: - results = searchInstalledPackages(atoms, idreturn = True, dbconn = dbconn) + results = searchInstalledPackages(atoms, idreturn = True, dbconn = dbconn, EquoConnection = EquoConnection) clientDbconn = dbconn dataInfo = set() # when idreturn is True @@ -610,11 +633,16 @@ def searchSlottedPackages(slots, datareturn = False, dbconn = None): return foundPackages return 0 -def searchTaggedPackages(tags, datareturn = False, dbconn = None): +def searchTaggedPackages(tags, datareturn = False, dbconn = None, EquoConnection = None): - global Equo - if Equo == None: - Equo = EquoInterface() + if EquoConnection != None: + Equo = EquoConnection + else: + try: + if Equo == None: + Equo = EquoInterface() + except NameError: + Equo = EquoInterface() foundPackages = {} dbclose = True @@ -640,7 +668,7 @@ def searchTaggedPackages(tags, datareturn = False, dbconn = None): foundPackages[repo][result[1]] = result[0] # print info if (not datareturn): - printPackageInfo(result[1],dbconn) + printPackageInfo(result[1],dbconn, EquoConnection = EquoConnection) if (not datareturn) and (not etpUi['quiet']): print_info(blue(" Keyword: ")+bold("\t"+tag)) print_info(blue(" Found: ")+bold("\t"+str(len(results)))+red(" entries")) @@ -679,7 +707,7 @@ def searchDescription(descriptions, idreturn = False): ''' Internal functions ''' -def __searchDescriptions(descriptions, dbconn, idreturn = False): +def __searchDescriptions(descriptions, dbconn, idreturn = False, EquoConnection = None): dataInfo = set() # when idreturn is True mydescdata = {} @@ -694,7 +722,7 @@ def __searchDescriptions(descriptions, dbconn, idreturn = False): elif (etpUi['quiet']): print dbconn.retrieveAtom(idpackage) else: - printPackageInfo(idpackage,dbconn) + printPackageInfo(idpackage,dbconn, EquoConnection = EquoConnection) # print info if (not idreturn) and (not etpUi['quiet']): print_info(blue(" Keyword: ")+bold("\t"+desc)) @@ -747,15 +775,18 @@ def printPackageInfo(idpackage, dbconn, clientSearch = False, strictOutput = Fal installedVer = "Not installed" installedTag = "N/A" installedRev = "N/A" - pkginstalled = Equo.clientDbconn.atomMatch(Equo.entropyTools.dep_getkey(pkgatom), matchSlot = pkgslot) - if (pkginstalled[1] == 0): - idx = pkginstalled[0] - # found - installedVer = Equo.clientDbconn.retrieveVersion(idx) - installedTag = Equo.clientDbconn.retrieveVersionTag(idx) - if not installedTag: - installedTag = "NoTag" - installedRev = Equo.clientDbconn.retrieveRevision(idx) + try: + pkginstalled = Equo.clientDbconn.atomMatch(Equo.entropyTools.dep_getkey(pkgatom), matchSlot = pkgslot) + if (pkginstalled[1] == 0): + idx = pkginstalled[0] + # found + installedVer = Equo.clientDbconn.retrieveVersion(idx) + installedTag = Equo.clientDbconn.retrieveVersionTag(idx) + if not installedTag: + installedTag = "NoTag" + installedRev = Equo.clientDbconn.retrieveRevision(idx) + except: + clientSearch = True print_info(red(" @@ Package: ")+bold(pkgatom)+"\t\t"+blue("branch: ")+bold(pkgbranch)) if (not strictOutput): diff --git a/libraries/reagentTools.py b/libraries/reagentTools.py index 6e0978b4e..eace03605 100644 --- a/libraries/reagentTools.py +++ b/libraries/reagentTools.py @@ -1041,31 +1041,31 @@ def database(options): if myopts[0] == "tags": if (len(myopts) > 1): - rc = text_query.searchTaggedPackages(myopts[1:], dbconn = dbconn) + rc = text_query.searchTaggedPackages(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "files": if (len(myopts) > 1): - rc = text_query.searchFiles(myopts[1:], dbconn = dbconn) + rc = text_query.searchFiles(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "belongs": if (len(myopts) > 1): - rc = text_query.searchBelongs(myopts[1:], dbconn = dbconn) + rc = text_query.searchBelongs(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "description": if (len(myopts) > 1): - text_query.__searchDescriptions(myopts[1:], dbconn = dbconn) + text_query.__searchDescriptions(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "needed": if (len(myopts) > 1): - text_query.searchNeeded(myopts[1:], dbconn = dbconn) + text_query.searchNeeded(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "depends": if (len(myopts) > 1): - text_query.searchDepends(myopts[1:], dbconn = dbconn) + text_query.searchDepends(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) if myopts[0] == "eclass": if (len(myopts) > 1): - text_query.searchEclass(myopts[1:], dbconn = dbconn) + text_query.searchEclass(myopts[1:], dbconn = dbconn, EquoConnection = Entropy) dbconn.closeDB() return rc