diff --git a/client/equoTools.py b/client/equoTools.py index f4d127ce2..75d70c30d 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -1662,7 +1662,7 @@ def installPackageIntoGentooDatabase(infoDict,packageFile): @input pointer(clientDbconn): client database connection pointer (optional) @output: 0 = all fine, >0 = error! ''' -def installPackageIntoDatabase(idpackage,repository, clientDbconn = None): +def installPackageIntoDatabase(idpackage, repository, clientDbconn = None): # fetch info dbconn = openRepositoryDatabase(repository) data = dbconn.getPackageData(idpackage) @@ -1678,7 +1678,7 @@ def installPackageIntoDatabase(idpackage,repository, clientDbconn = None): if clientDbconn == None: closedb = True clientDbconn = openClientDatabase() - idpk, rev, x, status = clientDbconn.addPackage(data, revision = rev, wantedBranch = branch, addBranch = False) + idpk, rev, x, status = clientDbconn.handlePackage(etpData = data, forcedRevision = rev, forcedBranch = True, addBranch = False) del x if (not status): clientDbconn.closeDB() @@ -1740,7 +1740,8 @@ def query(options): if (opt == "--quiet"): equoRequestQuiet = True else: - myopts.append(opt) + if not opt.startswith("-"): + myopts.append(opt) if options[0] == "installed": rc = searchInstalledPackages(myopts[1:], quiet = equoRequestQuiet) @@ -1922,7 +1923,7 @@ def database(options): dbconn.closeDB() # filling print_info(" "+bold("(")+darkgreen(str(count))+"/"+blue(total)+bold(")")+red(" Injecting ")+bold(atomName), back = True) - # fill clientDbconn # FIXME write a general client side addPackage function + # fill client database idpk, rev, xx, status = clientDbconn.addPackage(atomInfo, wantedBranch = atomBranch, addBranch = False) # now add the package to the installed table clientDbconn.addPackageToInstalledTable(idpk,x[1]) @@ -2672,6 +2673,7 @@ def installPackages(packages, ask = False, pretend = False, verbose = False, dep installedTag = '' installedRev = clientDbconn.retrieveRevision(idx) actionQueue[pkgatom]['remove'] = idx + actionQueue[pkgatom]['removeatom'] = clientDbconn.retrieveAtom(idx) break clientDbconn.closeDB() @@ -2744,10 +2746,6 @@ def installPackages(packages, ask = False, pretend = False, verbose = False, dep if (not onlyfetch): # install steps.append("install") - # remove - if (actionQueue[pkgatom]['remove'] != -1): - #steps.append("remove") differential remove will be processed by install step - steps.append("removedatabase") steps.append("installdatabase") steps.append("cleanup") @@ -2891,10 +2889,8 @@ def removePackages(packages, ask = False, pretend = False, verbose = False, deps for idpackage in plainRemovalQueue: - #print clientDbconn.retrieveAtom(idpackage) removalQueue.append(idpackage) - # FIXME: complete for idpackage in removalQueue: infoDict = {} infoDict['remove'] = idpackage @@ -3035,13 +3031,13 @@ def stepExecutor(step,infoDict, clientDbconn = None): errormsg = red("An error occured while trying to remove the package. Check if you have enough disk space on your hard disk. Error "+str(output)) print_error(errormsg) elif step == "installdatabase": - print_info(red(" ## ")+blue("Injecting into database: ")+red(os.path.basename(infoDict['download']))) - output = installPackageIntoDatabase(infoDict['idpackage'],infoDict['repository'], clientDbconn) + print_info(red(" ## ")+blue("Injecting into database: ")+red(infoDict['atom'])) + output = installPackageIntoDatabase(infoDict['idpackage'], infoDict['repository'], clientDbconn) if output != 0: errormsg = red("An error occured while trying to add the package to the database. What have you done? Error "+str(output)) print_error(errormsg) elif step == "removedatabase": - print_info(red(" ## ")+blue("Removing from database: ")+red(clientDbconn.retrieveAtom(infoDict['remove']))) + print_info(red(" ## ")+blue("Removing from database: ")+red(infoDict['removeatom'])) output = removePackageFromDatabase(infoDict['remove'], clientDbconn) if output != 0: errormsg = red("An error occured while trying to remove the package from database. What have you done? Error "+str(output)) diff --git a/libraries/databaseTools.py b/libraries/databaseTools.py index b3fd38223..22651f5c9 100644 --- a/libraries/databaseTools.py +++ b/libraries/databaseTools.py @@ -216,72 +216,6 @@ def database(options): print_warning(red(" * ")+red("Nothing found.")) else: print - - elif (options[0] == "restore-package-info"): - mypackages = options[1:] - if (len(mypackages) == 0): - print_error(yellow(" * ")+red("Not enough parameters")) - sys.exit(302) - - # sync packages directory - activatorTools.packages(["sync","--ask"]) - - dbconn = etpDatabase(readOnly = False, noUpload = True) - - # validate entries - _mypackages = [] - for pkg in mypackages: - if (dbconn.isPackageAvailable(pkg)): - _mypackages.append(pkg) - mypackages = _mypackages - - if len(mypackages) == 0: - print_error(yellow(" * ")+red("No valid package found. You must specify category/atom-version.")) - sys.exit(303) - - print_info(green(" * ")+red("Reinitializing Entropy database using Packages in the repository ...")) - - # get the file list - pkglist = [] - branches = [] - for pkg in mypackages: - # dump both branches if exist - if (dbconn.isSpecificPackageAvailable(pkg, branch = "stable")): - branches.append("stable") - if (dbconn.isSpecificPackageAvailable(pkg, branch = "unstable")): - branches.append("unstable") - for branch in branches: - idpackage = dbconn.getIDPackage(pkg,branch) - pkgfile = dbconn.retrieveDownloadURL(idpackage) - pkgfile = os.path.basename(pkgfile) - pkglist.append(pkgfile) - - # validate files - _pkglist = [] - for file in pkglist: - if (not os.path.isfile(etpConst['packagesbindir']+"/"+file)): - print_info(yellow(" * ")+red("Attention: ")+bold(file)+red(" does not exist anymore.")) - else: - _pkglist.append(file) - pkglist = _pkglist - - currCounter = 0 - atomsnumber = len(pkglist) - for pkg in pkglist: - print_info(green(" * ")+red("Analyzing: ")+bold(pkg), back = True) - currCounter += 1 - print_info(green(" (")+ blue(str(currCounter))+"/"+red(str(atomsnumber))+green(") ")+red("Analyzing ")+bold(pkg)+red(" ...")) - etpData = reagentTools.extractPkgData(etpConst['packagesbindir']+"/"+pkg) - # remove shait - entropyTools.spawnCommand("rm -rf "+etpConst['packagestmpdir']+"/"+pkg) - # fill the db entry - dbconn.handlePackage(etpData) - dbconn.commitChanges() - - dbconn.commitChanges() - dbconn.closeDB() - print_info(green(" * ")+red("Successfully restored database information for the chosen packages.")) - elif (options[0] == "create-empty-database"): mypath = options[1:] @@ -931,7 +865,7 @@ class etpDatabase: # this function manages the submitted package # if it does not exist, it fires up addPackage # otherwise it fires up updatePackage - def handlePackage(self, etpData, forceBump = False): + def handlePackage(self, etpData, addBranch = True, forcedRevision = -1, forcedBranch = False): if (self.readOnly): dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"handlePackage: Cannot handle this in read only.") @@ -944,12 +878,18 @@ class etpDatabase: dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"handlePackage: called.") if (not self.isPackageAvailable(etpData['category']+"/"+etpData['name']+"-"+etpData['version']+versiontag)): - idpk, revision, etpDataUpdated, accepted = self.addPackage(etpData) + if (forcedRevision < 0): + forcedRevision = 0 + if (forcedBranch): + idpk, revision, etpDataUpdated, accepted = self.addPackage(etpData, addBranch = addBranch, revision = forcedRevision, wantedBranch = etpData['branch']) + else: + idpk, revision, etpDataUpdated, accepted = self.addPackage(etpData, addBranch = addBranch, revision = forcedRevision) else: - idpk, revision, etpDataUpdated, accepted = self.updatePackage(etpData,forceBump) + idpk, revision, etpDataUpdated, accepted = self.updatePackage(etpData, forcedRevision) # branch and revision info will be overwritten return idpk, revision, etpDataUpdated, accepted - # default add an unstable package + + # FIXME: default add an unstable package ~~ use indexes def addPackage(self, etpData, revision = 0, wantedBranch = "unstable", addBranch = True): if (self.readOnly): @@ -1223,7 +1163,7 @@ class etpDatabase: # Update already available atom in db # returns True,revision if the package has been updated # returns False,revision if not - def updatePackage(self, etpData, forceBump = False): + def updatePackage(self, etpData, forcedRevision = -1): if (self.readOnly): dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"updatePackage: Cannot handle this in read only.") @@ -1235,57 +1175,48 @@ class etpDatabase: versiontag = "" if (etpData['versiontag']): versiontag = "-"+etpData['versiontag'] - - # are there any stable packages? - searchsimilarStable = self.searchSimilarPackages(etpData['category']+"/"+etpData['name'], branch = "stable") - dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: here is the list of similar stable packages found for "+etpData['category']+"/"+etpData['name']+": "+str(searchsimilarStable)) - # filter the one with the same version - stableFound = False - for pkg in searchsimilarStable: - # get version - idpackage = pkg[1] - dbStoredVer = self.retrieveVersion(idpackage) - dbStoredVerTag = self.retrieveVersionTag(idpackage) - if (etpData['version'] == dbStoredVer) and (etpData['versiontag'] == dbStoredVerTag): - # found it ! - stableFound = True - break - - if (stableFound): - - dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: mark the branch of this updated package, stable too") - etpData['branch'] = "stable" - - - # get selected package revision + # build atom string pkgatom = etpData['category'] + "/" + etpData['name'] + "-" + etpData['version']+versiontag - idpackage = self.getIDPackage(pkgatom,etpData['branch']) - - if (idpackage != -1): - curRevision = self.retrieveRevision(idpackage) + + # if client opened the database, before starting the update, remove previous entries - same atom, all branches + if (self.clientDatabase): + + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"updatePackage: client request. Removing duplicated entries.") + atomInfos = self.searchPackages(pkgatom) + for atomInfo in atomInfos: + idpackage = atomInfo[1] + self.removePackage(idpackage) + + if (forcedRevision < 0): + forcedRevision = 0 # FIXME: this shouldn't happen + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: removal complete. Now spawning addPackage.") + x,y,z,accepted = self.addPackage(etpData, revision = forcedRevision, wantedBranch = etpData['branch']) + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: returned back from addPackage.") + return x,y,z,accepted + else: - curRevision = 0 + # update package in etpData['branch'] + # get its package revision + idpackage = self.getIDPackage(pkgatom,etpData['branch']) + if (forcedRevision == -1): + if (idpackage != -1): + curRevision = self.retrieveRevision(idpackage) + else: + curRevision = 0 + else: + curRevision = forcedRevision - # do I really have to update the database entry? If the information are the same, drop all - oldPkgAtom = etpData['category']+"/"+etpData['name']+"-"+etpData['version']+versiontag - rc = self.comparePackagesData(etpData, oldPkgAtom, branchToQuery = etpData['branch']) - if (rc) and (not forceBump): - return idpackage, curRevision, etpData, False # package not accepted + if (idpackage != -1): # remove old package in branch + self.removePackage(idpackage) + if (forcedRevision == -1): + curRevision += 1 + + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: current revision set to "+str(curRevision)) - # OTHERWISE: - # remove the current selected package, if exists - if (idpackage != -1): - self.removePackage(idpackage) - - # bump revision nevertheless - curRevision += 1 - - dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: current revision set to "+str(curRevision)) - - # add the new one - dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: complete. Now spawning addPackage.") - x,y,z,accepted = self.addPackage(etpData,curRevision,etpData['branch']) - return x,y,z,accepted + # add the new one + dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"updatePackage: complete. Now spawning addPackage.") + x,y,z,accepted = self.addPackage(etpData, revision = curRevision, wantedBranch = etpData['branch']) + return x,y,z,accepted def removePackage(self,idpackage): @@ -2760,6 +2691,7 @@ class etpDatabase: result.append(row) return result + # FIXME: remove this, we don't just have stable/unstable branches def searchStablePackages(self,atom): dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"searchStablePackages: called for "+atom) category = atom.split("/")[0] @@ -2770,6 +2702,7 @@ class etpDatabase: result.append(row) return result + # FIXME: also remove this def searchUnstablePackages(self,atom): dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"searchUnstablePackages: called for "+atom) category = atom.split("/")[0] diff --git a/libraries/entropyConstants.py b/libraries/entropyConstants.py index c0caa3165..8ffc35200 100644 --- a/libraries/entropyConstants.py +++ b/libraries/entropyConstants.py @@ -32,7 +32,7 @@ import sys # DO NOT EDIT THIS UNLESS YOU KNOW WHAT YOU'RE DOING !! etpData = { 'name': u"", # the Package Name - 'version': u"", # the Package version plus our -etpXX revision + 'version': u"", # the Package version 'description': u"", # the Package description 'category': u"", # the gentoo category 'chost': u"", # the CHOST used to compile it diff --git a/libraries/reagentTools.py b/libraries/reagentTools.py index 8f607e104..67a9e29fa 100644 --- a/libraries/reagentTools.py +++ b/libraries/reagentTools.py @@ -40,9 +40,9 @@ reagentLog = logTools.LogFile(level=etpConst['reagentloglevel'],filename = etpCo # reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"testFunction: example. ") -def generator(package, enzymeRequestBump = False, dbconnection = None, enzymeRequestBranch = "unstable"): +def generator(package, dbconnection = None, enzymeRequestBranch = "unstable"): - reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"generator: called -> Package: "+str(package)+" | enzymeRequestBump: "+str(enzymeRequestBump)+" | dbconnection: "+str(dbconnection)) + reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"generator: called -> Package: "+str(package)+" | dbconnection: "+str(dbconnection)) # check if the package provided is valid validFile = False @@ -62,7 +62,7 @@ def generator(package, enzymeRequestBump = False, dbconnection = None, enzymeReq else: dbconn = dbconnection - idpk, revision, etpDataUpdated, accepted = dbconn.handlePackage(etpData,enzymeRequestBump) + idpk, revision, etpDataUpdated, accepted = dbconn.handlePackage(etpData) # add package info to our official repository etpConst['officialrepositoryname'] if (accepted): @@ -95,12 +95,9 @@ def enzyme(options): reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"enzyme: called -> options: "+str(options)) - enzymeRequestBump = False enzymeRequestBranch = "unstable" #_atoms = [] for i in options: - if ( i == "--force-bump" ): - enzymeRequestBump = True if ( i == "--branch=" and len(i.split("=")) == 2 ): mybranch = i.split("=")[1] if (mybranch): @@ -128,7 +125,7 @@ def enzyme(options): tbz2name = tbz2.split("/")[len(tbz2.split("/"))-1] print_info(" ("+str(counter)+"/"+str(totalCounter)+") Processing "+tbz2name) tbz2path = etpConst['packagesstoredir']+"/"+tbz2 - rc, newFileName, idpk = generator(tbz2path, enzymeRequestBump, dbconn, enzymeRequestBranch) + rc, newFileName, idpk = generator(tbz2path, dbconn, enzymeRequestBranch) if (rc): etpCreated += 1 # move the file with its new name diff --git a/server/reagent b/server/reagent index 1c54cb377..590a60fd2 100644 --- a/server/reagent +++ b/server/reagent @@ -42,13 +42,11 @@ def print_help(): print_info(" --nocolor\t\tdisable colorized output") print_info(blue("Tools available: ")) print_info(" \t"+green("enzyme")+yellow("\t\t to analyze enzyme store directory")) - print_info(" \t\t"+red("--force-bump")+"\t\t\t\t to force the revision bumping of the package entries") print_info(" \t\t"+red("--branch=[stable,unstable]")+"\t\t to force a specific branch") print_info(" \t"+green(bold("database"))+yellow("\t Entropy database tool manager")) print_info(" \t\t"+red("--initialize")+"\t\t\t\t (Re)Initialize the Entropy packages database [DO NOT USE THIS]") print_info(" \t\t"+red("statistics")+"\t\t\t\t Show Entropy database statistics.") print_info(" \t\t"+green("search")+"\t\t\t\t\t Search a package inside the Entropy packages database") - print_info(" \t\t"+green("restore-package-info")+"\t\t\t Reinitialize a package entry looking at the current install") print_info(" \t\t"+green(bold("remove"))+"\t\t\t\t\t Remove a package or a list of packages") print_info(" \t\t\t"+red("--branch=[stable,unstable]")+"\t Choose which branch of the package to remove") print_info(" \t\t"+green("create-empty-database")+"\t\t\t Create an empty Entropy database file in the specified ")