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
| racine=Tkinter.Tk()
isDown = False
isOpen = False
def MyTimer(tempo = 1.0):
global isOpen #quand j'enlève cette ligne
threading.Timer(tempo, MyTimer, [tempo]).start()
lPing = subprocess.Popen(["ping","-c", "1 ", ip ],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
sLigne, erreur = lPing.communicate()
#print sLigne
info_reg = info_reg = re.search(r'(\d+) packets transmitted, (\d+) received, (.+)% packet loss, time (\d+)ms',sLigne,re.M)
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':
isOpen = False
if(os.path.exists(pathLoc) and os.path.getsize(pathLoc) > 0):
s = ftp.FTP(pathServ,user,passwd) # Connect
f = open(pathLoc,'rb') # file to send
s.storbinary('STOR test.txt', f) # Send the file
f.close() # Close file and FTP
s.quit()
os.remove(pathLoc) #supprime fichier
else:
print racine.state()
if(received == 0 and loss == 100): #et enlève ceci du if
fen_matricule(racine) #c'est ici que ça pose problème
isOpen = True
def save(val,racine):
if(os.path.exists(pathLoc) == False):
file(pathLoc, 'w')
now = datetime.datetime.now()
print now.strftime("%d/%m/%YT%H:%M:%S")
line = now.strftime("%d/%m/%YT%H:%M:%S")+'\n'
logfile2 = open(pathLoc, 'a+')
logfile2.write(line)
logfile2.close()
isDown = True;
print val
#ferme la fenêtre
racine.destroy()
#saisie.delete(0, Tk.END)
def fen_matricule(racine):
fond=Tkinter.Canvas(racine, width=300, height=200, background='darkgray')
fond.pack()
texte=Tkinter.Label(fond, text="Matricule", fg="black")
texte.pack(side=Tkinter.LEFT)
valsaisir=Tkinter.StringVar() # prevoir la variable pour recevoir le texte saisi
saisie=Tkinter.Entry(textvariable=valsaisir, width=30)
saisie.pack()
bouton=Tkinter.Button(racine, text="OK", command=lambda: save(valsaisir.get(),racine)).pack(side=Tkinter.BOTTOM)
racine.mainloop()
valsaisir.get()
MyTimer(float(time)) |
Partager