Browse code

* s3cmd, s3cmd.1, S3/S3.py: Display or don't display progress meter default depends on whether we're on TTY (console) or not.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@270 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/11/25 15:35:03
Showing 4 changed files
... ...
@@ -1,5 +1,10 @@
1 1
 2008-11-24  Michal Ludvig  <michal@logix.cz>
2 2
 
3
+	* s3cmd, s3cmd.1, S3/S3.py: Display or don't display progress meter
4
+	  default depends on whether we're on TTY (console) or not.
5
+
6
+2008-11-24  Michal Ludvig  <michal@logix.cz>
7
+
3 8
 	* s3cmd: Fixed 'get' conflict.
4 9
 	* s3cmd.1, TODO: Document 'mv' command.
5 10
 
... ...
@@ -569,9 +569,15 @@ class S3(object):
569 569
 				raise S3DownloadError("Download failed for: %s" % resource['uri'])
570 570
 
571 571
 		stream.flush()
572
-		progress.done("done")
573 572
 		timestamp_end = time.time()
574 573
 
574
+		if self.config.progress_meter:
575
+			## The above stream.flush() may take some time -> update() progress meter
576
+			## to correct the average speed. Otherwise people will complain that 
577
+			## 'progress' and response["speed"] are inconsistent ;-)
578
+			progress.update()
579
+			progress.done("done")
580
+
575 581
 		if start_position == 0:
576 582
 			# Only compute MD5 on the fly if we were downloading from the beginning
577 583
 			response["md5"] = md5_hash.hexdigest()
... ...
@@ -996,8 +996,8 @@ def main():
996 996
 
997 997
 	optparser.add_option("-H", "--human-readable-sizes", dest="human_readable_sizes", action="store_true", help="Print sizes in human readable form.")
998 998
 
999
-	optparser.add_option(      "--progress", dest="progress_meter", action="store_true", help="Display progress meter (default).")
1000
-	optparser.add_option(      "--no-progress", dest="progress_meter", action="store_false", help="Don't display progress meter.")
999
+	optparser.add_option(      "--progress", dest="progress_meter", action="store_true", help="Display progress meter (default on TTY).")
1000
+	optparser.add_option(      "--no-progress", dest="progress_meter", action="store_false", help="Don't display progress meter (default on non-TTY).")
1001 1001
 	optparser.add_option("-v", "--verbose", dest="verbosity", action="store_const", const=logging.INFO, help="Enable verbose output.")
1002 1002
 	optparser.add_option("-d", "--debug", dest="verbosity", action="store_const", const=logging.DEBUG, help="Enable debug output.")
1003 1003
 	optparser.add_option(      "--version", dest="show_version", action="store_true", help="Show s3cmd version (%s) and exit." % (PkgInfo.version))
... ...
@@ -1044,6 +1044,10 @@ def main():
1044 1044
 		cfg.verbosity = options.verbosity
1045 1045
 	logging.root.setLevel(cfg.verbosity)
1046 1046
 
1047
+	## Default to --progress on TTY devices, --no-progress elsewhere
1048
+	## Can be overriden by actual --(no-)progress parameter
1049
+	cfg.update_option('progress_meter', sys.stdout.isatty())
1050
+
1047 1051
 	## Update Config with other parameters
1048 1052
 	for option in cfg.option_list():
1049 1053
 		try:
... ...
@@ -146,6 +146,9 @@ Print sizes in human readable form.
146 146
 .\"\fB\-u\fR, \fB\-\-show\-uri\fR
147 147
 .\"Show complete S3 URI in listings.
148 148
 .TP
149
+\fB\-\-progress\fR, \fB\-\-no\-progress\fR
150
+Display or don't display progress meter. When running on TTY (e.g. console or xterm) the default is to display progress meter. If not on TTY (e.g. output is redirected somewhere or running from cron) the default is to not display progress meter.
151
+.TP
149 152
 \fB\-v\fR, \fB\-\-verbose\fR
150 153
 Enable verbose output.
151 154
 .TP