diff --git a/README.rst b/README.rst index 9530f3b9..bca7493b 100644 --- a/README.rst +++ b/README.rst @@ -430,7 +430,7 @@ Command Line Tool Usage options=[--dry-run, --install-new, binary packages from an older --reinstall, --verbose] version to a newer one. -r, --removepkg, [options] [package...], Removes a previously installed - --check-deps, --tag Slackware binary packages, + --check-deps, --tag, --checklist Slackware binary packages, options=[-warn, -preserve, -copy, while writing a progress report -keep] to the standard output. -d, --display, [package...] Display the installed packages @@ -1391,6 +1391,15 @@ Remove packages with by TAG: Are you sure to remove 14 packages [y/N]? +Remove packages using dialog utility: + +.. code-block:: bash + + $ slpkg -r _SBo --tag --checklist + +.. image:: https://raw.githubusercontent.com/dslackw/images/master/slpkg/pythondialog.png + :target: https://github.com/dslackw/slpkg + Build and install packages that have added to the queue: diff --git a/man/slpkg.8 b/man/slpkg.8 index 6c7e586b..e1de74b6 100644 --- a/man/slpkg.8 +++ b/man/slpkg.8 @@ -35,7 +35,7 @@ Usage: slpkg Commands: [-q [build, install, build-install]] [-g [print, edit=[editor]]] [-l [repository], --index, --installed] - [-c [repository], --upgrade, --skip=[...] --resolve-off] + [-c [repository], --upgrade, --skip=[...], --resolve-off] [-s [repository] [package...], --resolve-off] [-t [repository] [package], --check-deps, --graph=[type]] [-p [repository] [package], --color=[]] @@ -44,7 +44,7 @@ Usage: slpkg Commands: [-f [package...]] [-i [options] [package...]] [-u [options] [package...]] - [-r [options] [package...], --check-deps] + [-r [options] [package...], --check-deps, --tag, --checklist] [-d [package...]] .SH DESCRIPTION @@ -127,7 +127,7 @@ with the option "slpkg -s ". .PP Additional options: .PP -\fB--graph=[type]\fP : Drawing dependencies diagram. (example for type: ascii, image.x11, image.png etc.) +\fB--graph=[type]\fP : Drawing dependencies diagram. (example for type: ascii, image.x11, image.png etc. Require pygraphviz) .PP \fB--tree\fP : Switch to tree view. @@ -219,7 +219,7 @@ Additional options: .PP \fB--check-deps\fP : Check if installed packages used by other packages. .PP -\fB--graph=[type]\fP : Drawing dependencies graph. (example for type: ascii, image.x11, image.png etc.) +\fB--graph=[type]\fP : Drawing dependencies graph. (example for type: ascii, image.x11, image.png etc. Require pygraphviz) .SS -p, --desk, print packages description \fBslpkg\fP \fB-p\fP <\fIrepository\fP> <\fIname of package\fP>, \fB--color=[]\fP @@ -264,7 +264,7 @@ and will skip any packages that do not already have a version installed. More information please read "man upgradepkg". .SS -r, --removepkg, remove previously installed Slackware binary packages -\fBslpkg\fP \fB-r\fP \fB[-copy, -keep, -preserve, -warn]\fP <\fInames of packages\fP>, \fB--check-deps\fP, \fB--tag\fP +\fBslpkg\fP \fB-r\fP \fB[-copy, -keep, -preserve, -warn]\fP <\fInames of packages\fP>, \fB--check-deps\fP, \fB--tag\fP, \fB--checklist\fP .PP Removes a previously installed Slackware package, while writing a progress report to the standard output. A package may be specified either by the full package name (as @@ -278,6 +278,8 @@ Additional options: \fB--check-deps\fP : Check if installed packages used by other packages. .pp \fB--tag\fP : Remove packages with by TAG. +.PP +\fB--checklist\fP : Remove packages using dialog utility. (Require python2-pythondialog) .SS -d, --display, display the installed packages contents and file list \fBslpkg\fP \fB-d\fP <\fInames of packages\fP> diff --git a/requirements.txt b/requirements.txt index 8feb66ab..2343e940 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,6 @@ # [OPTIONAL] # perl 5 # graph-easy >= 0.75 (drawing dependencies ascii diagram) +# +# [OPTIONAL] +# python2-pythondialog >= 3.3.0 (Python interface to the UNIX dialog utility) diff --git a/setup.py b/setup.py index 27c6557d..57b166a4 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ DOCS_REQUIREMENTS = [] TESTS_REQUIREMENTS = [] OPTIONAL_REQUIREMENTS = [ "pygraphviz >= 1.3rc2", + "python2-pythondialog >= 3.3.0" ] # Non-Python/non-PyPI optional dependencies: # ascii diagram: graph-easy (available from SBo repository) diff --git a/slpkg/arguments.py b/slpkg/arguments.py index 2a1099ea..a72224b8 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -87,7 +87,7 @@ Optional arguments: only packages installed on the system. -c, --check, [repository], --upgrade, Check, view and install updated - --skip=[...] --resolve--off packages from repositories. + --skip=[...], --resolve--off packages from repositories. -s, --sync, [repository] [package...], Sync packages. Install packages --resolve-off directly from remote repositories with all dependencies. @@ -117,7 +117,7 @@ Optional arguments: options=[--dry-run, --install-new, binary packages from an older --reinstall, --verbose] version to a newer one. -r, --removepkg, [options] [package...], Removes a previously installed - --check-deps, --tag Slackware binary packages, + --check-deps, --tag, --checklist Slackware binary packages, options=[-warn, -preserve, -copy, while writing a progress report -keep] to the standard output. -d, --display, [package...] Display the installed packages @@ -152,7 +152,7 @@ def usage(repo): [-q [build, install, build-install]] [-g [print, edit=[editor]]] [-l [repository], --index, --installed] - [-c [repository], --upgrade, --skip=[...] --resolve-off] + [-c [repository], --upgrade, --skip=[...], --resolve-off] [-s [repository] [package...], --resolve-off] [-t [repository] [package], --check-deps, --graph=[type]] [-p [repository] [package], --color=[]] @@ -161,7 +161,7 @@ def usage(repo): [-f [package...]] [-i [options] [package...]] [-u [options] [package...]] - [-r [options] [package...], --check-deps, --tag] + [-r [options] [package...], --check-deps, --tag, --checklist] [-d [package...]] """ error_repo = "" diff --git a/slpkg/checklist.py b/slpkg/checklist.py index fe52dc42..e1a9d083 100644 --- a/slpkg/checklist.py +++ b/slpkg/checklist.py @@ -23,13 +23,18 @@ from __future__ import unicode_literals -from dialog import Dialog class CheckList(object): """Create dialog checklist """ def __init__(self, data, text, title, backtitle): + try: + from dialog import Dialog + except ImportError: + print("Require 'pythondialog': Install with '# slpkg -s sbo " + "python2-pythondialog'") + raise SystemExit() self.d = Dialog(dialog="dialog", autowidgetsize=True) self.data = data self.text = text @@ -41,15 +46,16 @@ class CheckList(object): def run(self): """Run dialog checklist """ - pkgs = [] - for item in self.data: - pkgs.append((item, "", False)) - - code, self.tags = self.d.checklist(text=self.text, - height=20, width=65, list_height=13, - choices=pkgs, - title=self.title, - backtitle=self.backtitle) + try: + choice = [] + for item in self.data: + choice.append((item, "", False)) + code, self.tags = self.d.checklist( + text=self.text, height=20, width=65, list_height=13, + choices=choice, title=self.title, backtitle=self.backtitle) + except KeyboardInterrupt: + print("") + raise SystemExit() if code == "ok": self.ununicode_to_string() return self.ununicode diff --git a/slpkg/main.py b/slpkg/main.py index 79e86a9f..a590dd57 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -457,8 +457,8 @@ class ArgParse(object): """ packages = self.args[1:] options = ["-r", "--removepkg"] - additional_options = ["--check-deps", "--tag"] - flag = extra = "" + additional_options = ["--check-deps", "--tag", "--checklist"] + flag, extra = "", [] flags = [ "-warn", "-preserve", @@ -466,10 +466,11 @@ class ArgParse(object): "-keep" ] if len(self.args) > 1 and self.args[0] in options: - if self.args[-1] in additional_options: - index = additional_options.index(self.args[-1]) - extra = additional_options[index] - packages = self.args[1:-1] + for additional in additional_options: + if additional in self.args: + extra.append(additional) + self.args.remove(additional) + packages = self.args[1:] if self.args[1] in flags: flag = self.args[1] packages = self.args[2:] diff --git a/slpkg/pkg/manager.py b/slpkg/pkg/manager.py index 8e15a8d7..387b3b41 100644 --- a/slpkg/pkg/manager.py +++ b/slpkg/pkg/manager.py @@ -34,6 +34,8 @@ from slpkg.messages import Msg from slpkg.splitting import split_package from slpkg.__metadata__ import MetaData as _meta_ +from slpkg.checklist import CheckList + class PackageManager(object): """Package manager class for install, upgrade, @@ -141,22 +143,19 @@ class PackageManager(object): raise SystemExit() return remove_dep - def _view_removed(self): - """View packages before removed + def _get_removed(self): + """Manage removed packages by extra options """ - removed = [] + removed, packages = [], [] print("\nPackages with name matching [ {0}{1}{2} ]\n".format( self.meta.color["CYAN"], ", ".join(self.binary), self.meta.color["ENDC"])) - if self.extra == "--tag": + if "--tag" in self.extra: for pkg in find_package("", self.meta.pkg_path): for tag in self.binary: if pkg.endswith(tag): - print("[ {0}delete{1} ] --> {2}".format( - self.meta.color["RED"], self.meta.color["ENDC"], - pkg)) removed.append(split_package(pkg)[0]) - self._sizes(pkg) + packages.append(pkg) if not removed: self.msg.pkg_not_found("", tag, "Can't remove", "") else: @@ -166,15 +165,33 @@ class PackageManager(object): package = find_package("{0}{1}{2}".format( name, ver, self.meta.sp), self.meta.pkg_path) if pkg and name == pkg: - print("[ {0}delete{1} ] --> {2}".format( - self.meta.color["RED"], self.meta.color["ENDC"], - package[0])) removed.append(pkg) - self._sizes(package[0]) + packages.append(package[0]) else: self.msg.pkg_not_found("", pkg, "Can't remove", "") - self._calc_sizes() - self._remove_summary() + return removed, packages + + def _view_removed(self): + """View packages before removed + """ + removed, packages = self._get_removed() + if packages and "--checklist" in self.extra: + removed = [] + pkgs = CheckList(packages, + "Hit 'spacebar' to choose packages to remove", + "Remove", + "{0} {1}".format(self.meta.__all__, + self.meta.__version__)).run() + for rmv in pkgs: + removed.append(split_package(rmv)[0]) + self.meta.default_answer = "y" + else: + for rmv, pkg in zip(removed, packages): + print("[ {0}delete{1} ] --> {2}".format( + self.meta.color["RED"], self.meta.color["ENDC"], pkg)) + self._sizes(pkg) + self._calc_sizes() + self._remove_summary() return removed def _calc_sizes(self): @@ -271,7 +288,7 @@ class PackageManager(object): def _check_if_used(self, removes): """Check package if dependencies for another package before removed""" - if self.extra == "--check-deps": + if "--check-deps" in self.extra: print("") view = False package, dependency = [], []