Commit 3a12bbea authored by Hicham Brahimi's avatar Hicham Brahimi

ajout rapatriement 4G, deplacement de la gestion de wvdial dans rapatriement

parent 896d5b7b
# A executer avec SUDO
# Gestion de wvdial deplacee dans rapatriement.py
# PYTHON 3.5+
import subprocess
......@@ -10,13 +11,14 @@ import os.path
from datetime import datetime
import psutil
def check_pid(pid):
# Verifie l'existence d'un pid
if psutil.pid_exists(pid):
p = psutil.Process(pid)
if p.status() != psutil.STATUS_ZOMBIE:
return True
return False
#def check_pid(pid):
# # Verifie l'existence d'un pid
# if psutil.pid_exists(pid):
# p = psutil.Process(pid)
# if p.status() != psutil.STATUS_ZOMBIE:
# return True
# return False
# Verifie qu'il n'y a pas d'autres processus d'envoi en verifiant le fichier lock
......@@ -42,15 +44,15 @@ f = None
try:
pid = subprocess.Popen(["wvdial"])
#pid = subprocess.Popen(["wvdial"])
print("============ WVDIAL LANCE ==============")
print("PID = ",pid.pid)
#print("============ WVDIAL LANCE ==============")
#print("PID = ",pid.pid)
time.sleep(10)
#time.sleep(10)
print("============ CORRECTION ROUTE ==============")
subprocess.Popen(["route", "add", "default", "dev", "ppp0"]) # Corrige la 4G au demarrage du raspberry
#print("============ CORRECTION ROUTE ==============")
#subprocess.Popen(["route", "add", "default", "dev", "ppp0"]) # Corrige la 4G au demarrage du raspberry
print("============ CONNEXION ==============")
......@@ -77,8 +79,8 @@ except KeyboardInterrupt :
print("============= LIBERATION =============")
os.remove(".lockprocess")
print("============ WVDIAL ARRET ==============")
subprocess.Popen(["kill", "-1", pid.pid])
#print("============ WVDIAL ARRET ==============")
#subprocess.Popen(["kill", "-1", str(pid.pid)])
except Exception as ex:
......@@ -88,8 +90,8 @@ except Exception as ex:
print("============= LIBERATION =============")
os.remove(".lockprocess")
print("============ WVDIAL ARRET ==============")
subprocess.Popen(["kill", "-1", pid.pid])
#print("============ WVDIAL ARRET ==============")
#subprocess.Popen(["kill", "-1", str(pid.pid)])
print("================ FIN =================")
......@@ -99,9 +101,9 @@ if f is not None:
log.close()
if check_pid(pid.pid):
print("============ WVDIAL ARRET ==============")
subprocess.Popen(["kill", "-1", str(pid.pid)])
#if check_pid(pid.pid):
#print("============ WVDIAL ARRET ==============")
#subprocess.Popen(["kill", "-1", str(pid.pid)])
time.sleep(1)
if os.path.isfile("./.lockprocess"):
......
# A EXECUTER AVEC SUDO
# Python 3.5+
import os
import subprocess
import shutil
import time
import psutil
import sys
def check_pid(pid):
# Verifie l'existence d'un pid
if psutil.pid_exists(pid):
p = psutil.Process(pid)
if p.status() != psutil.STATUS_ZOMBIE:
return True
return False
FOLDER = "data/"
TRAITEES = "traitees/"
DIR = os.listdir(FOLDER)
pid = -1
# Parcours les fichiers et les envois au serveur PC
while True:
try :
pid = subprocess.Popen(["wvdial"])
print("============= WVDIAL LANCEE =============")
print("PID = ", pid.pid)
time.sleep(10)
print("============= CORRECTION ROUTE =============")
subprocess.Popen(["route", "add", "default", "dev", "ppp0"])
for f in DIR :
if os.access(FOLDER+f, os.W_OK) and os.access(FOLDER+f, os.R_OK):
print(FOLDER+f)
process = subprocess.Popen(["python3", "processusEnvoi4G.py", FOLDER+f])
process.wait()
print("Fin process")
shutil.move(FOLDER+f, TRAITEES+f)
print("Dossier data vide -- FIN")
except KeyboardInterrupt:
print("============= WVDIAL ARRET =============")
subprocess.Popen(["kill", "-1", str(pid.pid)])
sys.exit(0)
except Exception as ex:
print(ex)
print("============= WVDIAL ARRET =============")
subprocess.Popen(["kill", "-1", str(pid.pid)])
if check_pid(pid.pid):
print("============= WVDIAL ARRET =============")
subprocess.Popen(["kill", "-1", str(pid.pid)])
time.sleep(21600) # Envoi toutes les 6 heures
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment