[jhbuild] refactor sysdep uninstalled list handling a bit



commit e84de4200c6408c4a057337ab042d071b5e864de
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Dec 14 19:13:27 2014 -0500

    refactor sysdep uninstalled list handling a bit
    
    Instead of collecting uninstall sysdeps into two lists (one for pkgconfig and
    one for filenames) use just one list along with a 'dep_type' field.
    
    This lets us send the list into the backend modules without converting C
    includes and path programs into absolute filenames.
    
    Right now we have a convenience function in the backend that implements the
    same logic as before, but this can be improved in the future.
    
    This will also allow for easier addition of new types of sysdeps.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691394

 jhbuild/commands/sysdeps.py    |   36 +++++++++---------------------------
 jhbuild/utils/systeminstall.py |   25 +++++++++++++++++++++----
 2 files changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index e8a7f1d..b59d780 100644
--- a/jhbuild/commands/sysdeps.py
+++ b/jhbuild/commands/sysdeps.py
@@ -90,8 +90,7 @@ class cmd_sysdeps(cmd_build):
             print _('    (none)')
 
         print _('  No matching system package installed:')
-        uninstalled_pkgconfigs = []
-        uninstalled_filenames = []
+        uninstalled = []
         for module, (req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
             if installed_version is None and (not new_enough) and systemmodule:
                 print ('    %s %s' % (module.name,
@@ -99,22 +98,11 @@ class cmd_sysdeps(cmd_build):
                                                   req_version,
                                                   installed_version)))
                 if module.pkg_config is not None:
-                    uninstalled_pkgconfigs.append((module.name,
-                                                   # remove .pc
-                                                   module.pkg_config[:-3]))
+                    uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
                 elif module.systemdependencies is not None:
                     for dep_type, value in module.systemdependencies:
-                        if dep_type.lower() == 'path':
-                            uninstalled_filenames.append(
-                                (module.name,
-                                 os.path.join(config.system_prefix, 'bin',
-                                              value),))
-                        elif dep_type.lower() == 'c_include':
-                            uninstalled_filenames.append(
-                                (module.name,
-                                 os.path.join(config.system_prefix, 'include',
-                                              value),))
-        if len(uninstalled_pkgconfigs) + len(uninstalled_filenames) == 0:
+                        uninstalled.append((module.name, dep_type, value))
+        if len(uninstalled) == 0:
             print _('    (none)')
 
         have_too_old = False
@@ -140,11 +128,9 @@ class cmd_sysdeps(cmd_build):
                                                       req_version,
                                                       installed_version)))
                     if module.pkg_config is not None:
-                        uninstalled_pkgconfigs.append((module.name,
-                                                       # remove .pc
-                                                       module.pkg_config[:-3]))
+                        uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
 
-            if len(uninstalled_pkgconfigs) == 0:
+            if len(uninstalled) == 0:
                 print _('    (none)')
 
         if options.install:
@@ -160,15 +146,11 @@ class cmd_sysdeps(cmd_build):
 
                 raise FatalError(_("Don't know how to install packages on this system"))
 
-            if (len(uninstalled_pkgconfigs) +
-                len(uninstalled_filenames)) == 0:
+            if len(uninstalled) == 0:
                 logging.info(_("No uninstalled system dependencies to install for modules: %r") % (modules, 
))
             else:
                 logging.info(_("Installing dependencies on system: %s") % \
-                               ' '.join([pkg[0] for pkg in
-                                         uninstalled_pkgconfigs +
-                                         uninstalled_filenames]))
-                installer.install(uninstalled_pkgconfigs,
-                                  uninstalled_filenames)
+                               ' '.join(pkg[0] for pkg in uninstalled))
+                installer.install(uninstalled)
 
 register_command(cmd_sysdeps)
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index d77a0e2..2d3f0a9 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -53,6 +53,20 @@ def get_installed_pkgconfigs(config):
         pass
     return pkgversions
 
+def get_uninstalled_pkgconfigs_and_filenames(uninstalled):
+    uninstalled_pkgconfigs = []
+    uninstalled_filenames = []
+
+    for module_name, dep_type, value in uninstalled:
+        if dep_type == 'pkgconfig':
+            uninstalled_pkgconfigs.append(module_name, value)
+        elif dep_type.lower() == 'path':
+            uninstalled_filenames.append((module_name, os.path.join('/usr/bin', value),))
+        elif dep_type.lower() == 'c_include':
+            uninstalled_filenames.append((module.name, os.path.join('/usr/include', value),))
+
+    return uninstalled_pkgconfigs, uninstalled_filenames
+
 def systemdependencies_met(module_name, sysdeps, config):
     '''Returns True of the system dependencies are met for module_name'''
     def get_c_include_search_paths(config):
@@ -141,7 +155,7 @@ class SystemInstall(object):
         else:
             raise SystemExit, _('No suitable root privilege command found; you should install "pkexec"')
 
-    def install(self, uninstalled_pkgconfigs, uninstalled_filenames):
+    def install(self, uninstalled):
         """Takes a list of pkg-config identifiers and uses a system-specific method to install them."""
         raise NotImplementedError()
 
@@ -202,7 +216,8 @@ class PKSystemInstall(SystemInstall):
         txn.connect_to_signal('Destroy', lambda *args: self._loop.quit())
         return txn_tx, txn
 
-    def install(self, uninstalled_pkgconfigs, uninstalled_filenames):
+    def install(self, uninstalled):
+        uninstalled_pkgconfigs, uninstalled_filenames = get_uninstalled_pkgconfigs_and_filenames(uninstalled)
         pk_package_ids = set()
 
         if uninstalled_pkgconfigs:
@@ -279,7 +294,8 @@ class YumSystemInstall(SystemInstall):
     def __init__(self):
         SystemInstall.__init__(self)
 
-    def install(self, uninstalled_pkgconfigs, uninstalled_filenames):
+    def install(self, uninstalled):
+        uninstalled_pkgconfigs, uninstalled_filenames = get_uninstalled_pkgconfigs_and_filenames(uninstalled)
         logging.info(_('Using yum to install packages.  Please wait.'))
 
         if len(uninstalled_pkgconfigs) + len(uninstalled_filenames) > 0:
@@ -323,7 +339,8 @@ class AptSystemInstall(SystemInstall):
             # otherwise for now, just take the first match
             return name
 
-    def install(self, uninstalled_pkgconfigs, uninstalled_filenames):
+    def install(self, uninstalled):
+        uninstalled_pkgconfigs, uninstalled_filenames = get_uninstalled_pkgconfigs_and_filenames(uninstalled)
         logging.info(_('Using apt-file to search for providers; this may be slow.  Please wait.'))
         native_packages = []
         pkgconfigs = [(modname, '/%s.pc' % pkg) for modname, pkg in


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