1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| #!/usr/bin/python
import datetime,BaseHTTPServer
import HL7Passerrelle
import time
import os, shutil
import threading
import dxLab
VERSION=open(os.path.dirname(os.path.realpath(__file__))+'/version.txt','r')
__Name__="PERINAT_INTERCOM_SERVER"
__version__=''.join(VERSION.readlines())
__port__=34672
def directoryCheck():
'''verifie que les dossiers de travail sont presents, sinon creation'''
curdir=os.path.dirname(os.path.realpath(__file__))
print curdir
listDossier=['IN',#dossier de reception identite/mouvement
'OUT',#dossier de sortie
'TRASH',#corbeille
'TEMP',#Dossier temporaire
'IN_LABO',#Dossier de reception des resultats de labo
'OUT/acte_pratique',#dossier de sortie activite
'OUT/compte_rendu',#Dossier de sortie CR
'OUT_PURGE',#dossier de sortie des purge SQL
'ERROR',#Dossier de sortie en cas d'erreur de traitement
'ERROR/LABO',#Dossier de sortie des erreur de traitement LABO
'ERROR/IDT_MVT',#Dossier de sortie des erreur de traitement IDT_MVT
'LOG'#dossier de sauvegarde de log
]
for path in listDossier:
try:
os.mkdir('%s/%s' %(curdir,path))
print "--> %s/%s : CREATED" %(curdir,path)
except:
print "--> %s/%s : ALREADY EXIST" %(curdir,path)
def logfileCheck():
"""Met en archive les fichiers log,
Cree de nouveaux fichiers pret a l'emploi"""
listFile=['IDT_MVT','LABO','ACT','CR']
curdir=os.path.dirname(os.path.realpath(__file__))
t=str(time.time())
try:
os.mkdir('%s/LOG' %(curdir))
except:
pass
for f in listFile:
try:
shutil.move('%s/LOG/%s.log' %(curdir,f),'%s/LOG/%s_%s.log' %(curdir,f,t))
print "--> %s/LOG/%s : MOVED" %(curdir,f)
except:
print "--> %s/LOG/%s : NOT EXIST" %(curdir,f)
F=open('%s/LOG/%s.log' %(curdir,f),'w')
F.close()
print "--> %s/LOG/%s : CREATED" %(curdir,f)
def IDT_MVT():
HL7Passerrelle.identiteMvt()
print "--> IDT_MVT THREAD RUNNING"
def OUT_MSG():
HL7Passerrelle.traitementOUT()
print "--> OUT_MSG THREAD RUNNING"
def LABO():
dxLab.traitement()
print "--> LABO THREAD RUNNING"
try:
from asyncore import dispatcher
import sys, time, socket
except Exception,e:
print e
class Server( dispatcher ):
def __init__(self,port=5000):
dispatcher.__init__(self)
self.create_socket( socket.AF_INET, socket.SOCK_STREAM )
self.bind( ( '', port ) )
self.listen(1)
if __name__ == '__main__':
print "%s %s" %(__Name__,__version__)
try:
Server(port=__port__)
print "==> SERVER RUNNING : PORT ==> %s" %(str(__port__))
directoryCheck()#verification des dossiers
logfileCheck()#verification des fichiers log
a=0
while a<2:
th1=threading.Thread(group=None,target=IDT_MVT)
th1.start()
th2=threading.Thread(group=None,target=OUT_MSG)
th2.start()
th3=threading.Thread(group=None,target=LABO)
th3.start()
del th1,th2,th3
time.sleep(0.5)
except Exception,e:
print "==> SERVEUR ALREADY RUNNING"
print " Patientez, abandon de demarrage"
time.sleep(3)
sys.exit() |