Skip to content
Snippets Groups Projects
Commit 344a8c9c authored by Edileuton Henrique de Oliveira's avatar Edileuton Henrique de Oliveira
Browse files

Add elapsedtime function that verifies if have passed 24 hours since the last sucessful execution

parent af352cd2
No related branches found
No related tags found
1 merge request!7Elapsed Time
......@@ -27,7 +27,7 @@ import subprocess
import urllib
import collect
import glob
from time import localtime, strftime
from time import localtime, strftime, time
from xml.etree.ElementTree import tostring
# ==========================================
......@@ -36,7 +36,8 @@ from xml.etree.ElementTree import tostring
# TODO: Check compatibility with 64bit Windows (Program Files(x86) folder)
DATASIDPATH = os.environ["ProgramFiles"] + "\\DataSID"
PREVIOUSPATH = DATASIDPATH + "\\data\\previous"
URL = "http://bisimmcdev.c3sl.ufpr.br/axis2/services/DataSID"
URL = "http://simmc.c3sl.ufpr.br/axis2/services/DataSID"
LASTEXEC = DATASIDPATH + "\\data\\lastexec.txt"
# Log lifetime in days
LOGLIFETIME = 30
......@@ -184,12 +185,25 @@ def callUpdater():
# Wait to be killed
out = proc.communicate()
# Check if have passed 24 hours since the last sucessful execution
def elapsedTime():
if not os.path.exists(LASTEXEC):
return True
lastexec = file(LASTEXEC , "r").read()
# 86400 seconds = 24 hours
if time() - float(lastexec) > 86400:
return True
else:
return False
# ==========================================
# Main program
# ==========================================
# Open the logfile
log = Log()
# Delete old log files
try:
deleteOldLogs()
......@@ -204,7 +218,6 @@ except:
log.close()
sys.exit(1)
# Write version conf files
try:
writeVersionConf(version)
......@@ -258,19 +271,26 @@ if(updatelink):
else:
log.write("UPDATE: No updates are available.")
# Check if have passed 24 hours since the last sucessful execution
if not elapsedTime():
# If everything ran ok, exit with success status
log.write("EXIT(0): Success, not elapsed time.")
log.close()
sys.exit(0)
# Collect data
try:
collectData = collect.collect()
except Exception, e:
log.write("ERROR(8): Failed to collect data: " + str(e))
log.write("ERROR(8): Failed to collect data. " + str(e))
log.close()
sys.exit(8)
# Write the collect-data.xml file
try:
writeCollectData(collectData, "collect-data.xml")
except:
log.write("ERROR(9): Failed to write collect-data.xml.")
except Exception, e:
log.write("ERROR(9): Failed to write collect-data.xml. " + str(e))
log.close()
sys.exit(9)
......@@ -282,8 +302,8 @@ except clientError, e:
log.write("Client message: " + str(e.errorMsg))
log.close()
sys.exit(10)
except:
log.write("ERROR(11): Failed to get the proxy information from Windows registry.")
except Exception, e:
log.write("ERROR(11): Failed to get the proxy information from Windows registry. " + str(e))
log.close()
sys.exit(11)
......@@ -298,8 +318,8 @@ if os.path.isdir(PREVIOUSPATH):
# Write the collect-data.xml file
try:
writeCollectData(netCollectData, "net-collect-data.xml")
except:
log.write("ERROR(13): Failed to write net-collect-data.xml.")
except Exception, e:
log.write("ERROR(13): Failed to write net-collect-data.xml. " + str(e))
log.close()
sys.exit(13)
......@@ -311,11 +331,16 @@ if os.path.isdir(PREVIOUSPATH):
log.write("Client message: " + str(e.errorMsg))
log.close()
sys.exit(10)
except:
log.write("ERROR(11): Failed to get the proxy information from Windows registry.")
except Exception, e:
log.write("ERROR(11): Failed to get the proxy information from Windows registry. " + str(e))
log.close()
sys.exit(11)
# Record the last sucess execution
lastExecFile = file(LASTEXEC , "w")
lastExecFile.write(str(time()))
lastExecFile.close()
# If everything ran ok, exit with success status
log.write("EXIT(0): Success.")
log.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment