#!/usr/bin/env python # -*- coding: cp1252 -*- ''' Created on 08.10.2011 @author: sth2mt ''' import time from optparse import OptionParser import FertigungsTest.XML.Parser as XmlParser import xml.sax as Interpreter import FertigungsTest.Hardware.LtInterface as LT import os as os import subprocess O_PruefSoftware = None class PruefSoftware: ObjCount = 0 _Thread_name = "PruefSoftware" stout = False LogOut = False O_LT = None O_XmlParser = None def __init__(self): ''' Constructor ''' PruefSoftware.ObjCount += 1 self.printf("%i.Construktor %s Anzahl %i App %i" % (PruefSoftware.ObjCount,PruefSoftware._Thread_name,PruefSoftware.ObjCount,os.getuid())) pass def printf(self,string): fOutput = file if PruefSoftware.stout: print string if PruefSoftware.LogOut: if fOutput.closed: fOutput = open ("PruefSWInput.log","a+") print >> fOutput,("%s" % string) #Ausgabe in logDatei umbiegen if (fOutput.closed==False): fOutput.flush() fOutput.close() pass def __del__(self): self.printf ("Pruefsoftware __del__(self) PruefSoftware.ObjCount %i"%PruefSoftware.ObjCount) if PruefSoftware.ObjCount>0: PruefSoftware.ObjCount -= 1 if PruefSoftware.ObjCount==0: if PruefSoftware.O_XmlParser != None: self.printf ("del(O_XmlParser)") del(PruefSoftware.O_XmlParser) if PruefSoftware.O_LT != None: self.printf( "del(O_LT)") del(PruefSoftware.O_LT) # In /var/run/diag service = 0 setzen # Andere Prozesse Informieren das PruefSoftware beendet f_diag = open("/var/run/diag/service","w") try: f_diag.write('0') finally: f_diag.close() self.printf("Pruefsoftware __del__(self) Ende") pass def main(self,optionen,args): #return 0 self.printf ("PruefSoftware -g %s"%(optionen.GUI)) self.printf ("Start") if optionen.GUI: if optionen.GUI == "production": mode = 1 elif optionen.GUI == "browser": mode = 2 else: PruefSoftware.error("unbekannte option -g %s" %optionen.GUI) self.printf ("unbekannte option -g %s" %optionen.GUI) else: PruefSoftware.error("Bitte Option [-g] (production,browser,..) angeben") self.printf ("Bitte Option [-g] (production,browser,..) angeben") self.printf ("mode=%i" %mode) #Instanzen anlegen if PruefSoftware.O_LT == None: PruefSoftware.O_LT = LT.Treiber()# Watchdog Starten if PruefSoftware.O_XmlParser == None: PruefSoftware.O_XmlParser = XmlParser.CommandHandler(mode) # In /var/run/diag service = 1 setzen # Andere Prozesse Informieren das PruefSoftware läuft f_diag = file f_diag = open("/var/run/diag/service","w") try: f_diag.write('1') finally: f_diag.close() if mode == 1: Input = ' ' try: Input=raw_input() except Exception,e: print "raw_input", e self.printf("raw_input %s" %e) Input = ' ' while Input!= "z": if Input != '': if Input[0] == '<': try: Interpreter.parseString(Input,PruefSoftware.O_XmlParser,None) except Exception,e: print "Interpreter Type mismatch", e self.printf ("Interpreter Type mismatch %s" % e) try: Input=raw_input() except Exception,e: #print "raw_input", e #Bei Aufruf von Signalhandler wird diese EOF Exception geworfen Input = ' ' pass elif mode == 2: # Ansteuerung von webgui Bittwister ueber browser Input = '' try: Input=(raw_input()+"\r\n") #printf ("%s" % Input) except Exception,e: print "raw_input", e self.printf ("raw_input %s" % e) Input = '' while Input!= "z": if Input != '': position_CommandBegin = Input.find("") if (position_CommandBegin>(-1)): position_CommandEnd = Input.rfind("") if (position_CommandEnd>(-1)): Output=Input[position_CommandBegin:position_CommandEnd+10] try: Interpreter.parseString(Output,PruefSoftware.O_XmlParser,None) self.printf ("%s" % Output) Input = '' except Exception,e: #print "Interpreter Type mismatch", e Input = '' try: Input+=(raw_input()+"\r\n") #printf ("%s" % Input) except Exception,e: print "raw_input", e #Bei Aufruf von Signalhandler wird diese EOF Exception geworfen Input = '' pass pass if __name__ == '__main__': PruefSoftwarePara = OptionParser("PruefSoftware -g --gui [production, browser], -h --help") PruefSoftwarePara.add_option("-g", "--gui",dest="GUI",default ="production",help="GUI: production,browser" ) mode=0 (optionen,args) = PruefSoftwarePara.parse_args() dir = os.popen("ps aux | grep -v grep | grep -i python").read() #print "%s count %i"%(dir,dir.count("PruefSoftware.py")) if dir.count("PruefSoftware.py") == 1: #print "Prozess anstarten" O_PruefSoftware = PruefSoftware() O_PruefSoftware.main(optionen,args) #else: #print "Prozess bereits gestartet -> Exit" pass