Do not write log messages to stdout when --quiet specified With --quiet, all logging messages that are currently sent to stdout should instead not be written. We had accomplished this by internally redirecting stdout to /dev/null. However, this had the negative implication of causing all stdout writes, including get s3://bucket/file -, to fail to output anything to stdout. That wasn't the intended behavior. Fix both definitions of output() to look at the new Config option quiet, before writing to stdout directly.
diff --git a/S3/CloudFront.py b/S3/CloudFront.py index 341252a..5cc4d8c 100644 --- a/S3/CloudFront.py +++ b/S3/CloudFront.py
@@ -31,7 +31,9 @@ cloudfront_resource = "/%(api_ver)s/distribution" % { 'api_ver' : cloudfront_api_version } def output(message): - sys.stdout.write(message + "\n") + if not Config().quiet: + sys.stdout.write(message + "\n") + sys.stdout.flush() def pretty_output(label, message): #label = ("%s " % label).ljust(20, ".")
diff --git a/S3/Config.py b/S3/Config.py index dba19c0..63f1139 100644 --- a/S3/Config.py +++ b/S3/Config.py
@@ -41,6 +41,7 @@ simpledb_host = "sdb.amazonaws.com" cloudfront_host = "cloudfront.amazonaws.com" verbosity = logging.WARNING + quiet = False progress_meter = sys.stdout.isatty() progress_class = Progress.ProgressCR send_chunk = 64 * 1024
diff --git a/s3cmd b/s3cmd index a30be0f..611dbd4 100755 --- a/s3cmd +++ b/s3cmd
@@ -62,8 +62,10 @@ from ssl import SSLError def output(message): - sys.stdout.write(message + "\n") - sys.stdout.flush() + Config().quiet + if not Config().quiet: + sys.stdout.write(message + "\n") + sys.stdout.flush() def check_args_type(args, type, verbose_type): """NOTE: This function looks like to not be used.""" @@ -2693,13 +2695,6 @@ sys.exit(EX_OK) debug(u"s3cmd version %s" % PkgInfo.version) - if options.quiet: - try: - f = open("/dev/null", "w") - sys.stdout = f - except IOError: - warning(u"Unable to open /dev/null: --quiet disabled.") - ## Now finally parse the config file if not options.config: error(u"Can't find a config file. Please use --config option.") @@ -2720,6 +2715,8 @@ if options.verbosity is not None: cfg.verbosity = options.verbosity logging.root.setLevel(cfg.verbosity) + if options.quiet is not None: + cfg.quiet = options.quiet ## Unsupported features on Win32 platform if os.name == "nt": if cfg.preserve_attrs: