[jhbuild] sysdeps: Add direct dnf backend



commit db6f8d3965059fbb805b180ee4f769a820d4b6f1
Author: Patrick Griffis <tingping tingping se>
Date:   Sat Aug 21 21:47:54 2021 -0500

    sysdeps: Add direct dnf backend
    
    This is really simple and honestly just all around better than
    dealing with PackageKit.
    
    I left it as lowest priority just to avoid potential regressions
    but in my testing its more reliable.

 jhbuild/utils/systeminstall.py | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 610be80d..43662526 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -338,6 +338,43 @@ class PKSystemInstall(SystemInstall):
     def detect(cls):
         return cmds.has_command('pkcon')
 
+class DNFSystemInstall(SystemInstall):
+    def __init__(self):
+        SystemInstall.__init__(self)
+
+    def install(self, uninstalled, assume_yes):
+        uninstalled_pkgconfigs = get_uninstalled_pkgconfigs(uninstalled)
+        uninstalled_filenames = get_uninstalled_filenames(uninstalled)
+        logging.info(_('Using dnf to install packages.  Please wait.'))
+        package_names = set()
+
+        if not uninstalled_filenames and not uninstalled_pkgconfigs:
+            logging.info(_('Nothing to install'))
+            return
+
+        for name, pkgconfig in uninstalled_pkgconfigs:
+            package_names.add('pkgconfig({})'.format(pkgconfig))
+
+        for name, filename in uninstalled_filenames:
+            package_names.add(filename)
+
+        if not package_names:
+            logging.info(_('Nothing to install'))
+            return
+
+        logging.info('Installing:\n  %s' %('\n  '.join(package_names)))
+        dnf_command = ['dnf', 'install']
+        if assume_yes:
+            dnf_command.append('--assumeyes')
+        if subprocess.call(self._root_command_prefix_args + dnf_command + list(package_names)):
+            logging.error(_('Install failed'))
+        else:
+            logging.info(_('Completed!'))
+
+    @classmethod
+    def detect(cls):
+        return cmds.has_command('dnf')
+
 class PacmanSystemInstall(SystemInstall):
     def __init__(self):
         SystemInstall.__init__(self)
@@ -549,8 +586,8 @@ class AptSystemInstall(SystemInstall):
     def detect(cls):
         return cmds.has_command('apt-file')
 
-# Ordered from best to worst
-_classes = [AptSystemInstall, PacmanSystemInstall, PKSystemInstall]
+# Ordered from best to worst. DNF is only last because its newer than PackageKit.
+_classes = [AptSystemInstall, PacmanSystemInstall, PKSystemInstall, DNFSystemInstall]
 
 if __name__ == '__main__':
     logging.basicConfig(level=logging.INFO)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]