From 71c50a21fbb21f91253b552c3fbd9b7956261b69 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 11 Dec 2014 09:06:47 -0600 Subject: Don't blow up if lastsync file wasn't correctly fetched Instead, pass None value in which is handled accordingly. Signed-off-by: Dan McGee --- mirrors/management/commands/mirrorcheck.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'mirrors') diff --git a/mirrors/management/commands/mirrorcheck.py b/mirrors/management/commands/mirrorcheck.py index d2a27bee..8c17c78f 100644 --- a/mirrors/management/commands/mirrorcheck.py +++ b/mirrors/management/commands/mirrorcheck.py @@ -96,7 +96,7 @@ def parse_lastsync(log, data): try: parsed_time = datetime.utcfromtimestamp(int(data)) log.last_sync = parsed_time.replace(tzinfo=utc) - except ValueError: + except (TypeError, ValueError): # it is bad news to try logging the lastsync value; # sometimes we get a crazy-encoded web page. # if we couldn't parse a time, this is a failure. @@ -197,8 +197,11 @@ def check_rsync_url(mirror_url, location, timeout): log.duration = None else: logger.debug("success: %s, %.2f", url, log.duration) - with open(lastsync_path, 'r') as lastsync: - parse_lastsync(log, lastsync.read()) + if os.path.exists(lastsync_path): + with open(lastsync_path, 'r') as lastsync: + parse_lastsync(log, lastsync.read()) + else: + parse_lastsync(log, None) finally: if os.path.exists(lastsync_path): os.unlink(lastsync_path) -- cgit v1.2.3