Blob Blame Raw
From 95c04ed7230671bc813fa1e5df99dc01101f1e85 Mon Sep 17 00:00:00 2001
From: Björn Esser <besser82@fedoraproject.org>
Date: Jun 02 2017 21:33:58 +0000
Subject: Add mock-option '--no-bootstrap-chroot' to defaults

This is a temporary fix for mock >= 1.4.1

---

diff --git a/fedora-review.1 b/fedora-review.1
index e4389ed..0e7a25f 100644
--- a/fedora-review.1
+++ b/fedora-review.1
@@ -117,9 +117,9 @@ with the .cfg suffix stripped. Defaults to the root defined in
 /etc/mock/default.cfg
 .TP 4
 .B -o, --mock-options "options..."
-Mock options for the build. Defaults to --no-cleanup-after, you might
-want this along with other options
-you provide.
+Mock options for the build. Defaults to --no-cleanup-after --no-clean,
+for use with mock >= 1.4.1 --no-bootstrap-chroot additionally, you might
+want this along with other options you provide.
 .TP 4
 .B --no-report
 Do not generate the review template.
diff --git a/src/FedoraReview/settings.py b/src/FedoraReview/settings.py
index 8d22751..c637775 100644
--- a/src/FedoraReview/settings.py
+++ b/src/FedoraReview/settings.py
@@ -26,9 +26,11 @@ import errno
 import os
 import os.path
 import re
+import subprocess
 import sys
 
 import ansi
+from packaging import version
 from review_error import ReviewError
 from xdg_dirs import XdgDirs
 
@@ -53,6 +55,21 @@ def _check_mock_grp():
         raise ReviewError(mock_msg)
 
 
+def _check_mock_ver():
+    try:
+        mock_ver = subprocess.check_output(['mock', '--version'])
+    except subprocess.CalledProcessError:
+        mock_ver = '0'
+    return mock_ver
+
+
+def _mock_options_default():
+    mock_opts = '--no-cleanup-after --no-clean'
+    if(version.parse(_check_mock_ver()) >= version.parse('1.4.1')):
+        mock_opts = '--no-bootstrap-chroot %s' % mock_opts
+    return mock_opts
+
+
 def _add_modes(modes):
     ''' Add all mode arguments to the option parser group modes. '''
     modes.add_argument('-b', '--bug', metavar='<bug>',
@@ -111,10 +128,10 @@ def _add_optionals(optional):
                           help='Do not rebuild or install the srpm, use last'
                           ' built one in mock. Implies --cache')
     optional.add_argument('-o', '--mock-options', metavar='<mock options>',
-                          default='--no-cleanup-after --no-clean',
+                          default=_mock_options_default(),
                           dest='mock_options',
-                          help='Options to specify to mock for the build,'
-                          ' defaults to --no-cleanup-after --no-clean')
+                          help=('Options to specify to mock for the build,'
+                          ' defaults to %s' % _mock_options_default()))
     optional.add_argument('--other-bz', default=None,
                           metavar='<bugzilla url>', dest='other_bz',
                           help='Alternative bugzilla URL')