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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| #!/usr/bin/python
# -*-coding:Utf-8 -*
import os,sys
import ftplib as ftp
import sched
import time
import datetime
import threading
import subprocess
import Tkinter
import re
#répertoire courant du fichier
dir_path = os.path.abspath(os.path.dirname(sys.argv[0]))
racine=Tkinter.Tk()
#sys.path[0]
if sys.platform == "linux2":
separateur = "/"
elif sys.platform == "win32":
separateur = "\\"
ip="195.5.84.280"
txtHr=Tkinter.Label(racine, text="", fg="black")
texte=Tkinter.Label(racine, text="Entrez votre n° d'identification", fg="black")
txtInfoServ=Tkinter.Label(racine, text="Serveur actif", fg="black")
txtIP=Tkinter.Label(racine, text=ip, fg="black")
bouton=Tkinter.Button(racine, text="Pointer", command=racine.withdraw)
boutonESC=Tkinter.Button(racine, text="Fermer", command=racine.quit())
valsaisir=Tkinter.StringVar() #variable to get value
saisie=Tkinter.Entry(textvariable=valsaisir, width=30)
isDown = False
isOpen = False
cpt = 0
def MyTimer(cpt,isOpen,tempo):
#si linux
if sys.platform == "linux2":
lPing = subprocess.Popen(["ping","-c", "1 ", ip ],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
elif sys.platform == "win32":
lPing = subprocess.Popen(["ping","-n", "1 ", ip ],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
sLigne, erreur = lPing.communicate()
print sLigne
transmis = 0
received = 0
loss = 100
time = 0
cpt = int(cpt) + 1
#si linux
if sys.platform == "linux2":
info_reg = info_reg = re.search(r'(\d+) packets transmitted',sLigne,re.M)
if info_reg:
transmis = int(info_reg.group(1))
info_reg = info_reg = re.search(r'(\d+) received',sLigne,re.M)
if info_reg:
received = int(info_reg.group(1))
info_reg = info_reg = re.search(r'(\d+)% packet loss',sLigne,re.M)
if info_reg:
loss = int(info_reg.group(1))
if loss == 100:
loss = 1
info_reg = info_reg = re.search(r'time (\d+)ms',sLigne,re.M)
if info_reg:
time = int(info_reg.group(1))
#info_reg = info_reg = re.search(r'(\d+) packets transmitted, (\d+) received, (.+)% packet loss, time (\d+)ms',sLigne,re.M)
elif sys.platform == "win32":
info_reg = info_reg = re.search(r'envoy\Ds = (\d+)',sLigne,re.M)
if info_reg:
transmis = int(info_reg.group(1))
info_reg = info_reg = re.search(r're\Dus = (\d+)',sLigne,re.M)
if info_reg:
received = int(info_reg.group(1))
info_reg = info_reg = re.search(r'perte (\d+)%',sLigne,re.M)
if info_reg:
loss = int(info_reg.group(1))
info_reg = info_reg = re.search(r'Moyenne = (\d+)ms',sLigne,re.M)
if info_reg:
time = int(info_reg.group(1))
#info_reg = info_reg = re.search(r'Paquets : envoyés = (\d+), reçus = (\d+), perdus = (\d+) perte (.+)%',sLigne,re.M)
now = datetime.datetime.now()
#si l'expression régulière a donné un résultat
if transmis > 0:
"""transmis = int(info_reg.group(1))
received = int(info_reg.group(2))
loss = int(info_reg.group(3))
time = int(info_reg.group(4))"""
isDown = False
if received == 0:
isDown = True
#si le serveur répond après avoir été down et qu'il y a un fichier à uploader alors upload
#recupere les parametres du fichier
if isDown == False or isDown == 'False':
#Ferme la fenêtre pour encoder les pointages locales
if isOpen == True or isOpen == 'True':
#close window
#racine.destroy()
showroot(1)
isOpen = False
else:
if(cpt > 2):
#racine.withdraw()
isOpen = False
hideme()
#showroot(1)
#cpt = 0
print "connecte"
else:
if(received == 0 and (isOpen == False or isOpen == 'False')):
print now.strftime("%d/%m/%YT%H:%M:%S")
#fen_matricule(racine)
showroot(0)
isOpen = True
else:
print cpt
if(cpt > 2):
isOpen = False
showroot(1)
print "connecte"
if(received == 0 and (isOpen == False or isOpen == 'False')):
print now.strftime("%d/%m/%YT%H:%M:%S")
#fen_matricule(racine)
showroot(0)
isOpen = True
threading.Timer(2.0, MyTimer, [cpt,isOpen,2.0]).start()
def showroot(param):
now = datetime.datetime.now()
if param == 0:
txtInfoServ.config(text="Serveur inactif")
bouton.configure(state='normal',background='red',command=lambda: save(valsaisir.get(),racine,saisie))
saisie.configure(state='normal')
txtHr.config(text=now.strftime("%H:%M:%S"))
#boutonESC.pack_forget()
else:
txtInfoServ.config(text="Serveur actif")
bouton.configure(state='disabled',background='green',command=racine.withdraw)
saisie.configure(state='disabled')
txtHr.config(text=now.strftime("%H:%M:%S"))
racine.deiconify()
def hideme():
racine.withdraw()
MyTimer(cpt,isOpen,2.0)
#def fen_matricule(racine):
txtHr.pack(side=Tkinter.TOP)
texte.pack(side=Tkinter.TOP)
saisie.pack()
#boutonESC.pack(side=Tkinter.BOTTOM)
txtIP.pack(side=Tkinter.BOTTOM)
txtInfoServ.pack(side=Tkinter.BOTTOM)
bouton.pack(side=Tkinter.BOTTOM)
#boutonESC.pack_forget()
hideme()
racine.configure(width=260,height=150)
racine.mainloop()
#MyTimer(isOpen,float(time))
#show window
#racine.wm_deiconify() |
Partager