unified whitespace
parent
7177e470e5
commit
bf7859f05f
14
Logger.py
14
Logger.py
|
|
@ -25,7 +25,7 @@ class Logger(object):
|
|||
def temp_rise(self, old, new,sensor):
|
||||
if(old == self.temp_prev_default):
|
||||
return True
|
||||
if((old-new)>self.temp_max_diff or (new-old)>self.temp_max_diff):
|
||||
if(((old-new) > self.temp_max_diff) or ((new-old) > self.temp_max_diff)):
|
||||
self.log.write('error checking ' + sensor + ';prev(' + str(old) + ');cur(' + str(new) + '); ... @' + time.ctime() + "\n")
|
||||
self.log.flush()
|
||||
return False
|
||||
|
|
@ -46,9 +46,9 @@ class Logger(object):
|
|||
# generic callback #
|
||||
##########################################
|
||||
def cb_generic(self,value, sensor, type, supress = False):
|
||||
if(type == SensorType.temp):
|
||||
if type == SensorType.temp:
|
||||
i = int(sensor[-1])-1 #sensor contains name, followed by int
|
||||
if(self.temp_rise(self.prev_temps[i],value,sensor)):
|
||||
if self.temp_rise(self.prev_temps[i], value, sensor):
|
||||
self.write_value(value, sensor)
|
||||
self.prev_temps[i] = value
|
||||
elif (type == SensorType.none):
|
||||
|
|
@ -69,8 +69,8 @@ class Logger(object):
|
|||
new.text = traceback.format_exc()
|
||||
root.append(new)
|
||||
tree.write(settings.exceptionlog)
|
||||
|
||||
self.log.write('an Exception happen during connection @'+time.ctime()+"\n")
|
||||
message = 'an Exception happend @' + time.ctime()+"\n"
|
||||
self.log.write(message)
|
||||
self.log.flush()
|
||||
print('an Exception happen during connection @'+time.ctime()+"\n")
|
||||
#end#
|
||||
print(message)
|
||||
|
||||
|
|
|
|||
14
all.py
14
all.py
|
|
@ -45,10 +45,10 @@ if __name__ == "__main__":
|
|||
check_dirs_and_files()
|
||||
log=open(settings.logname, 'a')
|
||||
try:
|
||||
log.write('setting up "all" ... @'+time.ctime()+"\n")
|
||||
log.write("setting up all ... @" + time.ctime() + "\n")
|
||||
while True:
|
||||
if obtainLock():
|
||||
logger=Logger(log, )
|
||||
logger = Logger(log)
|
||||
try:
|
||||
connections = []
|
||||
connectedSensors = []
|
||||
|
|
@ -58,10 +58,10 @@ if __name__ == "__main__":
|
|||
connection, sensors = conSetup.setupConnectionAndSensors(con['host'], con['sensors'], settings.TIMES, logger.cb_generic)
|
||||
connections.append(connection)
|
||||
connectedSensors.append(sensors)
|
||||
log.write("started logging at %s ... @ %s\n"% (formatHost(con['host']), time.ctime()))
|
||||
log.write("started logging at " + formatHost(con['host']) + " ... @ " + time.ctime() + "\n")
|
||||
log.flush()
|
||||
raw_input('Press key to restart\n')
|
||||
log.write('stop logging... @'+time.ctime()+"\n")
|
||||
raw_input("Press key to restart\n")
|
||||
log.write("stop logging... @" + time.ctime() + "\n")
|
||||
conSetup.disconnectAny(connections)
|
||||
except Exception as inst:
|
||||
#connection failed, log and exit
|
||||
|
|
@ -69,8 +69,8 @@ if __name__ == "__main__":
|
|||
print(inst)
|
||||
freeLock()
|
||||
else:
|
||||
print('lock file active!!')
|
||||
log.write('lock collision: lock "all" active @ '+time.ctime()+"\n")
|
||||
print("lock file active!!")
|
||||
log.write("lock collision: lock 'all' active @ " + time.ctime() + "\n")
|
||||
print("wait for retry (" + str(settings.waitDelay) + ")")
|
||||
time.sleep(settings.waitDelay)
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
|||
|
|
@ -6,23 +6,23 @@ import time
|
|||
def prevday(then, now):
|
||||
#ist "then" gestern (oder noch älter)?
|
||||
greaterDay = (then.tm_yday < now.tm_yday) and (then.tm_year == now.tm_year)
|
||||
if(greaterDay):
|
||||
if greaterDay:
|
||||
newYear = False
|
||||
else:
|
||||
newYear = then.tm_year < now.tm_year
|
||||
return (greaterDay) or (newYear)
|
||||
return greaterDay or newYear
|
||||
|
||||
def preptime():
|
||||
now = time.localtime()
|
||||
day = now.tm_mday
|
||||
month = now.tm_mon
|
||||
year = str(now.tm_year)
|
||||
if(day<10):
|
||||
if day < 10:
|
||||
day = "0" + str(day)
|
||||
else:
|
||||
day = str(day)
|
||||
if(month<10):
|
||||
month="0"+str(month)
|
||||
if( month < 10:
|
||||
month = "0" str(month)
|
||||
else:
|
||||
month = str(month)
|
||||
return month + "." + day + "." + year
|
||||
|
|
|
|||
Loading…
Reference in New Issue