summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2008-12-22 23:00:01 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2008-12-22 23:00:01 -0800
commitf5753d1f1599cec740964e978392d16b2020058d (patch)
tree2a26d019fc5fff6e1fa6a2dfdae2314c6ebb4f79
parentRemove ambiguty over mirror type. (diff)
downloadgard-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-xgard-v2.py54
1 files changed, 31 insertions, 23 deletions
diff --git a/gard-v2.py b/gard-v2.py
index 4c77f0a..356f9d2 100755
--- a/gard-v2.py
+++ b/gard-v2.py
@@ -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)