Changeset 852:f883b3708318 for ftp_stat.py
- Timestamp:
- 2010-02-11 21:43:49 (7 months ago)
- Branch:
- default
- Files:
-
- 1 modified
-
ftp_stat.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ftp_stat.py
r843 r852 1 # Copyright (C) 2002-20 08, Stefan Schwarzer1 # Copyright (C) 2002-2010, Stefan Schwarzer 2 2 # All rights reserved. 3 3 # … … 148 148 149 149 def parse_unix_time(self, month_abbreviation, day, year_or_time, 150 time_shift ):150 time_shift, with_precision=False): 151 151 """ 152 152 Return a floating point number, like from `time.mktime`, by … … 155 155 "time on server" - "time on client" and is available as the 156 156 `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. 157 165 158 166 Times in Unix-style directory listings typically have one of … … 176 184 st_mtime = time.mktime( (year, month, day, 177 185 hour, minute, 0, 0, 0, -1) ) 186 # precise up to a day 187 st_mtime_precision = 24 * 60 * 60 178 188 else: 179 189 # `year_or_time` is a time hh:mm … … 184 194 st_mtime = time.mktime( (year, month, day, 185 195 hour, minute, 0, 0, 0, -1) ) 196 # precise up to a minute 197 st_mtime_precision = 60 186 198 # rhs of comparison: transform client time to server time 187 199 # (as on the lhs), so both can be compared with respect … … 199 211 st_mtime = time.mktime( (year-1, month, day, 200 212 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 202 217 203 218 def parse_ms_time(self, date, time_, time_shift): … … 221 236 # don't complain about unused `time_shift` argument 222 237 # 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). 223 244 try: 224 245 month, day, year = [int(part) for part in date.split('-')] … … 294 315 st_atime = None 295 316 # 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) 297 320 # st_ctime 298 321 st_ctime = None … … 305 328 (st_mode, st_ino, st_dev, st_nlink, st_uid, 306 329 st_gid, st_size, st_atime, st_mtime, st_ctime) ) 330 stat_result._st_mtime_precision = st_mtime_precision 307 331 stat_result._st_name = st_name 308 332 stat_result._st_target = st_target … … 362 386 stat_result._st_name = name 363 387 stat_result._st_target = None 388 # mtime precision in seconds 389 stat_result._st_mtime_precision = 60 364 390 return stat_result 365 391
