From 7fe6fc07aedfc3154dd709232e77fa0e466eabd3 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jul 2015 06:37:41 +0300 Subject: [PATCH] Added additional option --- README.rst | 24 +++++++++++++++++++++++- man/slpkg.8 | 7 ++++--- slpkg/arguments.py | 6 +++--- slpkg/main.py | 7 ++++++- slpkg/tracking.py | 35 ++++++++++++++++++++++++++--------- 5 files changed, 62 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index c865fb55..e243b602 100644 --- a/README.rst +++ b/README.rst @@ -683,7 +683,7 @@ and also displays installed packages: .. code-block:: bash $ slpkg -t sbo brasero - Reading package lists... Done + Resolving dependencies... Done +========================= | brasero dependencies : @@ -701,6 +701,28 @@ and also displays installed packages: | +--5 libunique + + Check if dependencies used: + + $ slpkg -t sbo Flask --check-deps + Resolving dependencies... Done + + +============================= + | Package Flask dependencies : + +============================= + \ + +---[ Tree of dependencies ] + | + +--1: pysetuptools is dependency --> Flask, bpython, pip, pylint + | + +--2: MarkupSafe is dependency --> Flask + | + +--3: itsdangerous is dependency --> Flask + | + +--4: Jinja2 is dependency --> Flask + | + +--5: werkzeug is dependency --> Flask + Check if your packages is up to date or changes in ChangeLog.txt: diff --git a/man/slpkg.8 b/man/slpkg.8 index 18634f7c..47e8861c 100644 --- a/man/slpkg.8 +++ b/man/slpkg.8 @@ -32,7 +32,7 @@ Usage: slpkg Commands: [-l [repository], --index, --installed] [-c [repository] --upgrade, --skip=[...] --resolve-off] [-s [repository] [package...], --resolve-off] - [-t [repository] [package]] + [-t [repository] [package], --check-deps] [-p [repository] [package], --color=[]] [-n [SBo package]] [-F [...]] [-f [...]] [-i [options] [...]] [-u [options] [...]] @@ -163,11 +163,12 @@ dependencies of the package. Switch off automatic resolve dependencies with addi "--resolve-off". .SS -t, --tracking, tracking dependencies -\fBslpkg\fP \fB-t\fP <\fIrepository\fP> <\fIname of package\fP> +\fBslpkg\fP \fB-t\fP <\fIrepository\fP> <\fIname of package\fP>, \fB--check-deps\fP .PP Tracking all dependencies of that package. The sequence shown is that you must follow to correctly install package. -Also you can check if the installed package has all the required dependencies. +Also you can check if the installed package has all the required dependencies and with +additional option "--check-deps" if used by other packages. .SS -p, --desk, print packages description \fBslpkg\fP \fB-p\fP <\fIrepository\fP> <\fIname of package\fP>, \fB--color=[]\fP diff --git a/slpkg/arguments.py b/slpkg/arguments.py index dc834c58..c590a801 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -85,8 +85,8 @@ Optional arguments: -s, --sync, [repository] [package...], Sync packages. Install packages --resolve-off directly from remote repositories with all dependencies. - -t, --tracking, [repository] [package] Tracking package dependencies and - print package dependenies tree with + -t, --tracking, [repository] [package], Tracking package dependencies and + --check-deps print package dependenies tree with highlight if packages is installed. -p, --desc, [repository] [package], Print description of a package --color=[] directly from the repository and @@ -140,7 +140,7 @@ def usage(repo): [-l [repository], --index, --installed] [-c [repository], --upgrade, --skip=[...] --resolve-off] [-s [repository] [package...], --resolve-off] - [-t [repository] [package]] + [-t [repository] [package], --check-deps] [-p [repository] [package], --color=[]] [-n [SBo package]] [-F [...]] [-f [...]] [-i [options] [...]] [-u [options] [...]] diff --git a/slpkg/main.py b/slpkg/main.py index c95c70da..6c784429 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -291,9 +291,14 @@ class ArgParse(object): """Tracking package dependencies """ options = ["-t", "--tracking"] + flag = ["--check-deps"] if (len(self.args) == 3 and self.args[0] in options and self.args[1] in self.meta.repositories): - track_dep(self.args[2], self.args[1]) + track_dep(self.args[2], self.args[1], flag="") + elif (len(self.args) == 4 and self.args[0] in options and + self.args[1] in self.meta.repositories and + self.args[3] == flag[0]): + track_dep(self.args[2], self.args[1], flag[0]) elif (len(self.args) > 1 and self.args[0] in options and self.args[1] not in self.meta.repositories): usage(self.args[1]) diff --git a/slpkg/tracking.py b/slpkg/tracking.py index 338bf8d7..f3f36a1b 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -36,7 +36,7 @@ from binary.search import search_pkg from binary.dependency import Dependencies -def track_dep(name, repo): +def track_dep(name, repo, flag): """ View tree of dependencies and also highlight packages with color green @@ -75,25 +75,42 @@ def track_dep(name, repo): _meta_.color["YELLOW"], _meta_.color["ENDC"])) index = 0 for pkg in dependencies: + used = "" + if flag == "--check-deps": + used = "{0} {1}{2}{3}".format( + "is dependency -->", _meta_.color["CYAN"], + ", ".join(check_used(pkg)), _meta_.color["ENDC"]) index += 1 installed = "" if find_package(pkg + _meta_.sp, _meta_.pkg_path): if _meta_.use_colors in ["off", "OFF"]: installed = "*" print(" |") - print(" {0}{1}: {2}{3}{4} {5}".format("+--", index, - _meta_.color["GREEN"], - pkg, _meta_.color["ENDC"], - installed)) + print(" {0}{1}: {2}{3}{4} {5}{6}".format( + "+--", index, _meta_.color["GREEN"], pkg, + _meta_.color["ENDC"], installed, used)) else: print(" |") - print(" {0}{1}: {2}{3}{4} {5}".format("+--", index, - _meta_.color["RED"], pkg, - _meta_.color["ENDC"], - installed)) + print(" {0}{1}: {2}{3}{4} {5}{6}".format( + "+--", index, _meta_.color["RED"], pkg, + _meta_.color["ENDC"], installed, used)) if _meta_.use_colors in ["off", "OFF"]: print("\n *: Installed\n") else: print("") # new line at end else: print("\nNo package was found to match\n") + + +def check_used(pkg): + """Check if dependencies used + """ + used = [] + dep_path = _meta_.log_path + "dep/" + logs = find_package("", dep_path) + for log in logs: + deps = Utils().read_file(dep_path + log) + for dep in deps.splitlines(): + if pkg == dep: + used.append(log) + return used