From 62c59b5fc1dceb42b58dedfcda03ce3bd946c8c4 Mon Sep 17 00:00:00 2001 From: lionel Date: Mon, 23 Nov 2015 10:25:12 +0100 Subject: [PATCH] Added date and time to log messages + some clean ups --- cm160Server.py | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/cm160Server.py b/cm160Server.py index 53ad88b..285b1a8 100755 --- a/cm160Server.py +++ b/cm160Server.py @@ -72,8 +72,8 @@ class UserOutput: else: #Create it fd = open(self.__logFile, "w") - - fd.write("%s\n" % (line) ) + logdatetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + fd.write("%s %s\n" % (logdatetime, line) ) finally: if fd != None: fd.close() @@ -436,7 +436,7 @@ class CM160: def serSend(self, byteList): """Send a list of bytes to the serial port - openSerialPort() must have been successfully called before alling this method + openSerialPort() must have been successfully called before calling this method """ self.__ser.write( self.getString(byteList) ) for b in byteList: @@ -697,6 +697,7 @@ class MySQLDataStore(object): """Responsible for the storage and retrieval of CM160 data using a MySQL database to hold the data""" def __init__ (self): + self.__uo = uo self.__db = "owl" self.__StoreConn = None self.__StoreCursor = None @@ -768,8 +769,8 @@ class MySQLDataStore(object): def info(self, text): """Display info text""" -# if self.__uo != None: -# self.__uo.info(text) + if self.__uo != None: + self.__uo.info(text) ######################## Command line interface ########################## @@ -783,34 +784,6 @@ def usage(uo): uo.info("-d: Debug on. Send extra debug text to stdout if not in quiet mode.") uo.info("-h : Display this help text.") -def getInput(prompt="", noEcho=False): - """Get input from user""" - p = "INPUT: %s: " % (prompt) - if noEcho: - return getpass.getpass(p, sys.stdout) - return raw_input(p) - -def getDateTime(text): - """Return a datetime object from the given text - text may contain a datetime as either - dd/mm/yyyy or - hh:mi:dd/mm/yyyy - """ - - dt=None - - #if just the date has been entered - if text.find('/') != -1 and text.find(':') == -1: - dt=datetime.datetime.strptime(text,"%d/%m/%Y") - - elif text.find('/') != -1: - dt=datetime.datetime.strptime(text,"%H:%M:%d/%m/%Y") - - else: - raise OWLError("%s is not a valid datetime" % (text) ) - - return dt - # MAIN if __name__=='__main__': -- 2.39.2