Show
Ignore:
Timestamp:
2010-02-11 21:43:49 (7 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Add a `_st_mtime_precision` value to stat result objects.

This contains the precision of the modification timestamp in
seconds. I plan to use this for a more robust decision in the
`upload_if_newer` and `download_if_newer` methods.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ftp_stat.py

    r843 r852  
    1 # Copyright (C) 2002-2008, Stefan Schwarzer 
     1# Copyright (C) 2002-2010, Stefan Schwarzer 
    22# All rights reserved. 
    33# 
     
    148148 
    149149    def parse_unix_time(self, month_abbreviation, day, year_or_time, 
    150                         time_shift): 
     150                        time_shift, with_precision=False): 
    151151        """ 
    152152        Return a floating point number, like from `time.mktime`, by 
     
    155155        "time on server" - "time on client" and is available as the 
    156156        `time_shift` parameter in the `parse_line` interface. 
     157 
     158        If `with_precision` is true (default: false), return a 
     159        two-element tuple consisting of the floating point number as 
     160        described in the previous paragraph and the precision of the 
     161        time in seconds. This takes into account that, for example, a 
     162        time string like "May 26  2005" has only a precision of one 
     163        day. This information is important for the `upload_if_newer` 
     164        and `download_if_newer` methods in the `FTPHost` class. 
    157165 
    158166        Times in Unix-style directory listings typically have one of 
     
    176184            st_mtime = time.mktime( (year, month, day, 
    177185                                     hour, minute, 0, 0, 0, -1) ) 
     186            # precise up to a day 
     187            st_mtime_precision = 24 * 60 * 60 
    178188        else: 
    179189            # `year_or_time` is a time hh:mm 
     
    184194            st_mtime = time.mktime( (year, month, day, 
    185195                                     hour, minute, 0, 0, 0, -1) ) 
     196            # precise up to a minute 
     197            st_mtime_precision = 60 
    186198            # rhs of comparison: transform client time to server time 
    187199            #  (as on the lhs), so both can be compared with respect 
     
    199211                st_mtime = time.mktime( (year-1, month, day, 
    200212                                         hour, minute, 0, 0, 0, -1) ) 
    201         return st_mtime 
     213        if with_precision: 
     214            return (st_mtime, st_mtime_precision) 
     215        else: 
     216            return st_mtime 
    202217 
    203218    def parse_ms_time(self, date, time_, time_shift): 
     
    221236        # don't complain about unused `time_shift` argument 
    222237        # pylint: disable-msg=W0613 
     238        # For the time being, I don't add a `with_precision` 
     239        #  parameter as in the Unix parser because the precision for 
     240        #  the DOS format is always a minute and can be set in 
     241        #  `MSParser.parse_line`. Should you find yourself needing 
     242        #  support for `with_precision` for a derived class, please 
     243        #  write a mail (see ftputil.txt/html). 
    223244        try: 
    224245            month, day, year = [int(part) for part in date.split('-')] 
     
    294315        st_atime = None 
    295316        # st_mtime 
    296         st_mtime = self.parse_unix_time(month, day, year_or_time, time_shift) 
     317        st_mtime, st_mtime_precision = \ 
     318          self.parse_unix_time(month, day, year_or_time, time_shift, 
     319                               with_precision=True) 
    297320        # st_ctime 
    298321        st_ctime = None 
     
    305328                      (st_mode, st_ino, st_dev, st_nlink, st_uid, 
    306329                       st_gid, st_size, st_atime, st_mtime, st_ctime) ) 
     330        stat_result._st_mtime_precision = st_mtime_precision 
    307331        stat_result._st_name = st_name 
    308332        stat_result._st_target = st_target 
     
    362386        stat_result._st_name = name 
    363387        stat_result._st_target = None 
     388        # mtime precision in seconds 
     389        stat_result._st_mtime_precision = 60 
    364390        return stat_result 
    365391