y[[./tv/vignettes/vignettes.py] Style

darcs-hash:20090304122722-8fbb1-46d46804cd7de7cd89b88053fbda15127dec0cd3.gz
This commit is contained in:
Olivier Huber 2009-03-04 13:27:22 +01:00
parent b4ce95f3fa
commit 4a1c67a459

View file

@ -1,18 +1,18 @@
#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
import os,sys,socket,shutil
import os, sys, socket, shutil
sys.path.append('/usr/scripts/gestion')
import lock
import time
from time import localtime,sleep
from time import localtime, sleep
tmp_dir = '/tmp'
www_dir = '/var/www/'
img_dir = '%s/images' % www_dir
t = localtime()
trame_entete="""
trame_entete = """
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html lang=\"fr\">
<head>
@ -32,17 +32,17 @@ trame_entete="""
<a href=vignettes.html>Vignettes Normales</a><br>
<table cellpading=25 cellspacing=25>
<tr>
""" % (int(t[3]) ,int(t[4]) )
""" % (int(t[3]), int(t[4]) )
table_piedpage="""</tr>
table_piedpage = """</tr>
</table>
"""
trame_piedpage="""</body>
trame_piedpage = """</body>
</html>
"""
def ajoute_image(nom,fqdn,ip,html,html_petites):
def ajoute_image(nom, fqdn, ip, html, html_petites):
html.write('<td align="center">')
html.write('<img src="images/%s.jpg" alt="Chaine : %s / IP : %s"><br>' % (fqdn, nom, ip))
html.write('<b><u>Chaine :</u></b> %s<br><b><u>IP :</u></b> %s:1234' % (nom, ip))
@ -60,7 +60,7 @@ def vignettes() :
col = 0
col_petites = 0
#a factoriser
chaines_probleamatiques=[]
chaines_probleamatiques = []
os.system('/usr/scripts/tv/recup_sap')
#On est obligé de mettre en dur le path
#car il n'est pas configurable dans recup_sap
@ -76,28 +76,28 @@ def vignettes() :
line = line.strip()
nom = line.split(':')[0]
ip = line.split(':')[-1]
print '%s %s' %(str(ip),str(nom))
print '%s %s' % (str(ip), str(nom))
try :
fqdn = socket.gethostbyaddr(ip)[0]
except gai.error, err :
print 'On n\'arrive pas à résoudre ce nom %s %s' % (ip,err[1])
print 'On n\'arrive pas à résoudre ce nom %s %s' % (ip, err[1])
continue
except :
print 'Erreur inconnue'
continue
else :
#on évite les radios, peu de debit et pas de vignettes
if nom[0:3]=='rad' :
if nom[0:3] == 'rad' :
#C'est une radio on cherche un logo
nom_court=(' '.join(nom.split(' ')[2:])).lower()
nom_court = (' '.join(nom.split(' ')[2:])).lower()
print "On s'occupe de la radio %s" % nom_court
for file in os.listdir('%s /logos_radios' % img_dir):
try :
shutil.copy(' %s/logos_radios/%s' % (img_dir,file),'%s/%s.jpg' % (img_dir,fqdn))
shutil.copy(' %s/logos_radios/%s' % (img_dir,file),'%s/%s_petites.jpg' % (img_dir,fqdn))
shutil.copy(' %s/logos_radios/%s' % (img_dir, file),'%s/%s.jpg' % (img_dir, fqdn))
shutil.copy(' %s/logos_radios/%s' % (img_dir, file),'%s/%s_petites.jpg' % (img_dir, fqdn))
except :
#il n'y a pas de logo :-(
chaines_probleamatiques.append('<b><u>Chaine :</u></b> %s<br><b><u>IP :</u></b> %s:1234<br><br>\n' %(nom,ip))
chaines_probleamatiques.append('<b><u>Chaine :</u></b> %s<br><b><u>IP :</u></b> %s:1234<br><br>\n' % (nom, ip))
continue
else :
if col == 2 :
@ -110,35 +110,35 @@ def vignettes() :
html_petites.write('</tr><tr>\n')
else :
col_petites += 1
ajoute_image(nom,fqdn,ip,html,html_petites)
print 'on s\'occupe de %s %s' % (ip,nom)
ajoute_image(nom, fqdn, ip, html, html_petites)
print 'on s\'occupe de %s %s' % (ip, nom)
print '\trecuperation du flux'
#ip port duree
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts 2>/dev/null' % (ip,tmp_dir,ip))
pid = os.spawnlp(os.P_NOWAIT,'ffmpeg','ffmpeg','-deinterlace','-an','-i','%s/%s.ts' %(tmp_dir,ip),'-s','400x300','-r','1','-t','00:00:01','-f','image2','%s/%s.jpg' % (img_dir,fqdn))
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts 2>/dev/null' % (ip, tmp_dir, ip))
pid = os.spawnlp(os.P_NOWAIT,'ffmpeg','ffmpeg','-deinterlace','-an','-i','%s/%s.ts' % (tmp_dir, ip),'-s','400x300','-r','1','-t','00:00:01','-f','image2','%s/%s.jpg' % (img_dir, fqdn))
time.sleep(3)
os.kill(pid,9)
if not os.path.exists('%s/%s.jpg' % (img_dir,fqdn)) or not os.stat('%s/%s.jpg' % (img_dir,fqdn))[6] :
os.kill(pid, 9)
if not os.path.exists('%s/%s.jpg' % (img_dir, fqdn)) or not os.stat('%s/%s.jpg' % (img_dir, fqdn))[6] :
print '\tOn retente'
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts ' % (ip,tmp_dir,ip))
pid = os.spawnlp(os.P_NOWAIT,'ffmpeg','ffmpeg','-deinterlace','-an','-i %s/%s.ts' %(tmp_dir,ip),'-s 400x300','-r 1','-t 00:00:01','-f image2 %s/%s.jpg' % (img_dir,fqdn))
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts ' % (ip, tmp_dir, ip))
pid = os.spawnlp(os.P_NOWAIT,'ffmpeg','ffmpeg','-deinterlace','-an','-i %s/%s.ts' % (tmp_dir, ip),'-s 400x300','-r 1','-t 00:00:01','-f image2 %s/%s.jpg' % (img_dir, fqdn))
time.sleep(3)
os.kill(pid,9)
if not os.path.exists('%s/%s.jpg' % (img_dir,fqdn)) or not os.stat('%s/%s.jpg' % (img_dir,fqdn))[6] :
shutil.copy('%s/fail.jpg' % (img_dir) , '%s/%s.jpg' % (img_dir,fqdn))
os.kill(pid, 9)
if not os.path.exists('%s/%s.jpg' % (img_dir, fqdn)) or not os.stat('%s/%s.jpg' % (img_dir, fqdn))[6] :
shutil.copy('%s/fail.jpg' % (img_dir) , '%s/%s.jpg' % (img_dir, fqdn))
if os.path.exists('%s/%s_petites.jpg' % (img_dir,fqdn)) :
os.remove('%s/%s_petites.jpg' % (img_dir,fqdn))
os.system('convert -geometry \'200x150 !\' %s/%s.jpg %s/%s_petites.jpg 2>/dev/null 1>/dev/null' % (img_dir,fqdn,img_dir,fqdn))
if os.path.exists('%s/%s_petites.jpg' % (img_dir, fqdn)) :
os.remove('%s/%s_petites.jpg' % (img_dir, fqdn))
os.system('convert -geometry \'200x150 !\' %s/%s.jpg %s/%s_petites.jpg 2>/dev/null 1>/dev/null' % (img_dir, fqdn, img_dir, fqdn))
#On met des symlink pour garder une compatibilité avec les programmes utilisant les adresses ip
if os.path.exists('%s/%s.jpg' % (img_dir,ip)) :
os.remove('%s/%s.jpg' % (img_dir,ip))
if os.path.exists('%s/%s_petites.jpg' % (img_dir,ip)) :
os.remove('%s/%s_petites.jpg' % (img_dir,ip))
os.symlink('%s/%s.jpg' % (img_dir,fqdn),'%s/%s.jpg' % (img_dir,ip))
os.symlink('%s/%s_petites.jpg' % (img_dir,fqdn),'%s/%s_petites.jpg' % (img_dir,ip))
if os.path.exists('%s/%s.jpg' % (img_dir, ip)) :
os.remove('%s/%s.jpg' % (img_dir, ip))
if os.path.exists('%s/%s_petites.jpg' % (img_dir, ip)) :
os.remove('%s/%s_petites.jpg' % (img_dir, ip))
os.symlink('%s/%s.jpg' % (img_dir, fqdn),'%s/%s.jpg' % (img_dir, ip))
os.symlink('%s/%s_petites.jpg' % (img_dir, fqdn),'%s/%s_petites.jpg' % (img_dir, ip))
if os.path.exists('%s/%s.ts' % (tmp_dir,ip)) and os.stat('%s/%s.ts' % (tmp_dir,ip))[6] : #on teste sur le ts car il est enleve a chaque fois
if os.path.exists('%s/%s.ts' % (tmp_dir, ip)) and os.stat('%s/%s.ts' % (tmp_dir, ip))[6] : #on teste sur le ts car il est enleve a chaque fois
if col == 2 :
col = 1
html.write('</tr><tr>\n')
@ -149,18 +149,18 @@ def vignettes() :
html_petites.write('</tr><tr>\n')
else :
col_petites += 1
ajoute_image(nom,fqdn,ip,html,html_petites)
ajoute_image(nom, fqdn, ip, html, html_petites)
print "--------------- Ok %s" % ip
else :
chaines_probleamatiques.append('<b><u>Chaine :</u></b> %s<br><b><u>IP :</u></b> %s:1234<br><br>\n' %(nom,ip))
chaines_probleamatiques.append('<b><u>Chaine :</u></b> %s<br><b><u>IP :</u></b> %s:1234<br><br>\n' %(nom, ip))
print "--------------- Problematique %s ..." % ip
if os.path.exists('%s/%s.jpg' % (img_dir,fqdn)) :
os.remove('%s/%s.jpg' % (img_dir,fqdn))
if os.path.exists('%s/%s_petites.jpg' % (img_dir,fqdn)) :
os.remove('%s/%s_petites.jpg' % (img_dir,fqdn))
if os.path.exists('%s/%s.jpg' % (img_dir, fqdn)) :
os.remove('%s/%s.jpg' % (img_dir, fqdn))
if os.path.exists('%s/%s_petites.jpg' % (img_dir, fqdn)) :
os.remove('%s/%s_petites.jpg' % (img_dir, fqdn))
if os.path.exists('%s/%s.ts' % (tmp_dir,ip)) :
os.remove('%s/%s.ts' % (tmp_dir,ip))
if os.path.exists('%s/%s.ts' % (tmp_dir, ip)) :
os.remove('%s/%s.ts' % (tmp_dir, ip))
html.write(table_piedpage)
html_petites.write(table_piedpage)