Exemple #1
0
 def Set_xml(self,xmlstr):
     self.xml=xmlstr
     xf=None
     if (self.opts['-xsd']=='-'):
         xsdfile=[get_main_dir(),'OMCEanalyser.xsd']
         CheckFile(self.context,xsdfile)
         self.context.NOISE('Reading xsdfile begin...')
         xf=file(os.path.join(*xsdfile),'r')
         self.context.NOISE('Reading xsdfile end...')
     else:
         xsdfile=self.context.PathJoin(get_main_dir(),self.opts['-xsd'])
         if xsdfile!='':
             xsd=self.context.ReadFile(xsdfile)
             xf=StringIO.StringIO(xsd)
     if not (xf is None):
         if type(xsdfile)==type([]):
             xsd_name=MakeFilename(xsdfile)
         else:
             xsd_name=xsdfile
         self.context.PRINT("Validating against XML Schema (%s)" % xsd_name,VL_Info)
         xmlschemadoc=etree.parse(xf)
         xf.close()
         xmlschema=etree.XMLSchema(xmlschemadoc)
         xmldoc=etree.XML(self.xml)
         xmlschema.assertValid(xmldoc)
     doc=None
     if amara_version==1:
         doc = amara.parse(xmlstr)
     elif amara_version==2:
         doc = bindery.parse(xmlstr,standalone=True,validate=False)
     else:
         self.context.ERROR(82)
     self.doc=doc
     return
Exemple #2
0
 def exposed_OMCE(self,argv,path,modname,functab):
     OMCEService.LOCK.acquire()
     OMCEService.RunningSimulations+=1
     OMCEService.SimulationID+=1
     self.SimulationID=OMCEService.SimulationID
     self.SetSimIDStr()
     OMCEService.LOCK.release()
     self.Server.logger.info("starting simulation %s", self.SimIDStr)
     context=ConText(functab)
     context.IsServer=True
     context.Imports=os.path.join(get_main_dir(),OMCEService.Imports)
     ExitCode=0
     try:
         try:
             try:
                 Simulator(argv,context,path,modname,True)
             except Error,er:
                 errmsg=DefConText.ERRORMSG(er.number,*er.params)
                 self.Server.logger.info("simulation %sterminated with Error %s", self.SimIDStr,errmsg)
                 context.ERROR(er.number,*er.params)
         except Terminate,te:
             ExitCode = te.code
     except Exception,e:
         context.PRINT(context.ERRORMSG(255,'\nFatal Error: '+context.STR(e)+"!"),VL_Error)
         context.PRINT(context.MSG(1,'Service'),VL_Error)
         self.Server.logger.info("simulation %sterminated with exception %s", self.SimIDStr,str(e))
         ExitCode=255
Exemple #3
0
def main():
    cmdargv=list(sys.argv[1:])
    cfg=''
    if '--config' in cmdargv:
        i=cmdargv.index('--config')
        if len(cmdargv)>i+1:
            cfg=cmdargv[i+1]
            del cmdargv[i]
        else:
            print 'Warning: config file is not given after option --config'
        del cmdargv[i]
    if cfg=='':
        cfg=os.path.join(get_main_dir(),OMCED_CONFIG_FILE)
    argv=sys.argv[0:1]+['--Q']+ReadOptionFile(cfg)
    argv = argv + cmdargv
    pidfile = open(OMCED_PID_FILE, 'w')
    pidfile.write("%s" % os.getpid())
    pidfile.write("%s" % os.getcwd())
    ExitCode=run_main(ServerMain,argv,False)
    return ExitCode
Exemple #4
0
def ServerMain(argv=[],usecfg=True):
    cfg_filename=''
    CP=''
    argv=list(argv)
    if usecfg:
        for prm in argv[1:]:
            if prm[0:6]=="--CFG=":
                o=prm.split('=')
                if len(o)==2:
                    cfg_filename=DefConText.PathJoin(get_main_dir(),DefConText.STR(o[1]))
        if cfg_filename=='':
            cfg_filename=os.path.splitext(sys.argv[0])[0]+'.cfg'
        argv=argv[0:1]+ReadOptionFile(DefConText,cfg_filename)+argv[1:]
    for prm in argv[1:]:
        if prm[0:5]=="--CP=":
            o=prm.split('=')
            if len(o)==2:
                CP=str(o[1])
    if CP!='':
        DefConText.CodePage=CP
    DefConText.PRINT('Config file: '+cfg_filename,VL_Noise)
    um=[]
    ar=False
    port = DefServerPort
    host='0.0.0.0'
    fork=False
    quiet=False
    vdbn=''
    tls=None
    oo=[]
    skip=1 #skip argv[0]
    for i,prm in enumerate(argv):
        if skip>0:
            skip-=1
            continue
        elif len(um)==0:
            if prm=="--THREAD":
                fork=False
            elif prm[0:7]=="--PORT=":
                o=prm.split('=')
                if (len(o)==2) and isInt(o[1]):
                    port=int(o[1])
            elif prm[0:7]=="--HOST=":
                o=prm.split('=')
                if len(o)==2:
                    host=o[1]
            elif prm=="--AUTOREGISTER":
                ar=True
            elif prm=="--NOREGISTER":
                ar=False
            elif prm=="--NOAUTH":
                vdbn=''
                tls=None
            elif prm=="--FORK":
                fork=True
            elif prm=="--Q":
                quiet=True
            elif prm=="--Q-":
                quiet=False
            elif prm[0:10]=="--IMPORTS=":
                o=prm.split('=')
                if len(o)==2:
                    OMCEService.Imports=o[1]
            elif prm[0:4]=="--V=":
                o=prm.split('=')
                if len(o)==2:
                    DefConText.VerboseLevel=int(o[1])
            elif prm[0:6]=="--LOG=":
                o=prm.split('=')
                if len(o)==2:
                    if o[1]!="":
                        fn=os.path.join(get_main_dir(),'logs',o[1])
                        DefConText.logfile=open(fn,'a')
            elif prm[0:6]=="--VDB=":
                o=prm.split('=')
                if len(o)==2:
                    if o[1]!="":
                        vdbn=os.path.join(get_main_dir(),o[1])
                        tls=None
            elif prm=="--TLS":
                skip=2
                if len(argv)>i+2:
                    tls=(argv[i+1].strip(),argv[i+2])
                    vdbn=''
                else:
                    msg[1][0]=''
                    DefConText.ERROR(77,'--TLS')
            elif prm=="--USER":
                um.append('USER')
            else:
                oo.append(prm)
        else:
            um.append(prm)
    if (len(um)>0):
        msg[1][0]=''
        EditVDB(vdbn,um)
    else:
        msg[1][0]=''
        for prm in oo:
            DefConText.PRINT(DefConText.MSG(102,prm),VL_Warn)
        wf=False
        for prm in sys.argv[1:]:
            if not (re.match('^-(?!-).*',prm) is None):
                wf=True
        if wf:
            DefConText.PRINT(DefConText.MSG(103,prm),VL_Warn)
        StartServer(port,ar,host,fork,quiet,vdbn,tls)
    return