[jhbuild/desrt/master: 1/9] refactor sysdep uninstalled list handling a bit



commit e0d8bf74c078e409b320a2708544227cc04290a6
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 |   30 ++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 31 deletions(-)
---
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index ccc3ba0..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 b54fc7d..94fc1f7 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -53,6 +53,25 @@ 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(config.system_prefix, 'bin', value),))
+        elif dep_type.lower() == 'c_include':
+            uninstalled_filenames.append((module.name,
+                                          os.path.join(config.system_prefix, 'include', value),))
+
+        else:
+            print 'bah'
+
+    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 +160,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()
 
@@ -201,7 +220,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_files(uninstalled)
         pk_package_ids = set()
 
         if uninstalled_pkgconfigs:
@@ -268,7 +288,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_files(uninstalled)
         logging.info(_('Using yum to install packages.  Please wait.'))
 
         if len(uninstalled_pkgconfigs) + len(uninstalled_filenames) > 0:
@@ -312,7 +333,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_files(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]