Changeset 199
- Timestamp:
- 2002-10-22 20:58:17 (6 years ago)
- Files:
-
- trunk/_test_ftputil.py (modified) (8 diffs)
- trunk/ftputil.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/_test_ftputil.py
r184 r199 30 30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 31 32 # $Id: _test_ftputil.py,v 1.6 0 2002/04/03 21:50:24schwa Exp $32 # $Id: _test_ftputil.py,v 1.61 2002/10/22 20:58:17 schwa Exp $ 33 33 34 34 import unittest … … 157 157 except ftputil.RootDirError, exc_obj: 158 158 self.failIf( isinstance(exc_obj, ftputil.FTPOSError) ) 159 159 160 160 def test_lstat_one_file(self): 161 161 """Test lstat for a file.""" … … 179 179 # The comparison with the value 937785600.0 may fail in 180 180 # some Python environments. It seems that this depends on 181 # how time.mktime interprets the dst flag. 182 self.assertEqual(stat_result.st_mtime, 937785600.0) 181 # how `time.mktime` interprets the dst flag. 182 self.failUnless(stat_result.st_mtime == 937785600.0 or 183 stat_result.st_mtime == 937778400.0) 183 184 self.assertEqual(stat_result.st_ctime, None) 184 self.assertEqual( stat_result, (17901, None, None, 6, '45854', '200', 185 512, None, 937785600.0, None) ) 185 # same here (or similarly) 186 self.failUnless( stat_result == (17901, None, None, 6, '45854', '200', 187 512, None, 937785600.0, None) or 188 stat_result == (17901, None, None, 6, '45854', '200', 189 512, None, 937778400.0, None) ) 186 190 187 191 def test_lstat_via_stat_module(self): … … 479 483 host = ftp_host_factory( 480 484 ftp_host_class=FailingUploadAndDownloadFTPHost) 481 host.upload_if_newer(local_source, '/home/newer') 485 flag = host.upload_if_newer(local_source, '/home/newer') 486 self.assertEqual(flag, False) 482 487 # target is older, so upload 483 488 host = ftp_host_factory() 484 host.upload_if_newer(local_source, '/home/older') 489 flag = host.upload_if_newer(local_source, '/home/older') 490 self.assertEqual(flag, True) 485 491 # check uploaded content 486 492 # the data which was uploaded has its line endings converted … … 491 497 # target doesn't exist, so upload 492 498 host = ftp_host_factory() 493 host.upload_if_newer(local_source, '/home/notthere') 499 flag = host.upload_if_newer(local_source, '/home/notthere') 500 self.assertEqual(flag, True) 494 501 remote_file_content = _mock_ftplib.content_of('/home/notthere') 495 502 self.assertEqual(data, remote_file_content) … … 511 518 # target does not exist, so download 512 519 host = ftp_host_factory(session_factory=BinaryDownloadMockSession) 513 host.download_if_newer('/home/newer', local_target, 'b') 520 flag = host.download_if_newer('/home/newer', local_target, 'b') 521 self.assertEqual(flag, True) 514 522 self.compare_and_delete_downloaded_data(local_target) 515 523 … … 521 529 # source is newer, so download 522 530 host = ftp_host_factory(session_factory=BinaryDownloadMockSession) 523 host.download_if_newer('/home/newer', local_target, 'b') 531 flag = host.download_if_newer('/home/newer', local_target, 'b') 532 self.assertEqual(flag, True) 524 533 self.compare_and_delete_downloaded_data(local_target) 525 534 … … 534 543 ftp_host_class=FailingUploadAndDownloadFTPHost, 535 544 session_factory=BinaryDownloadMockSession) 536 host.download_if_newer('/home/older', local_target, 'b') 545 flag = host.download_if_newer('/home/older', local_target, 'b') 546 self.assertEqual(flag, False) 537 547 # remove target file 538 548 os.unlink(local_target) trunk/ftputil.py
r198 r199 30 30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 31 32 # $Id: ftputil.py,v 1.9 4 2002/05/29 11:50:17 schwa Exp $32 # $Id: ftputil.py,v 1.95 2002/10/22 20:58:17 schwa Exp $ 33 33 34 34 """ … … 102 102 'PermanentError', 'ParserError', 'FTPIOError', 103 103 'RootDirError', 'FTPHost'] 104 __version__ = '1.1.1' 104 __version__ = '1.1.4' 105 106 107 # define `True` and `False` if necessary 108 try: 109 True, False 110 except NameError: 111 True, False = 1 == 1, 1 == 0 105 112 106 113 … … 508 515 Upload a file only if it's newer than the target on the 509 516 remote host or if the target file does not exist. 517 518 If an upload was necessary, return `True`, else return 519 `False`. 510 520 """ 511 521 source_timestamp = os.path.getmtime(source) … … 517 527 if source_timestamp > target_timestamp: 518 528 self.upload(source, target, mode) 529 return True 530 else: 531 return False 519 532 520 533 def download_if_newer(self, source, target, mode=''): … … 522 535 Download a file only if it's newer than the target on the 523 536 local host or if the target file does not exist. 537 538 If a download was necessary, return `True`, else return 539 `False`. 524 540 """ 525 541 source_timestamp = self.path.getmtime(source) … … 531 547 if source_timestamp > target_timestamp: 532 548 self.download(source, target, mode) 549 return True 550 else: 551 return False 533 552 534 553 def close(self):
