diff options
author | 2008-12-22 23:00:01 -0800 | |
---|---|---|
committer | 2008-12-22 23:00:01 -0800 | |
commit | f5753d1f1599cec740964e978392d16b2020058d (patch) | |
tree | 2a26d019fc5fff6e1fa6a2dfdae2314c6ebb4f79 | |
parent | Remove ambiguty over mirror type. (diff) | |
download | gard-f5753d1f1599cec740964e978392d16b2020058d.tar.gz gard-f5753d1f1599cec740964e978392d16b2020058d.tar.bz2 gard-f5753d1f1599cec740964e978392d16b2020058d.zip |
Factor out duplicate code again and be smarter for handling timestamps (.x is much easier).
-rwxr-xr-x | gard-v2.py | 54 |
1 files changed, 31 insertions, 23 deletions
@@ -179,35 +179,43 @@ for line in file: add_handler(fname) info7 = addy+" wants to be an source mirror and is being checked as per Bug #"+bugnum+ " over rsync" logging.info(info7) - target=drsync+"/distfiles/timestamp.chk" + target=drsync+"/distfiles/timestamp.x" retcode4=subprocess.call(['rsync','-aqP','--no-motd','--contimeout=30',target,'.']) + lag=False + ots='Unknown' if retcode4 > 0: logging.error("return value of rsync during distfiles check was "+str(retcode4)) else: - temp=open('timestamp.chk','r') + temp=open('timestamp.x','r') ots=temp.readline() temp.close() - t1=time.mktime(time.strptime(ots.replace(" +0000",""), "%a, %d %b %Y %H:%M:%S ")) - lag=(time.mktime(time.gmtime())-t1)/(60*60) - if lag > dmaxlag: - error7 = "Mirror is lagging by over 5.5 hours, difference is : "+str(round(lag,2))+" hours" - tstamp7 = "Timestamp on Mirror : "+str(ots).strip() - curtime7= "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.error(error7) - logging.info(tstamp7) - logging.info(curtime7) - logging.info(bugurl7) - else: - info7 = addy+" is in sync, current lag : "+str(round(lag,2))+" hours" - tstamp7 = "Timestamp on Mirror : "+str(ots) - curtime7 = "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.info(info7) - logging.info(tstamp7) - logging.info(curtime7) - logging.info(bugurl7) - os.unlink('timestamp.chk') + os.unlink('timestamp.x') + try: + t1=ots.split()[0] + lag=(time.time()-t1)/(60*60) + except: + t1=False + lag=False + + # Unique line first + if t1 is False or lag is False: + error7 = "Mirror is not reachable or has a corrupt timestamp." + logging.error(error7) + elif lag > dmaxlag: + error7 = "Mirror is lagging by over %.1f hours, difference is : %.2f hours" % (dmaxlag, lag) + logging.error(error7) + else: + info7 = addy+" is in sync, current lag : %.2f hours" % (lag) + logging.info(info7) + + # Now common lines + tstamp7 = "Timestamp on Mirror : "+str(ots).strip() + curtime7= "Current time in UTC : "+str(time.strftime("%s %a, %d %b %Y %H:%M:%S +0000", time.gmtime())) + bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate + logging.info(tstamp7) + logging.info(curtime7) + logging.info(bugurl7) + # New line for the prettiness logging.info('') remove_handler(handler) |