From 29f927e968d1bd994eb7c27b8538a3885c92541c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 16 2011 18:00:58 +0000 Subject: Implement the --keep-logs option - The logs will be removed once the package is built - The logs will not be removed if the package failed to build --- diff --git a/r2spec/build.py b/r2spec/build.py index ec1acb1..0a5bea9 100644 --- a/r2spec/build.py +++ b/r2spec/build.py @@ -93,6 +93,13 @@ class Build: self.log.info('Could not read the file "%s"' % self.buildlog) self.log.debug('ERROR: %s' % err) + def remove_logs(self): + """ Remove the log file generated while building the RPM. """ + if os.path.exists(self.buildlog): + os.remove(self.buildlog) + else: + self.log.info('No log file to remove') + def parse_error(self, specname): """Parses the build.log to extract the error Generates a file list (file installed but not found) diff --git a/r2spec/r2spec_obj.py b/r2spec/r2spec_obj.py index ac5441e..edfe454 100644 --- a/r2spec/r2spec_obj.py +++ b/r2spec/r2spec_obj.py @@ -64,6 +64,8 @@ def setup_parser(prog): help='Enforce the download of the source, even if they are already on the system.') parser.add_argument('--keep-sources', action='store_true', help='The extracted source on the current directory will not be removed.') + parser.add_argument('--keep-logs', action='store_true', + help='Keep the log file generated while building the rpm') parser.add_argument('--repo', default=None, help='Name of the repository as described in the configuration file.') parser.add_argument('--name', default=None, @@ -363,4 +365,6 @@ class R2rpm(R2spec): print 'An error occured during the build of %s' % self.pack.name self.log.debug('ERROR: %s' % err) return 1 + if not args.keep_logs: + self.build.remove_logs() return 0