[wiki-etch] suppression
darcs-hash:20090304160004-bd074-7e2630d385522d14ea3ad6a52ad0669b2ddc1b2e.gz
This commit is contained in:
parent
4a1c67a459
commit
aa5e8cdc52
67 changed files with 0 additions and 15442 deletions
|
@ -1,119 +0,0 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
"""
|
||||
MoinMoin - Portail parser
|
||||
|
||||
PURPOSE:
|
||||
une boite jolie
|
||||
|
||||
CALLING SEQUENCE:
|
||||
{{{
|
||||
#!Box titre
|
||||
blablabla
|
||||
|
||||
tables, images....
|
||||
}}}
|
||||
|
||||
"""
|
||||
from MoinMoin.parser import wiki
|
||||
import os,string,re,StringIO
|
||||
from MoinMoin.action import AttachFile
|
||||
|
||||
color_list = ['orange', 'black', 'red', 'green', 'blue', 'gray']
|
||||
|
||||
|
||||
#####################################################################
|
||||
# Fonctions #
|
||||
#####################################################################
|
||||
# to_wikiname : transfome la chaine text avec le parser wiki
|
||||
# classique et le formateur formatter
|
||||
# (je sais pas a quoi sert request, mais faut pas
|
||||
# l'enlever !)
|
||||
#######
|
||||
|
||||
def to_wikiname(request,formatter,text):
|
||||
##taken from MiniPage
|
||||
out=StringIO.StringIO()
|
||||
request.redirect(out)
|
||||
wikiizer = wiki.Parser(text,request)
|
||||
wikiizer.format(formatter)
|
||||
result=out.getvalue()
|
||||
request.redirect()
|
||||
del out
|
||||
|
||||
return result.strip()
|
||||
|
||||
#####################################################################
|
||||
# BoxFormatter : creer le code html
|
||||
#######
|
||||
class BoxFormatter:
|
||||
|
||||
def __init__(self, request, formatter):
|
||||
self.formatter = formatter
|
||||
self.request = request
|
||||
self.counter = 0
|
||||
def make(self, title, body_html, color=None):
|
||||
if color==None:
|
||||
css_color_class=u""
|
||||
else:
|
||||
css_color_class = u" %s_box" % color
|
||||
html = [
|
||||
self.formatter.rawHTML(u'<div class="sidebox%s">' % css_color_class),
|
||||
self.formatter.rawHTML(u'<div class="boxhead">'),
|
||||
self.formatter.heading(1,3),
|
||||
title,
|
||||
self.formatter.heading(0,3),
|
||||
self.formatter.rawHTML(u'</div>'),
|
||||
self.formatter.rawHTML(u'<div class="boxbody1">'),
|
||||
self.formatter.rawHTML(u'<div class="boxbody2">'),
|
||||
body_html,
|
||||
self.formatter.rawHTML(u'</div>'),
|
||||
self.formatter.rawHTML(u'</div>'),
|
||||
self.formatter.rawHTML(u'</div>'),
|
||||
]
|
||||
self.request.write(u'\n'.join(html))
|
||||
|
||||
#####################################################################
|
||||
# Parser : classe principale, c'est elle qui parse
|
||||
#######
|
||||
class Parser:
|
||||
|
||||
def __init__(self, raw, request, **kw):
|
||||
self.request = request
|
||||
self.raw = raw
|
||||
self.settings={'title': u'|'.join([u" ".join(kw.keys()), u" ".join(kw.values())])}
|
||||
self.settings = self.parseArgs(kw["format_args"])
|
||||
|
||||
def getRandomColor(self):
|
||||
nb_of_colors = color_list.__len__()
|
||||
from random import randint
|
||||
colorNum = randint(0, nb_of_colors - 1)
|
||||
return color_list[colorNum]
|
||||
|
||||
def parseArgs(self, argsString):
|
||||
argList = argsString.split(u',')
|
||||
settings = {}
|
||||
for anArg in argList:
|
||||
anArg = anArg.strip(u' ')
|
||||
if anArg.find(u'color=')!=-1:
|
||||
theColor = anArg.split(u'=')[1].lower()
|
||||
if theColor == 'random':
|
||||
theColor = self.getRandomColor()
|
||||
settings['color'] = theColor
|
||||
else:
|
||||
settings['title'] = anArg
|
||||
return settings
|
||||
|
||||
def format(self, formatter):
|
||||
quotes = self.raw
|
||||
|
||||
# on utilise la classe qui va fabriquer le code html
|
||||
boite = BoxFormatter(self.request, formatter)
|
||||
title = self.settings['title']
|
||||
content = to_wikiname(self.request, formatter, quotes)
|
||||
try:
|
||||
color = self.settings['color']
|
||||
except:
|
||||
color=None
|
||||
boite.make(title, content, color)
|
||||
return
|
||||
|
1197
wiki/parser/EXIF.py
1197
wiki/parser/EXIF.py
File diff suppressed because it is too large
Load diff
|
@ -1,134 +0,0 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
..
|
||||
.... ............ ........
|
||||
. ....... . .... ..
|
||||
. ... .. .. .. .. ..... . ..
|
||||
.. .. ....@@@. .. . ........ .
|
||||
.. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. ....
|
||||
.@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... ....
|
||||
@@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. ..
|
||||
.@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. .....
|
||||
...@@@.... @@@ .@@.......... ........ ..... ..
|
||||
. ..@@@@.. . .@@@@. .. ....... . .............
|
||||
. .. .... .. .. . ... ....
|
||||
. . .... ............. .. ...
|
||||
.. .. ... ........ ... ...
|
||||
................................
|
||||
|
||||
MoinMoin - Portail parser
|
||||
|
||||
PURPOSE:
|
||||
Pour afficher un portail a la wikipedia.
|
||||
|
||||
CALLING SEQUENCE:
|
||||
{{{
|
||||
#!Portail
|
||||
image1.png @@ title1 @@ description 1
|
||||
image2.png @@ title2 @@ description 2
|
||||
image3.png @@ title3 @@ description 3
|
||||
}}}
|
||||
|
||||
CREDIT
|
||||
Le code est derive de celui de Gallery2.
|
||||
|
||||
"""
|
||||
from MoinMoin.parser import wiki
|
||||
import os,string,re,StringIO
|
||||
from MoinMoin.action import AttachFile
|
||||
|
||||
#####################################################################
|
||||
# Fonctions #
|
||||
#####################################################################
|
||||
# to_wikiname : transfome la chaine text avec le parser wiki
|
||||
# classique et le formateur formatter
|
||||
# (je sais pas a quoi sert request, mais faut pas
|
||||
# l'enlever !)
|
||||
#######
|
||||
|
||||
def to_wikiname(request,formatter,text):
|
||||
##taken from MiniPage
|
||||
out=StringIO.StringIO()
|
||||
request.redirect(out)
|
||||
wikiizer = wiki.Parser(text.strip(),request)
|
||||
wikiizer.format(formatter)
|
||||
result=out.getvalue()
|
||||
request.redirect()
|
||||
del out
|
||||
|
||||
return result.strip()
|
||||
|
||||
#####################################################################
|
||||
# PortailFormatter : creer le code html du portail a l'aide de
|
||||
# de formatter et l'envoie a request
|
||||
#######
|
||||
class PortailFormatter:
|
||||
|
||||
def __init__(self, request, formatter):
|
||||
self.formatter = formatter
|
||||
self.request = request
|
||||
self.counter = 0
|
||||
|
||||
def open(self):
|
||||
self.request.write(self.formatter.table(1,{'style':'width:100%;padding:10px;'}))
|
||||
|
||||
def cell(self, title, description, image):
|
||||
if self.counter==0:
|
||||
self.request.write(self.formatter.table_row(1))
|
||||
self.request.write(self.formatter.table_cell(1,{'style':'width:50%;border:none;padding:20px 20px 20px 50px;background:transparent url(\'' + image.replace("\'","\\\'") + '\') center left no-repeat; vertical-align:middle;'}))
|
||||
self.request.write(title)
|
||||
self.request.write(description)
|
||||
self.request.write(self.formatter.table_cell(0))
|
||||
if self.counter==1:
|
||||
self.request.write(self.formatter.table_row(0))
|
||||
self.counter = (self.counter + 1)%2
|
||||
|
||||
def close(self):
|
||||
if self.counter==1:
|
||||
self.request.write(self.formatter.table_cell(1,{'style':'width:50%;border:none;padding:20px 20px 20px 50px;'}))
|
||||
self.request.write(self.formatter.table_cell(0))
|
||||
self.request.write(self.formatter.table_row(0))
|
||||
self.request.write(self.formatter.table(0))
|
||||
|
||||
#####################################################################
|
||||
# Parser : classe principale, c'est elle qui parse
|
||||
#######
|
||||
class Parser:
|
||||
|
||||
def __init__(self, raw, request, **kw):
|
||||
self.request = request
|
||||
self.raw = raw
|
||||
return
|
||||
|
||||
|
||||
def format(self, formatter):
|
||||
|
||||
# on divise le textes en lignes (1 ligne = une entree dans le portail)
|
||||
quotes = self.raw.split('\n')
|
||||
|
||||
# on récupere le chemin des fichiers attaches pour les images
|
||||
current_pagename=formatter.page.page_name
|
||||
attachment_path = AttachFile.getAttachDir(self.request, current_pagename, create=1)
|
||||
|
||||
# on initialise la classe qui va fabriquer le code html
|
||||
portail = PortailFormatter(self.request, formatter)
|
||||
portail.open()
|
||||
|
||||
# on traite les ligne une à une
|
||||
for line in quotes:
|
||||
line=line.strip()
|
||||
items=line.split('@@',2)
|
||||
if items.__len__()<3:
|
||||
self.request.write('<!-- error, wrong number of parameters -->')
|
||||
else:
|
||||
description=items.pop().strip()
|
||||
link=items.pop().strip()
|
||||
image = AttachFile.getAttachUrl(current_pagename, items.pop().strip(), self.request).replace('& ','&')
|
||||
|
||||
link = to_wikiname(self.request, formatter, link)
|
||||
description = to_wikiname(self.request, formatter, description)
|
||||
portail.cell(link, description, image)
|
||||
portail.close()
|
||||
|
||||
return
|
|
@ -1,5 +0,0 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
|
||||
from MoinMoin.util import pysupport
|
||||
|
||||
modules = pysupport.getPackageModules(__file__)
|
|
@ -1,214 +0,0 @@
|
|||
#FORMAT python
|
||||
#!/usr/bin/python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
"""
|
||||
New latex formatter using dvipng and tempfile
|
||||
|
||||
Author: JohannesBerg <johannes@sipsolutions.net>
|
||||
|
||||
This parser (and the corresponding macro) was tested with Python 2.3.4 and
|
||||
* Debian Linux with out-of-the-box tetex-bin and dvipng packages installed
|
||||
* Windows XP (not by me)
|
||||
|
||||
In the parser, you can add stuff to the prologue by writing
|
||||
%%end-prologue%%
|
||||
somewhere in the document, before that write stuff like \\usepackage and after it put
|
||||
the actual latex display code.
|
||||
"""
|
||||
|
||||
Dependencies = []
|
||||
|
||||
import sha, os, tempfile, shutil, re
|
||||
from MoinMoin.action import AttachFile
|
||||
from MoinMoin.Page import Page
|
||||
|
||||
latex_template = r'''
|
||||
\documentclass[12pt]{article}
|
||||
\pagestyle{empty}
|
||||
%(prologue)s
|
||||
\begin{document}
|
||||
%(raw)s
|
||||
\end{document}
|
||||
'''
|
||||
|
||||
max_pages = 10
|
||||
MAX_RUN_TIME = 5 # seconds
|
||||
|
||||
latex = "latex" # edit full path here, e.g. reslimit = "C:\\path\\to\\latex.exe"
|
||||
dvipng = "dvipng" # edit full path here (or reslimit = r'C:\path\to\latex.exe')
|
||||
|
||||
# last arg must have %s in it!
|
||||
latex_args = ("--interaction=nonstopmode", "%s.tex")
|
||||
|
||||
# last arg must have %s in it!
|
||||
dvipng_args = ("-bgTransparent", "-Ttight", "--noghostscript", "-l%s" % max_pages, "%s.dvi")
|
||||
|
||||
# this is formatted with hexdigest(texcode),
|
||||
# page number and extension are appended by
|
||||
# the tools
|
||||
latex_name_template = "latex_%s_p"
|
||||
|
||||
# keep this up-to-date, also with max_pages!!
|
||||
latex_attachment = re.compile((latex_name_template+'%s%s') % (r'[0-9a-fA-F]{40}', r'[0-9]{1,2}', r'\.png'))
|
||||
|
||||
anchor = re.compile(r'^%%anchor:[ ]*([a-zA-Z0-9_-]+)$', re.MULTILINE | re.IGNORECASE)
|
||||
# the anchor re must start with a % sign to be ignored by latex as a comment!
|
||||
end_prologue = '%%end-prologue%%'
|
||||
|
||||
def call_command_in_dir_NT(app, args, targetdir):
|
||||
reslimit = "runlimit.exe" # edit full path here
|
||||
os.environ['openin_any'] = 'p'
|
||||
os.environ['openout_any'] = 'p'
|
||||
os.environ['shell_escape'] = 'f'
|
||||
stdouterr = os.popen('%s %d "%s" %s %s < NUL' % (reslimit, MAX_RUN_TIME, targetdir, app, ' '.join(args)), 'r')
|
||||
output = ''.join(stdouterr.readlines())
|
||||
err = stdouterr.close()
|
||||
if not err is None:
|
||||
return ' error! exitcode was %d, transscript follows:\n\n%s' % (err,output)
|
||||
return None
|
||||
|
||||
def call_command_in_dir_unix(app, args, targetdir):
|
||||
# this is the unix implementation
|
||||
(r,w) = os.pipe()
|
||||
pid = os.fork()
|
||||
if pid == -1:
|
||||
return 'could not fork'
|
||||
if pid == 0:
|
||||
# child
|
||||
os.close(r)
|
||||
os.dup2(os.open("/dev/null", os.O_WRONLY), 0)
|
||||
os.dup2(w, 1)
|
||||
os.dup2(w, 2)
|
||||
os.chdir(targetdir)
|
||||
os.environ['openin_any'] = 'p'
|
||||
os.environ['openout_any'] = 'p'
|
||||
os.environ['shell_escape'] = 'f'
|
||||
import resource
|
||||
resource.setrlimit(resource.RLIMIT_CPU,
|
||||
(MAX_RUN_TIME * 1000, MAX_RUN_TIME * 1000)) # docs say this is seconds, but it is msecs on my system.
|
||||
os.execvp(app, [app] + list(args))
|
||||
print "failed to exec()",app
|
||||
os._exit(2)
|
||||
else:
|
||||
# parent
|
||||
os.close(w)
|
||||
r = os.fdopen(r,"r")
|
||||
output = ''.join(r.readlines())
|
||||
(npid, exi) = os.waitpid(pid, 0)
|
||||
r.close()
|
||||
sig = exi & 0xFF
|
||||
stat = exi >> 8
|
||||
if stat != 0 or sig != 0:
|
||||
return ' error! exitcode was %d (signal %d), transscript follows:\n\n%s' % (stat,sig,output)
|
||||
return None
|
||||
# notreached
|
||||
|
||||
if os.name == 'nt':
|
||||
call_command_in_dir = call_command_in_dir_NT
|
||||
else:
|
||||
call_command_in_dir = call_command_in_dir_unix
|
||||
|
||||
|
||||
class Parser:
|
||||
extensions = ['.tex']
|
||||
def __init__ (self, raw, request, **kw):
|
||||
self.raw = raw
|
||||
if len(self.raw)>0 and self.raw[0] == '#':
|
||||
self.raw[0] = '%'
|
||||
self.request = request
|
||||
self.exclude = []
|
||||
if not hasattr(request, "latex_cleanup_done"):
|
||||
request.latex_cleanup_done = {}
|
||||
|
||||
def cleanup(self, pagename):
|
||||
attachdir = AttachFile.getAttachDir(self.request, pagename, create=1)
|
||||
for f in os.listdir(attachdir):
|
||||
if not latex_attachment.match(f) is None:
|
||||
os.remove("%s/%s" % (attachdir, f))
|
||||
|
||||
def _internal_format(self, formatter, text):
|
||||
tmp = text.split(end_prologue, 1)
|
||||
if len(tmp) == 2:
|
||||
prologue,tex=tmp
|
||||
else:
|
||||
prologue = ''
|
||||
tex = tmp[0]
|
||||
if callable(getattr(formatter, 'johill_sidecall_emit_latex', None)):
|
||||
return formatter.johill_sidecall_emit_latex(tex)
|
||||
return self.get(formatter, tex, prologue, True)
|
||||
|
||||
def format(self, formatter):
|
||||
self.request.write(self._internal_format(formatter, self.raw))
|
||||
|
||||
def get(self, formatter, inputtex, prologue, para=False):
|
||||
if not self.request.latex_cleanup_done.has_key(formatter.page.page_name):
|
||||
self.request.latex_cleanup_done[formatter.page.page_name] = True
|
||||
self.cleanup(formatter.page.page_name)
|
||||
|
||||
if len(inputtex) == 0: return ''
|
||||
|
||||
if callable(getattr(formatter, 'johill_sidecall_emit_latex', None)):
|
||||
return formatter.johill_sidecall_emit_latex(inputtex)
|
||||
|
||||
extra_preamble = ''
|
||||
preamble_page = self.request.pragma.get('latex_preamble', None)
|
||||
if preamble_page is not None:
|
||||
extra_preamble = Page(self.request, preamble_page).get_raw_body()
|
||||
extra_preamble = re.sub(re.compile('^#'), '%', extra_preamble)
|
||||
|
||||
tex = latex_template % { 'raw': inputtex, 'prologue': extra_preamble + prologue }
|
||||
enctex = tex.encode('utf-8')
|
||||
fn = latex_name_template % sha.new(enctex).hexdigest()
|
||||
|
||||
attachdir = AttachFile.getAttachDir(self.request, formatter.page.page_name, create=1)
|
||||
dst = "%s/%s%%d.png" % (attachdir, fn)
|
||||
if not os.access(dst % 1, os.R_OK):
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
try:
|
||||
data = open("%s/%s.tex" % (tmpdir, fn), "w")
|
||||
data.write(enctex)
|
||||
data.close()
|
||||
args = list(latex_args)
|
||||
args[-1] = args[-1] % fn
|
||||
res = call_command_in_dir(latex, args, tmpdir)
|
||||
if not res is None:
|
||||
return formatter.preformatted(1)+formatter.text('latex'+res)+formatter.preformatted(0)
|
||||
args = list(dvipng_args)
|
||||
args[-1] = args[-1] % fn
|
||||
res = call_command_in_dir(dvipng, args, tmpdir)
|
||||
if not res is None:
|
||||
return formatter.preformatted(1)+formatter.text('dvipng'+res)+formatter.preformatted(0)
|
||||
|
||||
page = 1
|
||||
while os.access("%s/%s%d.png" % (tmpdir, fn, page), os.R_OK):
|
||||
shutil.copyfile ("%s/%s%d.png" % (tmpdir, fn, page), dst % page)
|
||||
page += 1
|
||||
|
||||
finally:
|
||||
for root,dirs,files in os.walk(tmpdir, topdown=False):
|
||||
for name in files:
|
||||
os.remove(os.path.join(root,name))
|
||||
for name in dirs:
|
||||
os.rmdir(os.path.join(root,name))
|
||||
os.rmdir(tmpdir)
|
||||
|
||||
result = ""
|
||||
page = 1
|
||||
loop = False
|
||||
for match in anchor.finditer(inputtex):
|
||||
result += formatter.anchordef(match.group(1))
|
||||
for match in anchor.finditer(prologue):
|
||||
result += formatter.anchordef(match.group(1))
|
||||
while os.access(dst % page, os.R_OK):
|
||||
url = AttachFile.getAttachUrl(formatter.page.page_name, fn+"%d.png" % page, self.request)
|
||||
if loop:
|
||||
result += formatter.linebreak(0)+formatter.linebreak(0)
|
||||
if para:
|
||||
result += formatter.paragraph(1)
|
||||
result += formatter.image(src="%s" % url, alt=inputtex, title=inputtex, align="absmiddle")
|
||||
if para:
|
||||
result += formatter.paragraph(0)
|
||||
page += 1
|
||||
loop = True
|
||||
return result
|
Loading…
Add table
Add a link
Reference in a new issue