[jhbuild] jhbuild/utils/systeminstall.py: added SystemInstall.sysdeps_assume_yes and implemented it in AptSyst



commit 0c7feb19eeaeae9ddaaf9da6a6edd289e742e881
Author: Karl-Philipp Richter <krichter722 aol de>
Date:   Wed Sep 27 02:29:50 2017 +0200

    jhbuild/utils/systeminstall.py: added SystemInstall.sysdeps_assume_yes and
    implemented it in AptSystemInstall
    jhbuild/commands/sysdeps.py: added --sysdeps-assume-yes to CLI
    
    Added SystemInstall.sysdeps_assume_yes and exposed it in the CLI
    
    In some environments like headless CI services it's necessary to be able to
    install system dependencies without user interaction.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788220

 jhbuild/commands/sysdeps.py    |  9 +++++++--
 jhbuild/utils/systeminstall.py | 18 +++++++++++-------
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index 779969ce..735c3970 100644
--- a/jhbuild/commands/sysdeps.py
+++ b/jhbuild/commands/sysdeps.py
@@ -46,7 +46,12 @@ class cmd_sysdeps(cmd_build):
                         help=_('Machine readable list of all sysdeps')),
             make_option('--install',
                         action='store_true', default = False,
-                        help=_('Install pkg-config modules via system'))])
+                        help=_('Install pkg-config modules via system')),
+            make_option('--assume-yes',
+                        action="store_true", default = False,
+                        dest="assume_yes",
+                        help=_('assume yes/the default answer to interactive questions during installation 
of system '
+                                + 'dependencies"'))])
 
     def run(self, config, options, args, help=None):
 
@@ -211,6 +216,6 @@ class cmd_sysdeps(cmd_build):
             else:
                 logging.info(_("Installing dependencies on system: %s") % \
                                ' '.join(pkg[0] for pkg in uninstalled))
-                installer.install(uninstalled)
+                installer.install(uninstalled, assume_yes=options.assume_yes)
 
 register_command(cmd_sysdeps)
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 50e92d3c..d8916bfb 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -217,7 +217,7 @@ class SystemInstall(object):
         else:
             raise SystemExit(_('No suitable root privilege command found; you should install "sudo" or 
"pkexec" (or the system package that provides it)'))
 
-    def install(self, uninstalled):
+    def install(self, uninstalled, assume_yes):
         """Takes a list of pkg-config identifiers and uses a system-specific method to install them."""
         raise NotImplementedError()
 
@@ -280,7 +280,7 @@ class PKSystemInstall(SystemInstall):
         txn.connect_to_signal('Destroy', lambda *args: self._loop.quit())
         return txn_tx, txn
 
-    def install(self, uninstalled):
+    def install(self, uninstalled, assume_yes):
         logging.info(_('Computing packages to install. This might be slow. Please wait.'))
         pk_package_ids = set()
         uninstalled_pkgconfigs = get_uninstalled_pkgconfigs(uninstalled)
@@ -352,7 +352,7 @@ class PacmanSystemInstall(SystemInstall):
             else:
                 logging.info(_('Successfully updated pkgfile cache'))
 
-    def install(self, uninstalled):
+    def install(self, uninstalled, assume_yes):
         uninstalled_pkgconfigs = get_uninstalled_pkgconfigs(uninstalled)
         uninstalled_filenames = get_uninstalled_filenames(uninstalled)
         logging.info(_('Using pacman to install packages.  Please wait.'))
@@ -435,13 +435,17 @@ class AptSystemInstall(SystemInstall):
                            '(%(filename)s)') % {'id'       : modname,
                                                 'filename' : filename})
 
-    def _install_packages(self, native_packages):
+    def _install_packages(self, native_packages, assume_yes):
         logging.info(_('Installing: %(pkgs)s') % {'pkgs': ' '.join(native_packages)})
-        args = self._root_command_prefix_args + ['apt-get', 'install']
+        apt_cmd_line = ['apt-get']
+        if assume_yes is True:
+            apt_cmd_line += ['--assume-yes']
+        apt_cmd_line += ['install']
+        args = self._root_command_prefix_args + apt_cmd_line
         args.extend(native_packages)
         subprocess.check_call(args)
 
-    def install(self, uninstalled):
+    def install(self, uninstalled, assume_yes):
         logging.info(_('Using apt-file to search for providers; this may be extremely slow. Please wait. 
Patience!'))
         native_packages = []
 
@@ -472,7 +476,7 @@ class AptSystemInstall(SystemInstall):
                 self._append_native_package_or_warn(modname, '/usr/include/%s' % filename, native_packages, 
True)
 
         if native_packages:
-            self._install_packages(native_packages)
+            self._install_packages(native_packages, assume_yes=assume_yes)
         else:
             logging.info(_('Nothing to install'))
 


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