Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jcdubacq/apt-moreutils
base: 95f1583ac3
...
head fork: jcdubacq/apt-moreutils
compare: restricted-list
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 74 additions and 28 deletions.
  1. +71 −28 bin/apt-tree
  2. +3 −0  man/apt-tree.1
View
99 bin/apt-tree
@@ -6,30 +6,41 @@ import apt_pkg
import apt.progress.text
import os
progusage="apt-tree [options]"
-shortoptions=["h","d","i","m","u","s"]
+shortoptions=["h","d","i","m","u","p:","s"]
longoptions=["help",
"depends",
"indirect",
"manual",
"unneeded",
- "signal",
+ "packages",
"help-nroff"]
-argstype=['','','','','','','']
+argstype=['','','','','','string','','']
explanation=['This help text',
'Do not consider Recommends as dependencies',
'Display non-trivial dependencies',
'Display manually selected packages',
'Display packages required but not installed followed by -',
- 'Signal non-trivial dependencies with a + sign'
+ 'Select packages (default all installed packages)'
]
provided={}
installed={}
manual={}
+visited={}
evident={}
nonEvident={}
unneeded={}
+queue=[]
+displaytext="\nThe codes for the display is by order of precedence:\
+M manually installed\
+S mentioned in a non-trivial dependency and installed\
+\
+s mentioned in a non-trivial dependency and uninstalled"
+
+def outputPackage(code,name):
+ """output a package name with appropriate formatting"""
+ print "%s|%s" % (code,name)
def markEvident(name,why):
"""mark a package as a direct dependency of another package"""
@@ -37,8 +48,13 @@ def markEvident(name,why):
if len(provided[name])>1:
markProviders(name,why)
else:
- evident[provided[name].keys()[0]]=True
+ newname=provided[name].keys()[0]
+ if newname not in visited and newname not in queue:
+ queue.append(newname)
+ evident[newname]=True
else:
+ if name not in visited and name not in queue:
+ queue.append(name)
evident[name]=True
@@ -46,6 +62,8 @@ def markProviders(name,why):
"""mark providers of virtual package"""
for provider in provided[name]:
nonEvident[provider]=True
+ if provider not in visited and provider not in queue:
+ queue.append(provider)
def markNonEvident(name,why):
"""mark a package as a dependency where some choice was made"""
@@ -53,8 +71,13 @@ def markNonEvident(name,why):
if len(provided[name])>1:
markProviders(name,why)
else:
- nonEvident[provided[name].keys()[0]]=True
+ newname=provided[name].keys()[0]
+ if newname not in visited and newname not in queue:
+ queue.append(newname)
+ nonEvident[newname]=True
else:
+ if name not in visited and name not in queue:
+ queue.append(name)
nonEvident[name]=True
@@ -109,7 +132,8 @@ def main():
xmanual=0
xindirect=0
xunneeded=0
- signal=0
+ packages=[]
+
for o,a in opts:
if o in ("-h","--help"):
usage()
@@ -131,8 +155,8 @@ def main():
xall=0
xindirect=1
xtypes=['Depends','Pre-Depends']
- elif o in ("-s","--signal"):
- signal=1
+ elif o in ("-p","--package"):
+ packages.extend(a.split(' '))
else:
assert False, "unhandled option"
if xall==1:
@@ -159,7 +183,19 @@ def main():
if version != None and pkg.current_state == apt_pkg.CURSTATE_INSTALLED:
installed[pkg.name]=True
manual[pkg.name]=not(depcache.is_auto_installed(pkg))
- for pkg in sorted(cache.packages, key=lambda pkg: pkg.name):
+ if len(packages) == 0:
+ for pkg in sorted(cache.packages, key=lambda pkg: pkg.name):
+ version=pkg.current_ver
+ if version != None and pkg.current_state == apt_pkg.CURSTATE_INSTALLED:
+ packages.append(pkg.name)
+ packages.sort()
+ queue.extend(list(packages))
+ while len(queue) > 0:
+ pkgn=queue.pop()
+ visited[pkgn] = True
+ if pkgn not in installed and pkgn not in provided:
+ continue
+ pkg=cache[pkgn]
version=pkg.current_ver
if version != None and pkg.current_state == apt_pkg.CURSTATE_INSTALLED:
clauses=[]
@@ -173,31 +209,38 @@ def main():
else:
for deppkg,depver,depnum in subclause:
markNonEvident(deppkg,pkg.name)
- if xmanual==1:
- for pkgname in manual:
- if manual[pkgname]:
+ forget={}
+ for pkgname in sorted(visited.keys()):
+ if (pkgname not in manual):
+ continue
+ if manual[pkgname]:
+ forget[pkgname]=True
+ if xmanual==1:
if pkgname in installed:
- if signal==1:
- print pkgname + "+"
- else:
- print pkgname
+ outputPackage("M",pkgname)
else:
- print pkgname + "-"
- if xunneeded==1:
- for pkgname in evident:
- if (pkgname in manual) and (manual[pkgname]):
- continue
- if pkgname not in installed:
- print pkgname + "-"
- for pkgname in nonEvident:
- if (pkgname in manual and manual[pkgname]) or (pkgname in evident):
+ outputPackage("m",pkgname) # WTF ?
+ for pkgname in sorted(visited.keys()):
+ if (pkgname not in evident):
+ continue
+ if (pkgname in forget):
+ continue
+ if pkgname not in installed:
+ forget[pkgname]=True
+ if xunneeded==1:
+ outputPackage("s",pkgname)
+ for pkgname in sorted(visited.keys()):
+ if (pkgname not in nonEvident):
+ continue
+ if (pkgname in forget):
continue
+ forget[pkgname]=True
if pkgname in installed:
if xindirect==1:
- print pkgname
+ outputPackage("S",pkgname)
else:
if xunneeded==1:
- print pkgname + "-"
+ outputPackage("s",pkgname)
if __name__ == '__main__':
main()
View
3  man/apt-tree.1
@@ -44,6 +44,9 @@ Display packages required but not installed followed by \-
.TP
\fB\-s\fR|\fB\-\-signal\fR
Signal non\-trivial dependencies with a + sign
+.TP
+\fB-p\fR|\fB--packages\fR\fIstring\fR
+Select packages (default all installed packages)
.SH "AUTHOR"
Copyright Jean-Christophe Dubacq 2013
.SH "COPYING"

No commit comments for this range

Something went wrong with that request. Please try again.