y[[./tv/vignettes/vignettes.py] Style
darcs-hash:20090304122722-8fbb1-46d46804cd7de7cd89b88053fbda15127dec0cd3.gz
This commit is contained in:
parent
b4ce95f3fa
commit
4a1c67a459
1 changed files with 44 additions and 44 deletions
|
@ -1,18 +1,18 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: iso-8859-15 -*-
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
import os,sys,socket,shutil
|
import os, sys, socket, shutil
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
import lock
|
import lock
|
||||||
import time
|
import time
|
||||||
from time import localtime,sleep
|
from time import localtime, sleep
|
||||||
|
|
||||||
tmp_dir = '/tmp'
|
tmp_dir = '/tmp'
|
||||||
www_dir = '/var/www/'
|
www_dir = '/var/www/'
|
||||||
img_dir = '%s/images' % www_dir
|
img_dir = '%s/images' % www_dir
|
||||||
|
|
||||||
t = localtime()
|
t = localtime()
|
||||||
trame_entete="""
|
trame_entete = """
|
||||||
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
|
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
|
||||||
<html lang=\"fr\">
|
<html lang=\"fr\">
|
||||||
<head>
|
<head>
|
||||||
|
@ -32,17 +32,17 @@ trame_entete="""
|
||||||
<a href=vignettes.html>Vignettes Normales</a><br>
|
<a href=vignettes.html>Vignettes Normales</a><br>
|
||||||
<table cellpading=25 cellspacing=25>
|
<table cellpading=25 cellspacing=25>
|
||||||
<tr>
|
<tr>
|
||||||
""" % (int(t[3]) ,int(t[4]) )
|
""" % (int(t[3]), int(t[4]) )
|
||||||
|
|
||||||
table_piedpage="""</tr>
|
table_piedpage = """</tr>
|
||||||
</table>
|
</table>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
trame_piedpage="""</body>
|
trame_piedpage = """</body>
|
||||||
</html>
|
</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('<td align="center">')
|
||||||
html.write('<img src="images/%s.jpg" alt="Chaine : %s / IP : %s"><br>' % (fqdn, nom, ip))
|
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))
|
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 = 0
|
||||||
col_petites = 0
|
col_petites = 0
|
||||||
#a factoriser
|
#a factoriser
|
||||||
chaines_probleamatiques=[]
|
chaines_probleamatiques = []
|
||||||
os.system('/usr/scripts/tv/recup_sap')
|
os.system('/usr/scripts/tv/recup_sap')
|
||||||
#On est obligé de mettre en dur le path
|
#On est obligé de mettre en dur le path
|
||||||
#car il n'est pas configurable dans recup_sap
|
#car il n'est pas configurable dans recup_sap
|
||||||
|
@ -76,28 +76,28 @@ def vignettes() :
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
nom = line.split(':')[0]
|
nom = line.split(':')[0]
|
||||||
ip = line.split(':')[-1]
|
ip = line.split(':')[-1]
|
||||||
print '%s %s' %(str(ip),str(nom))
|
print '%s %s' % (str(ip), str(nom))
|
||||||
try :
|
try :
|
||||||
fqdn = socket.gethostbyaddr(ip)[0]
|
fqdn = socket.gethostbyaddr(ip)[0]
|
||||||
except gai.error, err :
|
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
|
continue
|
||||||
except :
|
except :
|
||||||
print 'Erreur inconnue'
|
print 'Erreur inconnue'
|
||||||
continue
|
continue
|
||||||
else :
|
else :
|
||||||
#on évite les radios, peu de debit et pas de vignettes
|
#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
|
#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
|
print "On s'occupe de la radio %s" % nom_court
|
||||||
for file in os.listdir('%s /logos_radios' % img_dir):
|
for file in os.listdir('%s /logos_radios' % img_dir):
|
||||||
try :
|
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.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_petites.jpg' % (img_dir, fqdn))
|
||||||
except :
|
except :
|
||||||
#il n'y a pas de logo :-(
|
#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
|
continue
|
||||||
else :
|
else :
|
||||||
if col == 2 :
|
if col == 2 :
|
||||||
|
@ -110,35 +110,35 @@ def vignettes() :
|
||||||
html_petites.write('</tr><tr>\n')
|
html_petites.write('</tr><tr>\n')
|
||||||
else :
|
else :
|
||||||
col_petites += 1
|
col_petites += 1
|
||||||
ajoute_image(nom,fqdn,ip,html,html_petites)
|
ajoute_image(nom, fqdn, ip, html, html_petites)
|
||||||
print 'on s\'occupe de %s %s' % (ip,nom)
|
print 'on s\'occupe de %s %s' % (ip, nom)
|
||||||
print '\trecuperation du flux'
|
print '\trecuperation du flux'
|
||||||
#ip port duree
|
#ip port duree
|
||||||
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts 2>/dev/null' % (ip,tmp_dir,ip))
|
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))
|
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)
|
time.sleep(3)
|
||||||
os.kill(pid,9)
|
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] :
|
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'
|
print '\tOn retente'
|
||||||
os.system('/usr/scripts/tv/dumpudp %s 1234 2 > %s/%s.ts ' % (ip,tmp_dir,ip))
|
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))
|
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)
|
time.sleep(3)
|
||||||
os.kill(pid,9)
|
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] :
|
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))
|
shutil.copy('%s/fail.jpg' % (img_dir) , '%s/%s.jpg' % (img_dir, fqdn))
|
||||||
|
|
||||||
if os.path.exists('%s/%s_petites.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.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))
|
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
|
#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)) :
|
if os.path.exists('%s/%s.jpg' % (img_dir, ip)) :
|
||||||
os.remove('%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)) :
|
if os.path.exists('%s/%s_petites.jpg' % (img_dir, ip)) :
|
||||||
os.remove('%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.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))
|
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 :
|
if col == 2 :
|
||||||
col = 1
|
col = 1
|
||||||
html.write('</tr><tr>\n')
|
html.write('</tr><tr>\n')
|
||||||
|
@ -149,18 +149,18 @@ def vignettes() :
|
||||||
html_petites.write('</tr><tr>\n')
|
html_petites.write('</tr><tr>\n')
|
||||||
else :
|
else :
|
||||||
col_petites += 1
|
col_petites += 1
|
||||||
ajoute_image(nom,fqdn,ip,html,html_petites)
|
ajoute_image(nom, fqdn, ip, html, html_petites)
|
||||||
print "--------------- Ok %s" % ip
|
print "--------------- Ok %s" % ip
|
||||||
else :
|
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
|
print "--------------- Problematique %s ..." % ip
|
||||||
if os.path.exists('%s/%s.jpg' % (img_dir,fqdn)) :
|
if os.path.exists('%s/%s.jpg' % (img_dir, fqdn)) :
|
||||||
os.remove('%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)) :
|
if os.path.exists('%s/%s_petites.jpg' % (img_dir, fqdn)) :
|
||||||
os.remove('%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)) :
|
if os.path.exists('%s/%s.ts' % (tmp_dir, ip)) :
|
||||||
os.remove('%s/%s.ts' % (tmp_dir,ip))
|
os.remove('%s/%s.ts' % (tmp_dir, ip))
|
||||||
|
|
||||||
html.write(table_piedpage)
|
html.write(table_piedpage)
|
||||||
html_petites.write(table_piedpage)
|
html_petites.write(table_piedpage)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue