[wiki-lenny/local/macro/] Plein de macros qupresque insensibles à la màj
darcs-hash:20081110011032-bd074-27c1be15c497f19d6821115e08356c1f9bda6503.gz
This commit is contained in:
parent
0c660ccda9
commit
d05a08f7a6
9 changed files with 953 additions and 0 deletions
25
wiki-lenny/local/macro/EtatCommutationSecours.py
Normal file
25
wiki-lenny/local/macro/EtatCommutationSecours.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
def Cellule(texte, couleur, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'une cellule formattée aver le formatter f
|
||||||
|
"""
|
||||||
|
code = f.table(1)
|
||||||
|
code += f.table_row(1)
|
||||||
|
code += f.table_cell(1,{'style':'background-color:%s' % couleur })
|
||||||
|
code += f.text(texte)
|
||||||
|
code += f.table_cell(0)
|
||||||
|
code += f.table_row(0)
|
||||||
|
code += f.table(0)
|
||||||
|
return code
|
||||||
|
|
||||||
|
def execute(macro, text) :
|
||||||
|
try :
|
||||||
|
f = open('/usr/scripts/secours/etat_maitre')
|
||||||
|
f.readline()
|
||||||
|
if f.readline().strip() == 'auto' :
|
||||||
|
return "" #Cellule('La commutation automatique de l\'état est activée.','lime',macro.formatter)
|
||||||
|
else :
|
||||||
|
return Cellule(u'La commutation automatique de l\'état a été désactivée.','red',macro.formatter)
|
||||||
|
except :
|
||||||
|
return Cellule(u'Impossible de déterminer le type de commutation.','yellow',macro.formatter)
|
24
wiki-lenny/local/macro/EtatSecours.py
Normal file
24
wiki-lenny/local/macro/EtatSecours.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
|
||||||
|
def Cellule(texte, couleur, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'une cellule formattée aver le formatter f
|
||||||
|
"""
|
||||||
|
code = f.table(1)
|
||||||
|
code += f.table_row(1)
|
||||||
|
code += f.table_cell(1,{'style':'background-color:%s' % couleur })
|
||||||
|
code += f.text(texte)
|
||||||
|
code += f.table_cell(0)
|
||||||
|
code += f.table_row(0)
|
||||||
|
code += f.table(0)
|
||||||
|
return code
|
||||||
|
|
||||||
|
def execute(macro, text) :
|
||||||
|
try :
|
||||||
|
f = open('/usr/scripts/secours/etat_maitre')
|
||||||
|
if f.readline().strip() == 'normal' :
|
||||||
|
return Cellule('Nous sommes actuellement en connexion normale.','lime',macro.formatter)
|
||||||
|
else :
|
||||||
|
return Cellule('Nous sommes actuellement en connexion de secours.','red',macro.formatter)
|
||||||
|
except :
|
||||||
|
return Cellule('Impossible de déterminer l\'état de la connexion.','yellow',macro.formatter)
|
22
wiki-lenny/local/macro/Gravatar.py
Normal file
22
wiki-lenny/local/macro/Gravatar.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
"""
|
||||||
|
MoinMoin - Gravatar Macro
|
||||||
|
Gregoire Detrez, 2007
|
||||||
|
v 0.0.1
|
||||||
|
You can include a gravatar image by using this macro
|
||||||
|
[[Gravatar(name@exemple.com)]]
|
||||||
|
"""
|
||||||
|
|
||||||
|
def execute(macro, text):
|
||||||
|
import md5
|
||||||
|
|
||||||
|
parseargs = text.split(',')
|
||||||
|
if len(parseargs)<2:
|
||||||
|
return '<small><strong class="error">MailTo macro must have at least two arguments</strong></small>'
|
||||||
|
emailname, emailurl= parseargs[:2]
|
||||||
|
email = emailname.strip() + "@" + emailurl.strip()
|
||||||
|
|
||||||
|
user_id = md5.md5( email.strip() ).hexdigest()
|
||||||
|
url = 'http://www.gravatar.com/avatar.php?gravatar_id=%s&size=80' % user_id
|
||||||
|
html = "<img src=\"%s\" alt=\"Gravatar\" />" % url
|
||||||
|
return html
|
173
wiki-lenny/local/macro/ImageLink.py
Normal file
173
wiki-lenny/local/macro/ImageLink.py
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
"""
|
||||||
|
MoinMoin - ImageLink Macro
|
||||||
|
|
||||||
|
PURPOSE:
|
||||||
|
This macro is used to set a link as WikiName for an attached image. Optional the size of the
|
||||||
|
image could be adjusted. If no WikiName is given the attachment is linked to the image itselfs.
|
||||||
|
|
||||||
|
CALLING SEQUENCE:
|
||||||
|
[[ImageLink(attachment|URL,[WikiName|URL],[width=width,[height=heigt]])]]
|
||||||
|
|
||||||
|
INPUTS:
|
||||||
|
attachment:image name of attachment or the URL to an image
|
||||||
|
|
||||||
|
OPTIONAL INPUTS:
|
||||||
|
WikiName: the page to set the link to or the URL to link to
|
||||||
|
|
||||||
|
|
||||||
|
KEYWORD PARAMETERS:
|
||||||
|
width: width of the embedded image
|
||||||
|
height: height of the embedded image
|
||||||
|
|
||||||
|
EXAMPLE:
|
||||||
|
[[ImageLink(plot.png,FrontPage,width=20,height=20)]]
|
||||||
|
[[ImageLink(plot.png,FrontPage,height=20)]]
|
||||||
|
[[ImageLink(plot.png,FrontPage)]]
|
||||||
|
[[ImageLink(plot.png,width=20,height=20)]]
|
||||||
|
[[ImageLink(plot.png,width=20)]]
|
||||||
|
[[ImageLink(plot.png)]]
|
||||||
|
[[ImageLink(http://localhost/wiki/modern/img/to_slide.png,http://localhost/StartSeite,width=50)]]
|
||||||
|
[[ImageLink(http://localhost/wiki/modern/img/to_slide.png,FrontPage,width=50)]]
|
||||||
|
[[ImageLink(plot.png,http://localhost/StartSeite,width=50)]]
|
||||||
|
[[ImageLink(http://localhost/wiki/modern/img/to_slide.png)]]
|
||||||
|
[[ImageLink(http://localhost/wiki/modern/img/to_slide.png,alt=whateveryouwant)]]
|
||||||
|
|
||||||
|
PROCEDURE:
|
||||||
|
This routine requires attachment enabled. If the attachment isn't downloaded at all
|
||||||
|
the attachment line is shown.
|
||||||
|
If you give only one image size argument e.g. width only the other one is calculated
|
||||||
|
|
||||||
|
It must be in "MoinMoin/macro"
|
||||||
|
|
||||||
|
Please remove the version number from the file name!
|
||||||
|
|
||||||
|
From JeffKunce ImageLink.py I have copied _is_URL to this routine. I have no better idea too.
|
||||||
|
|
||||||
|
HISTORY:
|
||||||
|
The first published version on MoinMoin I know of ImageLink was written by JeffKunce in 2001.
|
||||||
|
|
||||||
|
MODIFICATION HISTORY:
|
||||||
|
@copyright: 2004 by Reimar Bauer (R.Bauer@fz-juelich.de)
|
||||||
|
@license: GNU GPL, see COPYING for details.
|
||||||
|
|
||||||
|
Marcin Zalewski:
|
||||||
|
Some things that were causing problems on my wiki are changed
|
||||||
|
(wikiutil.link_tag and macro.formatter.pagelink implemented)
|
||||||
|
|
||||||
|
Marcin Zalewski:
|
||||||
|
Added title attribute to the created link. One could generalize that to
|
||||||
|
add arbitrary attributes.
|
||||||
|
|
||||||
|
One could also add class attributes to <a> and/or
|
||||||
|
<img> elements. I do not see the need for such modifications. If however this is
|
||||||
|
to be done in the future one would need to add 'html_class' key to the kw dictionary
|
||||||
|
with a corresponding value to add class to <img> element. To add class to <a> element
|
||||||
|
one needs to add 'css_class' key with a corresponding value to the dictionary passed to
|
||||||
|
pagelink call.
|
||||||
|
Reimar Bauer:
|
||||||
|
2004-12-23 Adopted to MoinMoin Version 1.3.1-1
|
||||||
|
2004-12-23 SYNTAX CHANGE Version 1.3.1-2
|
||||||
|
width and height and probably other keywords must be called as keywords (e.g. height=20)
|
||||||
|
2004-12-31 Version 1.3.1-3 code clean up
|
||||||
|
2005-01-16 Bug fixed in the errorhandler found and patch code from Malte Helmert
|
||||||
|
2005-03-05 Version 1.3.3-5 Bug fixed found by cypress
|
||||||
|
''If I put [[ImageLink(moinmoin.png)]] it bombs''
|
||||||
|
2005-03-28 Version 1.3.3-6 feature request added by CDPark:
|
||||||
|
''Can we use an external image? And an external target? ''
|
||||||
|
2005-04-16 Version 1.3.3-7 no default alt tag definition requested by CDPark and AlexanderSchremmer
|
||||||
|
Chong-Dae Park:
|
||||||
|
2005-04-17 Version 1.3.3-8 code refactored
|
||||||
|
IMG with no alt tag is not recommended in the HTML standard.
|
||||||
|
It keeps user specified alt tag. If it is not, it tries to use WikiName or image name instead.
|
||||||
|
Reimar Bauer:
|
||||||
|
2005-04-21 Version 1.3.3-9 bug fixed
|
||||||
|
When the image does not exist yet, it gives you a "Upload Image" link, this link does not
|
||||||
|
work. I suspect that this only is a problem on sub-pages, caused by incorrect escaping of
|
||||||
|
"/". -- CraigJohnson
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from MoinMoin.action import AttachFile
|
||||||
|
from MoinMoin import wikiutil, config
|
||||||
|
import os,string
|
||||||
|
|
||||||
|
def _is_URL(aString):
|
||||||
|
'''answer true if aString is a URL.
|
||||||
|
The method used here is pretty dumb. Improvements are welcome.
|
||||||
|
jjk 03/28/01'''
|
||||||
|
return string.find(aString, '://')>0
|
||||||
|
|
||||||
|
|
||||||
|
def execute(macro, text):
|
||||||
|
|
||||||
|
kw ={} # create a dictionary for the formatter.image call
|
||||||
|
|
||||||
|
if text:
|
||||||
|
args=text.split(',')
|
||||||
|
else:
|
||||||
|
args=[]
|
||||||
|
|
||||||
|
number_args=len(args)
|
||||||
|
count=0
|
||||||
|
for a in args :
|
||||||
|
if (a.find('=') > -1):
|
||||||
|
count=count+1
|
||||||
|
key=a.split('=')
|
||||||
|
kw[str(key[0])]=wikiutil.escape(string.join(key[1],''), quote=1)
|
||||||
|
|
||||||
|
number_args=number_args-count
|
||||||
|
|
||||||
|
if (number_args < 1):
|
||||||
|
msg='Not enough arguments to ImageLink macro! Try [[ImageLink(attachment,[WikiName],[width=width,[height=heigt]])]]'
|
||||||
|
return macro.formatter.sysmsg(1)+macro.formatter.text(msg)+ macro.formatter.sysmsg(0)
|
||||||
|
|
||||||
|
|
||||||
|
attname=wikiutil.taintfilename(macro.formatter.text(args[0]))
|
||||||
|
if (number_args >= 2) :
|
||||||
|
wikiname=args[1]
|
||||||
|
current_pagename=macro.formatter.page.page_name
|
||||||
|
|
||||||
|
|
||||||
|
if _is_URL(args[0]):
|
||||||
|
kw['src']=args[0]
|
||||||
|
else:
|
||||||
|
kw['src']=AttachFile.getAttachUrl(current_pagename,attname,macro.request)
|
||||||
|
attachment_path = os.path.join(AttachFile.getAttachDir(macro.request,current_pagename), attname)
|
||||||
|
|
||||||
|
if not os.path.exists(attachment_path):
|
||||||
|
|
||||||
|
import urllib
|
||||||
|
linktext = macro.request.getText('Upload new attachment "%(filename)s"'%{
|
||||||
|
"filename":attname})
|
||||||
|
|
||||||
|
return wikiutil.link_tag(macro.request,
|
||||||
|
"%(pagename)s?action=AttachFile&rename=%(newname)s" % {
|
||||||
|
"pagename":current_pagename,
|
||||||
|
"newname": attname},linktext)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if not kw.has_key('alt'):
|
||||||
|
if (number_args == 1) or _is_URL(args[1]):
|
||||||
|
if _is_URL(args[0]):
|
||||||
|
# Get image name http://here.com/dir/image.gif -> image.gif
|
||||||
|
kw['alt'] = wikiutil.taintfilename(macro.formatter.text(args[0].split('/')[-1]))
|
||||||
|
kw['alt'] = args[0].split('/')[-1]
|
||||||
|
else:
|
||||||
|
kw['alt'] = attname
|
||||||
|
else:
|
||||||
|
kw['alt'] = wikiname
|
||||||
|
|
||||||
|
if (number_args == 1):
|
||||||
|
image_link=macro.formatter.image(**kw)
|
||||||
|
return macro.formatter.url(1,kw['src'] )+image_link +macro.formatter.url(0)
|
||||||
|
|
||||||
|
if (number_args == 2 ):
|
||||||
|
image_link=macro.formatter.image(**kw)
|
||||||
|
if _is_URL(args[1]):
|
||||||
|
return macro.formatter.url(1,args[1] )+image_link+macro.formatter.url(0)
|
||||||
|
else:
|
||||||
|
return macro.formatter.pagelink(1,wikiname)+image_link+macro.formatter.url(0)
|
||||||
|
|
89
wiki-lenny/local/macro/InfosBornes.py
Executable file
89
wiki-lenny/local/macro/InfosBornes.py
Executable file
|
@ -0,0 +1,89 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- encoding: iso-8859-1 -*-
|
||||||
|
|
||||||
|
# Génération d'un fichier XML indiquant le status des bornes
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import time, urllib2
|
||||||
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
def execute(macro, text):
|
||||||
|
f=macro.formatter
|
||||||
|
|
||||||
|
# ouverture du fichier d'info et parsage
|
||||||
|
try:
|
||||||
|
#os.putenv("http_proxy", "http://proxy.crans.org:3128")
|
||||||
|
status=xml.dom.minidom.parseString(urllib2.urlopen("https://wifi.crans.org/status.xml").read())
|
||||||
|
except:
|
||||||
|
return f.text(u"Impossible d'accéder aux informations des bornes")
|
||||||
|
|
||||||
|
# On récupère l'ensemble des bornes
|
||||||
|
bornes = status.childNodes[0]
|
||||||
|
code = f.text(u"Mise à jour le "+bornes.getAttribute("date"))
|
||||||
|
code += f.linebreak(0)
|
||||||
|
|
||||||
|
code += f.table(True, {'tablealign': 'center'})
|
||||||
|
|
||||||
|
code += f.table_row(True, {'rowbgcolor': '#FFFFA0'})
|
||||||
|
for nom_col in (u"Nom", u"Hotspot", u"État", u"Localisation", u"Clients",
|
||||||
|
u"MAC", u"Canal", u"Uptime", u"°E", u"°N"):
|
||||||
|
code += f.table_cell(True)
|
||||||
|
code += f.strong(True)
|
||||||
|
code += f.text(nom_col)
|
||||||
|
code += f.strong(False)
|
||||||
|
code += f.table_cell(False)
|
||||||
|
code += f.table_row(False)
|
||||||
|
|
||||||
|
|
||||||
|
bornes.childNodes.sort(lambda x, y: cmp(x.getAttribute(u"nom"),
|
||||||
|
y.getAttribute(u"nom")))
|
||||||
|
|
||||||
|
dico = {u"hotspot": {u"1": f.smiley('(./)'), u"0": f.text(u"")},
|
||||||
|
u"up": {u"1": f.smiley(u"(!)"), u"0": f.smiley(u"{X}")}}
|
||||||
|
|
||||||
|
for b in bornes.childNodes:
|
||||||
|
code += f.table_row(1)
|
||||||
|
|
||||||
|
code += f.table_cell(1)
|
||||||
|
code += f.text(b.getAttribute(u"nom"))
|
||||||
|
code += f.table_cell(0)
|
||||||
|
|
||||||
|
|
||||||
|
for nom_attribut in (u"hotspot", u"up"):
|
||||||
|
code += f.table_cell(1)
|
||||||
|
code += dico[nom_attribut][b.getAttribute(nom_attribut)]
|
||||||
|
code += f.table_cell(0)
|
||||||
|
|
||||||
|
for tag in [u'description', u"clients",u"mac",u"canal"]:
|
||||||
|
code += f.table_cell(1)
|
||||||
|
if (b.getElementsByTagName(tag)!=[]):
|
||||||
|
code += f.text(b.getElementsByTagName(tag)[0].firstChild.data)
|
||||||
|
else:
|
||||||
|
code += f.text(u"")
|
||||||
|
code += f.table_cell(0)
|
||||||
|
|
||||||
|
code += f.table_cell(1)
|
||||||
|
if (b.getElementsByTagName(u"uptime")!=[]):
|
||||||
|
code += f.text("%.2f" % float(b.getElementsByTagName(u"uptime")[0].firstChild.data)+" j")
|
||||||
|
else:
|
||||||
|
code += f.text(u"")
|
||||||
|
code += f.table_cell(0)
|
||||||
|
|
||||||
|
if (b.getElementsByTagName(u"position")!=[]):
|
||||||
|
for nom_attribut in [u'x',u'y']:
|
||||||
|
code += f.table_cell(1)
|
||||||
|
code += f.text(b.getElementsByTagName(u"position")[0].getAttribute(nom_attribut))
|
||||||
|
code += f.table_cell(0)
|
||||||
|
else:
|
||||||
|
code += f.table_cell(1)
|
||||||
|
code += f.text(u"")
|
||||||
|
code += f.table_cell(0)
|
||||||
|
code += f.table_cell(1)
|
||||||
|
code += f.text(u"")
|
||||||
|
code += f.table_cell(0)
|
||||||
|
|
||||||
|
code += f.table_row(0)
|
||||||
|
|
||||||
|
code += f.table(0)
|
||||||
|
return code
|
275
wiki-lenny/local/macro/MonitStatus.py
Normal file
275
wiki-lenny/local/macro/MonitStatus.py
Normal file
|
@ -0,0 +1,275 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
|
||||||
|
import os, sys, sre, commands, time
|
||||||
|
|
||||||
|
"""
|
||||||
|
Permet d'intégrer au wiki les résultats de Monit.
|
||||||
|
|
||||||
|
La macro wiki est :
|
||||||
|
[[MonitStatus(hotes=host,categories=[All|Process|File],services=[All|Off|On])]]
|
||||||
|
|
||||||
|
Exemple :
|
||||||
|
[[MonitStatus(All|Off|service@host)
|
||||||
|
"""
|
||||||
|
|
||||||
|
statusfolder = '/usr/scripts/monit/status'
|
||||||
|
|
||||||
|
def NotRunningHosts() :
|
||||||
|
"""
|
||||||
|
Retourne la liste des hotes ou Monit ne tourne pas ou que
|
||||||
|
le fichier de status est trop vieux
|
||||||
|
"""
|
||||||
|
hosts = []
|
||||||
|
for host in os.listdir(statusfolder) :
|
||||||
|
if os.path.getmtime('/usr/scripts/monit/status/%s' % host) < time.time() - 240 :
|
||||||
|
hosts.append(host)
|
||||||
|
return hosts
|
||||||
|
|
||||||
|
def HostStatus (host) :
|
||||||
|
"""
|
||||||
|
Retourne un dictionnaire représentation de l'état des services de
|
||||||
|
la machine.
|
||||||
|
"""
|
||||||
|
|
||||||
|
status = {}
|
||||||
|
|
||||||
|
f = open('%s/%s' % (statusfolder,host) )
|
||||||
|
|
||||||
|
# c'est un hote sous Debian
|
||||||
|
###########################
|
||||||
|
|
||||||
|
# s est le service qu'on est en trainde parser
|
||||||
|
s = None
|
||||||
|
for line in f.readlines()[2:] :
|
||||||
|
line = line.strip()
|
||||||
|
if not line :
|
||||||
|
# ligne vide, on passe au service suivant
|
||||||
|
s = None
|
||||||
|
elif not s :
|
||||||
|
# création d'un nouveau service
|
||||||
|
s = line.split(' ')[1][1:-1]
|
||||||
|
t = line.split(' ')[0]
|
||||||
|
# ajout du type s'il n'est pas dedans
|
||||||
|
if not status.has_key(t) :
|
||||||
|
status[t] = {}
|
||||||
|
status[t][s] = {}
|
||||||
|
else :
|
||||||
|
# on ajoute les données
|
||||||
|
status[t][s][line[:34].strip()] = line[34:].strip()
|
||||||
|
|
||||||
|
# on supprime les données system
|
||||||
|
try :
|
||||||
|
status.pop('System')
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
|
||||||
|
return status
|
||||||
|
|
||||||
|
def AllStatus () :
|
||||||
|
"""
|
||||||
|
Retourne la configuration de toutes les machines
|
||||||
|
"""
|
||||||
|
status = {}
|
||||||
|
for host in os.listdir(statusfolder) :
|
||||||
|
status[host] = HostStatus(host)
|
||||||
|
return status
|
||||||
|
|
||||||
|
def AllStatusOff () :
|
||||||
|
"""
|
||||||
|
Retourne status avec juste les services off
|
||||||
|
"""
|
||||||
|
|
||||||
|
status = AllStatus()
|
||||||
|
|
||||||
|
for h in status.keys() :
|
||||||
|
|
||||||
|
# si c'est un host qui est down, on le laisse tel quel pour éviter qu'il le supprime
|
||||||
|
if h in NotRunningHosts() :
|
||||||
|
continue
|
||||||
|
|
||||||
|
# on supprime les types
|
||||||
|
for t in status[h].keys() :
|
||||||
|
|
||||||
|
for s in status[h][t].keys() :
|
||||||
|
|
||||||
|
# on supprime un status s'il est Up
|
||||||
|
if status[h][t][s]['status'] in ['running','accessible'] :
|
||||||
|
status[h][t].pop(s)
|
||||||
|
|
||||||
|
# reste-t-il des services dans le groupe
|
||||||
|
if not status[h][t] :
|
||||||
|
status[h].pop(t)
|
||||||
|
|
||||||
|
# reste-t-il des groupes dans l'hote
|
||||||
|
if not status[h] :
|
||||||
|
status.pop(h)
|
||||||
|
|
||||||
|
return status
|
||||||
|
|
||||||
|
def FormatService(Type, Service, Data, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'un sercice
|
||||||
|
Type : type de service
|
||||||
|
Service : Nom du service
|
||||||
|
Data : dictionnaire contenant toutes les données Data[info]
|
||||||
|
f : formatter
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
result += f.table_row(1)
|
||||||
|
result += f.table_cell(1,{'style':'background-color:silver'})
|
||||||
|
if Type == 'Device' :
|
||||||
|
Service = Service[2:]
|
||||||
|
elif Type == 'File' :
|
||||||
|
Service = Service[4:]
|
||||||
|
result += f.strong(1)
|
||||||
|
result += f.text(Service)
|
||||||
|
result += f.strong(0)
|
||||||
|
result += f.table_cell(0)
|
||||||
|
if Data['status'] in ['running','accessible'] :
|
||||||
|
result += f.table_cell(1,{'style':'background-color:lime'})
|
||||||
|
else :
|
||||||
|
result += f.table_cell(1,{'style':'background-color:red'})
|
||||||
|
result += f.text(Data['status'])
|
||||||
|
result += f.table_cell(0)
|
||||||
|
result += f.table_row(0)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def FormatType(Type, Data, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'une liste de services
|
||||||
|
Host : nom de l'hote
|
||||||
|
Data : dictionnaire contenant toutes les données Data[service][info]
|
||||||
|
f : formatter
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
# titre
|
||||||
|
result += f.heading(1,3)
|
||||||
|
result += f.text(Type)
|
||||||
|
result += f.heading(0,3)
|
||||||
|
|
||||||
|
# les services
|
||||||
|
result += f.table(1)
|
||||||
|
for s in Data.keys() :
|
||||||
|
result += FormatService(Type,s,Data[s],f)
|
||||||
|
result += f.table(0)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def FormatHost (Host, Data, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'un hôte
|
||||||
|
Host : nom de l'hote
|
||||||
|
Data : dictionnaire contenant toutes les données Data[type][service][info]
|
||||||
|
f : formatter
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
# titre
|
||||||
|
result += f.heading(1,2)
|
||||||
|
result += f.text(Host)[0].upper() + f.text(Host)[1:]
|
||||||
|
result += f.heading(0,2)
|
||||||
|
|
||||||
|
# si monit ne tourne pas
|
||||||
|
if Host in NotRunningHosts() :
|
||||||
|
return result + Cellule('Monit ne semble pas tourner sur %s' % Host,'yellow',f)
|
||||||
|
|
||||||
|
result += f.table(1)
|
||||||
|
result += f.table_row(1)
|
||||||
|
for t in Data.keys() :
|
||||||
|
result += f.table_cell(1,{'valign':'top'})
|
||||||
|
result += FormatType(t,Data[t],f)
|
||||||
|
result += f.table_cell(0)
|
||||||
|
|
||||||
|
result += f.table_row(0)
|
||||||
|
result += f.table(0)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def FormatHosts(Data, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML de tous les hotes fournis
|
||||||
|
Data : dictionnaire contenant toutes les données Data[hote][type][service][info]
|
||||||
|
f : formatter
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
for h in Data.keys() :
|
||||||
|
result += FormatHost(h,Data[h],f)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def Cellule(texte, couleur, f) :
|
||||||
|
"""
|
||||||
|
Retourne le code HTML d'une cellule formattée aver le formatter f
|
||||||
|
"""
|
||||||
|
code = f.table(1)
|
||||||
|
code += f.table_row(1)
|
||||||
|
code += f.table_cell(1,{'style':'background-color:%s' % couleur })
|
||||||
|
code += f.text(texte)
|
||||||
|
code += f.table_cell(0)
|
||||||
|
code += f.table_row(0)
|
||||||
|
code += f.table(0)
|
||||||
|
return code
|
||||||
|
|
||||||
|
def execute(macro, filtre) :
|
||||||
|
"""
|
||||||
|
Corps principal de la macro
|
||||||
|
"""
|
||||||
|
f = macro.formatter
|
||||||
|
|
||||||
|
# on met en forme le filtre
|
||||||
|
if not filtre :
|
||||||
|
filtre = 'all'
|
||||||
|
else :
|
||||||
|
filtre = filtre.lower()
|
||||||
|
|
||||||
|
if filtre == 'off' :
|
||||||
|
# tous les services off
|
||||||
|
status = AllStatusOff()
|
||||||
|
if status :
|
||||||
|
return FormatHosts(status, f)
|
||||||
|
else :
|
||||||
|
# aucun service off, on affiche OK
|
||||||
|
return Cellule(u'Tous les services semblent opérationnels.','lime',f)
|
||||||
|
|
||||||
|
elif filtre == 'all' :
|
||||||
|
# tous les services
|
||||||
|
status = AllStatus()
|
||||||
|
return FormatHosts(status, f)
|
||||||
|
|
||||||
|
elif '@' in filtre :
|
||||||
|
# affichage d'un service simple
|
||||||
|
|
||||||
|
host = filtre.split('@')[1]
|
||||||
|
service = filtre.split('@')[0]
|
||||||
|
status = HostStatus(host)
|
||||||
|
|
||||||
|
# recherche du service dans la config
|
||||||
|
s = {}
|
||||||
|
for t in status.keys() :
|
||||||
|
if service in status[t].keys() :
|
||||||
|
s = status[t][service]
|
||||||
|
|
||||||
|
if not s :
|
||||||
|
# service non trouvé
|
||||||
|
code = f.table_cell(0)
|
||||||
|
code += f.table_cell(1,{'style':'background-color:yellow'})
|
||||||
|
code += f.text(u'Service introuvable')
|
||||||
|
return code
|
||||||
|
|
||||||
|
# création de la chaine de retour
|
||||||
|
code = f.table_cell(0)
|
||||||
|
if s['status'] in ['running','accessible'] :
|
||||||
|
code += f.table_cell(1,{'style':'background-color:lime'})
|
||||||
|
else :
|
||||||
|
code += f.table_cell(1,{'style':'background-color:red'})
|
||||||
|
code += f.text(s['status'])
|
||||||
|
return code
|
||||||
|
|
||||||
|
else :
|
||||||
|
return Cellule('Erreur de filtre','yellow',f)
|
225
wiki-lenny/local/macro/ProgressBar.py
Normal file
225
wiki-lenny/local/macro/ProgressBar.py
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
"""
|
||||||
|
MoinMoin - ProgressBar Macro
|
||||||
|
Generates a progress bar (in the form of a table)
|
||||||
|
|
||||||
|
@copyright: Pascal Bauermeister <pascal DOT bauermeister AT gmail DOT cm>
|
||||||
|
@license: GPL
|
||||||
|
|
||||||
|
Updates:
|
||||||
|
|
||||||
|
* [v0.1.1] Sun Dec 18 21:31:17 CET 2005
|
||||||
|
Changed table cell percentage markup.
|
||||||
|
|
||||||
|
* [v0.1.0] Fri Dec 16 22:30:10 CET 2005
|
||||||
|
Original version
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The ProgressBar macro generates a table showing a progress indicator.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
[[ ProgressBar ]]
|
||||||
|
[[ ProgressBar (TABLEWIDTH TABLEFORMAT PROGRESS%) ]]
|
||||||
|
[[ ProgressBar (TABLEWIDTH TABLEFORMAT CURRENT/STEPS) ]]
|
||||||
|
[[ ProgressBar (TABLEWIDTH TABLEFORMAT STARTDATE,ENDDATE) ]]
|
||||||
|
|
||||||
|
If no arguments are given, the usage is inserted in the HTML result.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
TABLEWIDTH (optional prefix)
|
||||||
|
A wiki tablewidth attribute value between []'s
|
||||||
|
Examples:
|
||||||
|
[100%]
|
||||||
|
[80px]
|
||||||
|
|
||||||
|
TABLEFORMAT (optional prefix)
|
||||||
|
A pair of wiki table attribute, to format the inactive and active cells.
|
||||||
|
Examples:
|
||||||
|
<bgcolor="black"><bgcolor="white"> # black on white bar
|
||||||
|
<tablewidth="90%" bgcolor="black"><bgcolor="white"> # same, 90% table
|
||||||
|
|
||||||
|
A third format may be given for STARTDATE,ENDDATE usage
|
||||||
|
|
||||||
|
By default: <tablewidth="100px"#808080><><#8080ff>
|
||||||
|
|
||||||
|
PROGRESS
|
||||||
|
Will display a table with two cells:
|
||||||
|
- left: completion, taking PROGRESS % of the table width
|
||||||
|
- right: remaining
|
||||||
|
|
||||||
|
CURRENT/STEPS
|
||||||
|
Will display a table with STEPS cells, CURRENT of which are active.
|
||||||
|
|
||||||
|
STARTDATE,ENDDATE
|
||||||
|
Will display a table with the number of days, with the cell
|
||||||
|
representing today in active format and background in inactive format.
|
||||||
|
|
||||||
|
If today is before STARTDATE, the left-most cell will be in the
|
||||||
|
3rd format. If today is after ENDDATE the rightmost cell will be
|
||||||
|
in the 3rd format.
|
||||||
|
|
||||||
|
Dates are in this format: YYYY-MM-DD
|
||||||
|
|
||||||
|
Debugging
|
||||||
|
Please prepend a '?' to the arguments.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
[[ProgressBar(60%)]]
|
||||||
|
[[ProgressBar(6/10)]]
|
||||||
|
[[ProgressBar(2005-11-01,2006-01-06)]]
|
||||||
|
|
||||||
|
[[ProgressBar([50%] 60%)]]
|
||||||
|
[[ProgressBar([50px] 60%)]]
|
||||||
|
[[ProgressBar([90%]<#8080ff><#808080> 6/10)]]
|
||||||
|
----
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
import time, re, StringIO
|
||||||
|
from MoinMoin import version
|
||||||
|
from MoinMoin.parser import text_moin_wiki as wiki
|
||||||
|
|
||||||
|
Dependencies = ["time"] # macro cannot be cached
|
||||||
|
|
||||||
|
|
||||||
|
class _Error (Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def escape (str):
|
||||||
|
return str.replace ('&','&').replace ('<', '<').replace ('>', '>')
|
||||||
|
|
||||||
|
def usage (full = False):
|
||||||
|
|
||||||
|
"""Returns the interesting part of the module's doc"""
|
||||||
|
|
||||||
|
if full:
|
||||||
|
return __doc__
|
||||||
|
else:
|
||||||
|
rx = re.compile ("--$(.*)^--", re.DOTALL + re.MULTILINE)
|
||||||
|
return rx.findall (__doc__) [0].strip ()
|
||||||
|
|
||||||
|
|
||||||
|
def s2t (s):
|
||||||
|
return time.mktime (time.strptime (s, "%Y-%m-%d"))
|
||||||
|
|
||||||
|
|
||||||
|
def execute (macro, text, args_re=None):
|
||||||
|
|
||||||
|
try: res = _execute (macro, text)
|
||||||
|
except Exception, msg:
|
||||||
|
return """
|
||||||
|
<p><strong class="error">
|
||||||
|
Error: macro ProgressBar: %s</strong> </p>
|
||||||
|
""" % escape ("%s" % msg)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def _execute (macro, text):
|
||||||
|
|
||||||
|
fmt = ['#808080','','#8080ff']
|
||||||
|
width ="100px"
|
||||||
|
res = ""
|
||||||
|
text = text.strip ()
|
||||||
|
|
||||||
|
# help if empty text
|
||||||
|
help = len (text) == 0
|
||||||
|
|
||||||
|
# debug if starts with '?'
|
||||||
|
if text.startswith ('?'):
|
||||||
|
debug = True
|
||||||
|
text = text [1:]
|
||||||
|
else:
|
||||||
|
debug = False
|
||||||
|
orig_text = text
|
||||||
|
|
||||||
|
# Formats
|
||||||
|
try:
|
||||||
|
# Table width
|
||||||
|
if text.startswith ('['):
|
||||||
|
pos = text.rfind (']')
|
||||||
|
width = text [1:pos]
|
||||||
|
text = text [pos+1:].strip ()
|
||||||
|
|
||||||
|
# Cells format
|
||||||
|
if text.startswith ('<'):
|
||||||
|
pos = text.rfind ('>')
|
||||||
|
f = text [1:pos].split ('><')
|
||||||
|
text = text [pos+1:].strip ()
|
||||||
|
fmt [:len (f)] = f
|
||||||
|
except:
|
||||||
|
help = True
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
if help:
|
||||||
|
return """
|
||||||
|
<p>
|
||||||
|
<pre>%s</pre></p>
|
||||||
|
""" % escape (usage (0))
|
||||||
|
|
||||||
|
# Cell formatting utility
|
||||||
|
def cell (txt, fmt):
|
||||||
|
if len (txt) == 0:
|
||||||
|
fmt = 'tablewidth="%s" ' % width + fmt
|
||||||
|
txt = "||"
|
||||||
|
if len (fmt): t = "<%s> ||" % fmt
|
||||||
|
else: t = " ||"
|
||||||
|
return txt + t
|
||||||
|
|
||||||
|
# Progress
|
||||||
|
if text.endswith ('%'):
|
||||||
|
# correction du bug des 0%
|
||||||
|
if text == "0%":
|
||||||
|
for f in [fmt [1]] :
|
||||||
|
res = cell (res, f)
|
||||||
|
else:
|
||||||
|
for f in fmt [0] + ' %s' % text, fmt [1] :
|
||||||
|
res = cell (res, f)
|
||||||
|
|
||||||
|
# Current/Steps
|
||||||
|
elif text.find ('/') > 0:
|
||||||
|
cur, steps = map (int, text.split ('/'))
|
||||||
|
for i in range (steps):
|
||||||
|
res = cell (res, fmt [i>=cur])
|
||||||
|
|
||||||
|
# Start/end date
|
||||||
|
else:
|
||||||
|
starts, ends = map (lambda s:s.strip (), text.split (","))
|
||||||
|
start, end = s2t (starts), s2t (ends)
|
||||||
|
now = time.mktime (time.localtime ())
|
||||||
|
|
||||||
|
duration = int ( (end-start) / 86400)
|
||||||
|
progress = int ( (now-start) / 86400) -1
|
||||||
|
pcent = int (90 / duration)
|
||||||
|
|
||||||
|
for i in range (duration):
|
||||||
|
if i == 0 and progress < 0:
|
||||||
|
f = fmt [2]
|
||||||
|
elif i == progress:
|
||||||
|
f = fmt [0]
|
||||||
|
else:
|
||||||
|
f = fmt [1]
|
||||||
|
res = cell (res, f)
|
||||||
|
|
||||||
|
if progress >= duration:
|
||||||
|
res = cell (res, fmt [2])
|
||||||
|
else:
|
||||||
|
res = cell (res, fmt [1])
|
||||||
|
|
||||||
|
# Output
|
||||||
|
if debug:
|
||||||
|
res = "{{{[[ProgressBar(%s)]]\n%s}}}\n%s" % (orig_text, res, res)
|
||||||
|
return _format (res, macro.request, macro.formatter)
|
||||||
|
|
||||||
|
|
||||||
|
def _format (src_text, request, formatter):
|
||||||
|
# parse the text (in wiki source format) and make HTML,
|
||||||
|
# after diverting sys.stdout to a string
|
||||||
|
str_out = StringIO.StringIO () # create str to collect output
|
||||||
|
request.redirect (str_out) # divert output to that string
|
||||||
|
# parse this line
|
||||||
|
wiki.Parser (src_text, request).format (formatter)
|
||||||
|
request.redirect () # restore output
|
||||||
|
return str_out.getvalue () # return what was generated
|
93
wiki-lenny/local/macro/TV.py
Normal file
93
wiki-lenny/local/macro/TV.py
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
Dependencies = ["Time"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SAP_FILE_URL = "http://tv/sap.txt"
|
||||||
|
BASE_IMAGE_URL = "http://tv/images/"
|
||||||
|
IMAGE_SUFFIX = ".jpg"
|
||||||
|
SMALL_IMAGE_SUFFIX = "_petites.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
def image_url_for_channel(channel_name, channel_ip, small=0 ):
|
||||||
|
if small:
|
||||||
|
return BASE_IMAGE_URL + str(channel_ip) + IMAGE_SUFFIX
|
||||||
|
else:
|
||||||
|
return BASE_IMAGE_URL + str(channel_ip) + SMALL_IMAGE_SUFFIX
|
||||||
|
|
||||||
|
def get_channel_list():
|
||||||
|
import urllib
|
||||||
|
# Getsap file from web sever.
|
||||||
|
f = urllib.urlopen(SAP_FILE_URL)
|
||||||
|
# Read it.
|
||||||
|
s = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
s = s.split("\n")
|
||||||
|
|
||||||
|
channel_list = []
|
||||||
|
for a_line in s:
|
||||||
|
try:
|
||||||
|
ch_name, ch_ip = a_line.split(":")
|
||||||
|
url = "udp://@%s:1234" % ch_ip
|
||||||
|
d = {
|
||||||
|
"name": ch_name,
|
||||||
|
"url": url,
|
||||||
|
"image_url": image_url_for_channel( ch_name, ch_ip ),
|
||||||
|
"small_image_url": image_url_for_channel( ch_name, ch_ip, small=1 ),
|
||||||
|
}
|
||||||
|
channel_list.append(d)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return channel_list
|
||||||
|
|
||||||
|
|
||||||
|
def execute(macro, args):
|
||||||
|
opt = {"col":4,"cat":False,"ch":False, "width":"10em"}
|
||||||
|
# parse args
|
||||||
|
if args:
|
||||||
|
try:
|
||||||
|
for name, value in [(x.split("=")[0].strip(), x.split("=")[1].strip()) for x in args.split(",")]:
|
||||||
|
opt[name] = value
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
IMAGES_PER_LINE = int(opt["col"])
|
||||||
|
CATHEGORY = opt["cat"]
|
||||||
|
CHANNEL = opt["ch"]
|
||||||
|
IMAGE_WIDTH = opt["width"]
|
||||||
|
# display all channel
|
||||||
|
ch_list = get_channel_list()
|
||||||
|
text = macro.formatter.table(1,{})
|
||||||
|
i = 0
|
||||||
|
for a_channel in ch_list:
|
||||||
|
if CATHEGORY:
|
||||||
|
if not a_channel["name"].startswith(CATHEGORY):
|
||||||
|
continue
|
||||||
|
if CHANNEL:
|
||||||
|
if a_channel["name"].find(CHANNEL)<0:
|
||||||
|
continue
|
||||||
|
if i == 0:
|
||||||
|
text+= macro.formatter.table_row(1)
|
||||||
|
text+= macro.formatter.table_cell(1, {'style':'text-align:center;'})
|
||||||
|
text+= macro.formatter.strong( 1 )
|
||||||
|
text+= macro.formatter.text( a_channel["name"] )
|
||||||
|
text+= macro.formatter.strong( 0 )
|
||||||
|
text+= macro.formatter.linebreak( 0 )
|
||||||
|
#text+= macro.formatter.url(1, href=a_channel["url"], style="text-decoration:none;")
|
||||||
|
text+= macro.formatter.url(1, url=a_channel["url"], style="text-decoration:none;")
|
||||||
|
text+= macro.formatter.image( src=a_channel["image_url"], alt="No image", style="width:%s;" % IMAGE_WIDTH )
|
||||||
|
text+= macro.formatter.linebreak( 0 )
|
||||||
|
text+= macro.formatter.text( "Regarder maintenant" )
|
||||||
|
text+= macro.formatter.url(0)
|
||||||
|
text+= macro.formatter.table_cell(0)
|
||||||
|
if i == IMAGES_PER_LINE - 1:
|
||||||
|
text+= macro.formatter.table_row(0)
|
||||||
|
i = (i + 1) % IMAGES_PER_LINE
|
||||||
|
while i != 0 and i < IMAGES_PER_LINE:
|
||||||
|
text+= macro.formatter.table_cell(1)
|
||||||
|
text+= macro.formatter.table_cell(0)
|
||||||
|
i += 1
|
||||||
|
text+= macro.formatter.table(0)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
27
wiki-lenny/local/macro/YouTube.py
Normal file
27
wiki-lenny/local/macro/YouTube.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
"""
|
||||||
|
MoinMoin - YouTube Macro
|
||||||
|
Jesus L. Alvaro 2006
|
||||||
|
v 0.0.2
|
||||||
|
You can include YouTube videos in the wiki by using this macro:
|
||||||
|
[[YouTube(V8tSRJ8e3b0)]] or
|
||||||
|
[[YouTube(http://www.youtube.com/v/V8tSRJ8e3b0)]]
|
||||||
|
visit "http://www.iesvaldebernardo.es/w/Post/2006-11-30-1447/YouTube_en_la_Wiki."
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def execute(macro, text):
|
||||||
|
if text.find('http://')> -1:
|
||||||
|
try:
|
||||||
|
text = text.split('v=')[1]
|
||||||
|
except:
|
||||||
|
return u"URL non valide..."
|
||||||
|
url = 'http://www.youtube.com/v/%s' % text
|
||||||
|
html = u'''
|
||||||
|
<object width="425" height="350">
|
||||||
|
<param name="movie" value="%(youtubelink)s"></param>
|
||||||
|
<param name="wmode" value="transparent"></param>
|
||||||
|
<embed src="%(youtubelink)s" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
|
||||||
|
</object>
|
||||||
|
''' % {"youtubelink": url}
|
||||||
|
return html
|
Loading…
Add table
Add a link
Reference in a new issue