diff --git a/TODO b/TODO index 40066abc9..065821cb4 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ TODO list: - world: first fetch all, then upgrade - - multipackage: clean tool - implement a sane exception infrastructure - mirrors: one more and in random order - trigger: Regenerating cracklib dictionary diff --git a/libraries/reagentTools.py b/libraries/reagentTools.py index 7211a9ae7..11b99c0db 100644 --- a/libraries/reagentTools.py +++ b/libraries/reagentTools.py @@ -712,6 +712,72 @@ def database(options): dbconn.closeDB() return 0 + elif (options[0] == "multiremove"): + + print_info(green(" * ")+red("Scanning packages that would be removed ..."), back = True) + + branch = etpConst['branch'] + atoms = [] + for opt in options[1:]: + if (opt.startswith("--branch=")) and (len(opt.split("=")) == 2): + branch = opt.split("=")[1] + else: + atoms.append(opt) + + pkglist = set() + dbconn = databaseTools.openServerDatabase(readOnly = True, noUpload = True) + allidpackages = dbconn.listAllIdpackages() + + idpackages = set() + if not atoms: + # choose all + for idpackage in allidpackages: + if dbconn.isInjected(idpackage): + idpackages.add(idpackage) + else: + for atom in atoms: + match = dbconn.atomMatch(atom, matchBranches = (branch,), multiMatch = True, packagesFilter = False) + if match[1] != 0: + print_warning(red("Attention, no match for: ")+bold(atom)) + else: + for x in match[0]: + if dbconn.isInjected(x): + idpackages.add(x) + + # check if atoms were found + if not idpackages: + dbconn.closeDB() + print_error(brown(" * ")+red("No packages found.")) + return 11 + + print_info(green(" * ")+blue("These are the packages that would be removed from the database:")) + + for idpackage in idpackages: + pkgatom = dbconn.retrieveAtom(idpackage) + branch = dbconn.retrieveBranch(idpackage) + print_info(darkred(" (*) ")+blue("[")+red(branch)+blue("] ")+brown(pkgatom)) + + # ask to continue + rc = askquestion(" Would you like to continue ?") + if rc == "No": + return 0 + + dbconn.closeDB() + del dbconn + dbconn = databaseTools.openServerDatabase(readOnly = False, noUpload = True) + + print_info(green(" * ")+red("Removing selected packages ...")) + + # open db + for idpackage in idpackages: + pkgatom = dbconn.retrieveAtom(idpackage) + print_info(green(" * ")+red("Removing package: ")+bold(pkgatom)+red(" ...")) + dbconn.removePackage(idpackage) + print_info(green(" * ")+red("All the selected packages have been removed as requested.")) + dbconn.closeDB() + del dbconn + return 0 + # used by reagent elif (options[0] == "md5check"): diff --git a/server/reagent b/server/reagent index 140feca8e..c53d6c9ff 100644 --- a/server/reagent +++ b/server/reagent @@ -57,6 +57,8 @@ def print_help(): print_info(" \t\t"+green("search")+"\t\t\t\t Search a package inside the Entropy packages database") print_info(" \t\t"+green("remove")+"\t\t\t\t Remove a package or a list of packages") print_info(" \t\t\t"+red("--branch=")+"\t Choose which branch of the package to remove") + print_info(" \t\t"+green("multiremove")+"\t\t\t Remove injected packages (all if no atom specified, multipackage)") + print_info(" \t\t\t"+red("--branch=")+"\t Choose which branch of the package to remove") print_info(" \t\t"+green("create-empty-database")+"\t\t Create an empty Entropy database file in the specified ") print_info(" \t\t"+green("switchbranch")+"\t\t\t Switch to the specified branch, a package, a list of packages, world") print_info(" \t\t"+green("md5check")+"\t\t\t Check digest of a package, a list of packages, world")