Blame SOURCES/sos-bz1015599-restore-build-command-line-option.patch

6b17e9
commit b65606177be6210f3f0501e5689cdbb107e0f2f7
6b17e9
Author: Bryn M. Reeves <bmr@redhat.com>
6b17e9
Date:   Tue Nov 5 16:07:23 2013 +0000
6b17e9
6b17e9
    Restore --build command line option
6b17e9
    
6b17e9
    Releases of sos prior to 3.0 included the '--build' option to
6b17e9
    disable creation of a compressed archive and to leave the
6b17e9
    temporary build tree in place. This was removed with the
6b17e9
    reorganisation of the archive classes to support in-line
6b17e9
    archiving. Since all supported policies are now using an archive
6b17e9
    that derives from FileCacheArchive (commit 0178d5f) the option
6b17e9
    can be re-introduced.
6b17e9
    
6b17e9
    Archive classes that do not accumulate files in a temporary
6b17e9
    directory will return the path to the in-progress archive file.
6b17e9
    
6b17e9
    Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
6b17e9
6b17e9
diff --git a/sos/archive.py b/sos/archive.py
6b17e9
index 4291660..28bf197 100644
6b17e9
--- a/sos/archive.py
6b17e9
+++ b/sos/archive.py
6b17e9
@@ -65,6 +65,15 @@ class Archive(object):
6b17e9
         to be included in the generated archive."""
6b17e9
         raise NotImplementedError
6b17e9
 
6b17e9
+    def get_archive_path(self):
6b17e9
+        """Return a string representing the path to the temporary
6b17e9
+        archive. For archive classes that implement in-line handling
6b17e9
+        this will be the archive file itself. Archives that use a
6b17e9
+        directory based cache prior to packaging should return the
6b17e9
+        path to the temporary directory where the report content is
6b17e9
+        located"""
6b17e9
+        pass
6b17e9
+
6b17e9
     def cleanup(self):
6b17e9
         """Clean up any temporary resources used by an Archive class."""
6b17e9
         pass
6b17e9
@@ -81,7 +90,7 @@ class FileCacheArchive(Archive):
6b17e9
 
6b17e9
     _tmp_dir = ""
6b17e9
     _archive_root = ""
6b17e9
-    _archive_path = ""
6b17e9
+    _archive_name = ""
6b17e9
     
6b17e9
     def __init__(self, name, tmpdir):
6b17e9
         self._name = name
6b17e9
@@ -146,6 +155,9 @@ class FileCacheArchive(Archive):
6b17e9
     def get_tmp_dir(self):
6b17e9
         return self._archive_root
6b17e9
 
6b17e9
+    def get_archive_path(self):
6b17e9
+        return self._archive_root
6b17e9
+
6b17e9
     def makedirs(self, path, mode=0700):
6b17e9
         self._makedirs(self.dest_path(path))
6b17e9
         self.log.debug("created directory at %s in FileCacheArchive %s"
6b17e9
@@ -162,8 +174,8 @@ class FileCacheArchive(Archive):
6b17e9
         self.log.debug("finalizing archive %s" % self._archive_root)
6b17e9
         self._build_archive()
6b17e9
         self.cleanup()
6b17e9
-        self.log.debug("built archive at %s (size=%d)" % (self._archive_path,
6b17e9
-        os.stat(self._archive_path).st_size))
6b17e9
+        self.log.debug("built archive at %s (size=%d)" % (self._archive_name,
6b17e9
+        os.stat(self._archive_name).st_size))
6b17e9
         return self._compress()
6b17e9
 
6b17e9
 class TarFileArchive(FileCacheArchive):
6b17e9
@@ -174,7 +186,7 @@ class TarFileArchive(FileCacheArchive):
6b17e9
     def __init__(self, name, tmpdir):
6b17e9
         super(TarFileArchive, self).__init__(name, tmpdir)
6b17e9
         self._suffix = "tar"
6b17e9
-        self._archive_path = os.path.join(tmpdir, self.name())
6b17e9
+        self._archive_name = os.path.join(tmpdir, self.name())
6b17e9
 
6b17e9
     def set_tarinfo_from_stat(self, tar_info, fstat, mode=None):
6b17e9
         tar_info.mtime = fstat.st_mtime
6b17e9
@@ -218,7 +230,7 @@ class TarFileArchive(FileCacheArchive):
6b17e9
         old_pwd = os.getcwd()
6b17e9
         old_umask = os.umask(0077)
6b17e9
         os.chdir(self._tmp_dir)
6b17e9
-        tar = tarfile.open(self._archive_path, mode="w")
6b17e9
+        tar = tarfile.open(self._archive_name, mode="w")
6b17e9
         tar.add(os.path.split(self._name)[1], filter=self.copy_permissions_filter)
6b17e9
         tar.close()
6b17e9
         os.umask(old_umask)
6b17e9
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
6b17e9
index 983842d..6de93fb 100644
6b17e9
--- a/sos/policies/__init__.py
6b17e9
+++ b/sos/policies/__init__.py
6b17e9
@@ -205,12 +205,6 @@ No changes will be made to system configuration.
6b17e9
         """
6b17e9
         pass
6b17e9
 
6b17e9
-    def package_results(self, package_name):
6b17e9
-        """
6b17e9
-        This function is called prior to packaging.
6b17e9
-        """
6b17e9
-        pass
6b17e9
-
6b17e9
     def post_work(self):
6b17e9
         """
6b17e9
         This function is called after the sosreport has been generated.
6b17e9
@@ -476,5 +470,3 @@ class LinuxPolicy(Policy):
6b17e9
         
6b17e9
         return
6b17e9
 
6b17e9
-    def package_results(self, archive_filename):
6b17e9
-        self._print(_("Creating compressed archive..."))
6b17e9
diff --git a/sos/sosreport.py b/sos/sosreport.py
6b17e9
index 49e9d92..42be3ee 100644
6b17e9
--- a/sos/sosreport.py
6b17e9
+++ b/sos/sosreport.py
6b17e9
@@ -327,6 +327,19 @@ class SoSOptions(object):
6b17e9
         self._batch = value
6b17e9
 
6b17e9
     @property
6b17e9
+    def build(self):
6b17e9
+        if self._options != None:
6b17e9
+            return self._options.build
6b17e9
+        return self._build
6b17e9
+
6b17e9
+    @build.setter
6b17e9
+    def build(self):
6b17e9
+        self._check_options_initialized()
6b17e9
+        if not isinstance(value, bool):
6b17e9
+            raise TypeError("SoSOptions.build expects a boolean")
6b17e9
+        self._build = value
6b17e9
+
6b17e9
+    @property
6b17e9
     def verbosity(self):
6b17e9
         if self._options != None:
6b17e9
             return self._options.verbosity
6b17e9
@@ -476,6 +489,9 @@ class SoSOptions(object):
6b17e9
         parser.add_option("--batch", action="store_true",
6b17e9
                              dest="batch", default=False,
6b17e9
                              help="batch mode - do not prompt interactively")
6b17e9
+        parser.add_option("--build", action="store_true", \
6b17e9
+                             dest="build", default=False, \
6b17e9
+                             help="keep sos tree available and dont package results")
6b17e9
         parser.add_option("-v", "--verbose", action="count",
6b17e9
                              dest="verbosity",
6b17e9
                              help="increase verbosity")
6b17e9
@@ -1097,24 +1113,29 @@ class SoSReport(object):
6b17e9
     def final_work(self):
6b17e9
 
6b17e9
         # package up the results for the support organization
6b17e9
-        self.policy.package_results(self.archive.name())
6b17e9
+        if not self.opts.build:
6b17e9
+            self.ui_log.info(_("Creating compressed archive..."))
6b17e9
 
6b17e9
-        self._finish_logging()
6b17e9
+            # compression could fail for a number of reasons
6b17e9
+            try:
6b17e9
+                final_filename = self.archive.finalize(self.opts.compression_type)
6b17e9
+            except:
6b17e9
+                if self.opts.debug:
6b17e9
+                    raise
6b17e9
+                else:
6b17e9
+                    return False
6b17e9
 
6b17e9
-        # compression could fail for a number of reasons
6b17e9
-        try:
6b17e9
-            final_filename = self.archive.finalize(self.opts.compression_type)
6b17e9
-        except:
6b17e9
-            if self.opts.debug:
6b17e9
-                raise
6b17e9
+            # automated submission will go here
6b17e9
+            if not self.opts.upload:
6b17e9
+                self.policy.display_results(final_filename)
6b17e9
             else:
6b17e9
-                return False
6b17e9
+                self.policy.upload_results(final_filename)
6b17e9
 
6b17e9
-        # automated submission will go here
6b17e9
-        if not self.opts.upload:
6b17e9
-            self.policy.display_results(final_filename)
6b17e9
         else:
6b17e9
-            self.policy.upload_results(final_filename)
6b17e9
+            self.ui_log.info(_("\n  sosreport build tree is located at : %s\n"
6b17e9
+                            % self.archive.get_archive_path()))
6b17e9
+
6b17e9
+        self._finish_logging()
6b17e9
 
6b17e9
         self.tempfile_util.clean()
6b17e9