Luke Ross

Scripts

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

Small scripts

Commit 29717d9e832522ce4008eaf0e23147737a0e39b1

my customised version

Committed 6 Oct 2019 by Luke Ross

FindDebCyclicOrphans/find_deb_cyclic_orphans.py

@@ -1,9 +1,12 @@
+#!/usr/bin/env python3
+
 import apt_pkg
 
 holds = ['PreDepends', 'Depends', 'Recommends']
 pkgs = set()
 keeps = set()
 virtuals = {}
+exclude_archs = {"i386",}
 
 apt_pkg.init()
 cache = apt_pkg.Cache()
@@ -32,8 +35,9 @@ def hold_pkg(pkg):
 
 def hold_provides(provides_list):
     for provides in provides_list:
-        flag_provides(provides[0], provides[2].parent_pkg)
-        hold_pkg(provides[2].parent_pkg)
+        if provides[2].parent_pkg.architecture not in exclude_archs:
+            flag_provides(provides[0], provides[2].parent_pkg)
+            hold_pkg(provides[2].parent_pkg)
 
 
 def hold_dependencies(dep_dict):
@@ -41,7 +45,8 @@ def hold_dependencies(dep_dict):
         if dep_type in holds:
             for dep in deps:
                 for opt in dep:
-                    hold_pkg(opt.target_pkg)
+                    if opt.target_pkg.architecture not in exclude_archs:
+                        hold_pkg(opt.target_pkg)
 
 
 def check_pkg(pkg):
@@ -60,32 +65,32 @@ def check_pkg(pkg):
     hold_dependencies(pkg.current_ver.depends_list)
 
 
-
 for pkg in cache.packages:
-    check_pkg(pkg)
+    if pkg.architecture not in exclude_archs:
+        check_pkg(pkg)
 
-print "\nHeld packages:"
+print("\nHeld packages:")
 keeps = list(keeps)
 keeps.sort()
-print '\n'.join(keeps)
+print('\n'.join(keeps))
 
-print "\nOrphaned packages:"
+print("\nOrphaned packages:")
 orphans = list(pkgs.difference(keeps))
 orphans.sort()
-print '\n'.join(orphans)
+print('\n'.join(orphans))
 
-print "\nVirtual packages provided by multiple held packages:"
-keys = virtuals.keys()
+print("\nVirtual packages provided by multiple held packages:")
+keys = list(virtuals.keys())
 keys.sort()
 for key in keys:
     if len(virtuals[key]) > 1:
         vals = list(virtuals[key])
         vals.sort()
-        print '%s:\n\t%s' % (key, '\n\t'.join(vals))
+        print('%s:\n\t%s' % (key, '\n\t'.join(vals)))
 
-print '\n%d packages held' % len(keeps)
-print '%d packages orphaned' % len(orphans)
+print('\n%d packages held' % len(keeps))
+print('%d packages orphaned' % len(orphans))
 
-print "\nTo remove orphans (omit '-s' option to do this for real):"
-print 'apt-get -s purge %s' % ' '.join(orphans)
-print 'aptitude -s purge %s' % ' '.join(orphans)
+print("\nTo remove orphans (omit '-s' option to do this for real):")
+print('apt-get -s purge %s' % ' '.join(orphans))
+print('aptitude -s purge %s' % ' '.join(orphans))