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