Browse code

* s3cmd: Remove python 2.5 specific code (try/except/finally block) and make s3cmd compatible with python 2.4 again.

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

Michal Ludvig authored on 2008/06/11 08:57:56
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+2008-06-11  Michal Ludvig  <michal@logix.cz>
2
+
3
+	* s3cmd: Remove python 2.5 specific code (try/except/finally 
4
+	  block) and make s3cmd compatible with python 2.4 again.
5
+
1 6
 2008-06-10  Michal Ludvig  <michal@logix.cz>
2 7
 
3 8
 	* s3cmd: Added --exclude switch for sync.
... ...
@@ -414,6 +414,13 @@ def cmd_sync_remote2local(src, dst):
414 414
 			attrs[key] = val
415 415
 		return attrs
416 416
 		
417
+	def _try_close_dst_stream(dst_stream):
418
+		## Close the file if still open. Don't care if not.
419
+		try:
420
+			dst_stream.close()
421
+		except:
422
+			pass
423
+
417 424
 	s3 = S3(Config())
418 425
 
419 426
 	src_uri = S3Uri(src)
... ...
@@ -484,6 +491,7 @@ def cmd_sync_remote2local(src, dst):
484 484
 						os.utime(dst_file, (atime, mtime))
485 485
 					## FIXME: uid/gid / uname/gname handling comes here! TODO
486 486
 			except OSError, e:
487
+				_try_close_dst_stream(dst_stream)
487 488
 				if e.errno == errno.EEXIST:
488 489
 					warning("%s exists - not overwriting" % (dst_file))
489 490
 					continue
... ...
@@ -492,14 +500,13 @@ def cmd_sync_remote2local(src, dst):
492 492
 					continue
493 493
 				raise
494 494
 			except Exception, e:
495
+				_try_close_dst_stream(dst_stream)
495 496
 				error("%s: %s" % (file, e))
496 497
 				continue
497
-			finally:
498
-				## Close the file if still open. Don't care if not.
499
-				try:
500
-					dst_stream.close()
501
-				except:
502
-					pass
498
+			# We have to keep repeating this call because 
499
+			# Python 2.4 doesn't support try/except/finally
500
+			# construction :-(
501
+			_try_close_dst_stream(dst_stream)
503 502
 		except S3DownloadError, e:
504 503
 			error("%s: download failed too many times. Skipping that file." % file)
505 504
 			continue