Luke Ross

Scripts

git clone https://lukeross.name/projects/scripts.git/

Small scripts

Commit ca5b8a8e78e94ce84e5129d79aa2ea5674d6038d

Fix broken script

Committed 27 Aug 2020 by Luke Ross

FindDebCyclicOrphans/README

@@ -7,5 +7,4 @@ participate in a circular dependency loop.
 This script was taken from that contributed by gnack at
 <http://forums.debian.net/viewtopic.php?f=10&t=74238>.
 
-It got upset on multiarch machines, so I added an easy(-ish) way to exclude
-architectures, and I've also updated it to python 3.
+I've updated it to python 3 and made it work more reliably on multiarch.


FindDebCyclicOrphans/debian/changelog

@@ -0,0 +1,17 @@
+dpkg-find-cyclic-orphans (1.2-1) unstable; urgency=medium
+
+  * Fix incorrect handling of multiatch
+
+ -- Luke Ross <luke@lukeross.name>  Thu, 27 Aug 2020 19:53:00 +0100
+
+dpkg-find-cyclic-orphans (1.1-1) unstable; urgency=medium
+
+  * Fix multiarch infinite loop
+
+ -- Luke Ross <luke@lukeross.name>  Wed, 29 Jul 2020 22:12:00 +0000
+
+dpkg-find-cyclic-orphans (1.0-1) unstable; urgency=medium
+
+  * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>
+
+ -- Luke Ross <luke@lukeross.name>  Sun, 09 Feb 2020 10:07:17 +0000


FindDebCyclicOrphans/debian/compat

@@ -0,0 +1 @@
+9


FindDebCyclicOrphans/debian/control

@@ -0,0 +1,17 @@
+Source: dpkg-find-cyclic-orphans
+Section: python
+Priority: optional
+Maintainer: Luke Ross <luke@lukeross.name>
+Build-Depends: debhelper (>= 7),
+               dh-python (>= 4),
+               python3 (>= 3)
+Standards-Version: 3.9.2
+X-Python-Version: >= 3.0
+
+Package: dpkg-find-cyclic-orphans
+Architecture: all
+Section: python
+Depends: python3-apt, ${misc:Depends}, ${python3:Depends}
+Description: Find cyclic deb loops
+ Find deb packages which are not marked as auto-removable because they
+ participate in a circular dependency loop.


FindDebCyclicOrphans/debian/copyright

@@ -0,0 +1,43 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: dpkg-find-cyclic-orphans
+Upstream-Contact: <preferred name and address to reach the upstream project>
+Source: <url://example.com>
+
+Files: *
+Copyright: <years> <put author's name and email here>
+           <years> <likewise for another author>
+License: <special license>
+ <Put the license of the package here indented by 1 space>
+ <This follows the format of Description: lines in control file>
+ .
+ <Including paragraphs>
+
+# If you want to use GPL v2 or later for the /debian/* files use
+# the following clauses, or change it to suit. Delete these two lines
+Files: debian/*
+Copyright: 2020 Luke Ross <luke@lukeross.name>
+License: GPL-2+
+ This package is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ .
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ .
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>
+ .
+ On Debian systems, the complete text of the GNU General
+ Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
+
+# Please also look if there are files or directories which have a
+# different copyright/license attached and list them here.
+# Please avoid picking licenses with terms that are more restrictive than the
+# packaged work, as it may make Debian's contributions unacceptable upstream.
+#
+# If you need, there are some extra license texts available in two places:
+#   /usr/share/debhelper/dh_make/licenses/
+#   /usr/share/common-licenses/


FindDebCyclicOrphans/debian/install

@@ -0,0 +1 @@
+dpkg-find-cyclic-orphans usr/bin/


FindDebCyclicOrphans/debian/rules

@@ -0,0 +1,4 @@
+#!/usr/bin/make -f
+
+%:
+	dh $@ --with=python3


FindDebCyclicOrphans/find_deb_cyclic_orphans.py -> FindDebCyclicOrphans/dpkg-find-cyclic-orphans

@@ -1,28 +1,17 @@
 #!/usr/bin/env python3
 
-import argparse
 import apt_pkg
 
+holds = ['PreDepends', 'Depends', 'Recommends']
 pkgs = set()
 keeps = set()
+already_held = set()
 virtuals = {}
 
 apt_pkg.init()
 cache = apt_pkg.Cache()
 dep_cache = apt_pkg.DepCache(cache)
 
-parser = argparse.ArgumentParser(
-    description='Check for circular-dependency dpkg orphans')
-parser.add_argument(
-    '-x', nargs='*', help='Exclude these archs', default=[])
-parser.add_argument(
-    '-f', nargs='*',
-    help='Hold these fields, default: PreDepends Depends Recommends',
-    default=['PreDepends', 'Depends', 'Recommends'])
-args = parser.parse_args()
-exclude_archs = args.x
-holds = args.f
-
 
 def flag_provides(virtual, pkg):
     if pkg.current_ver:
@@ -32,24 +21,24 @@ def flag_provides(virtual, pkg):
 
 
 def hold_pkg(pkg):
-    if pkg.name in keeps:
+    if (pkg.name, pkg.architecture) in already_held:
         return
 
+    already_held.add((pkg.name, pkg.architecture))
+
     if pkg.current_ver:
         keeps.add(pkg.name)
         hold_dependencies(pkg.current_ver.depends_list)
 
     if pkg.provides_list:
         flag_provides(pkg.name, pkg)
-        hold_provides(pkg.provides_list, pkg.name)
+        hold_provides(pkg.provides_list)
 
 
-def hold_provides(provides_list, from_pkg=''):
+def hold_provides(provides_list):
     for provides in provides_list:
-        if provides[2].parent_pkg.architecture not in exclude_archs:
-            flag_provides(provides[0], provides[2].parent_pkg)
-            if provides[2].parent_pkg.name != from_pkg:
-                hold_pkg(provides[2].parent_pkg)
+        flag_provides(provides[0], provides[2].parent_pkg)
+        hold_pkg(provides[2].parent_pkg)
 
 
 def hold_dependencies(dep_dict):
@@ -57,8 +46,7 @@ def hold_dependencies(dep_dict):
         if dep_type in holds:
             for dep in deps:
                 for opt in dep:
-                    if opt.target_pkg.architecture not in exclude_archs:
-                        hold_pkg(opt.target_pkg)
+                    hold_pkg(opt.target_pkg)
 
 
 def check_pkg(pkg):
@@ -78,8 +66,7 @@ def check_pkg(pkg):
 
 
 for pkg in cache.packages:
-    if pkg.architecture not in exclude_archs:
-        check_pkg(pkg)
+    check_pkg(pkg)
 
 print("\nHeld packages:")
 keeps = list(keeps)