Attachment 'DataLanguage.py'
Download 1 """
2 MoinMoin - Processor for idl (www.rsinc.com) compatible languages
3
4 INSTALL: create a user without a password e.g. idl_user
5 set the rights of su only callable from users of the su group
6 the httpd user account normally wwwrun must be in this group.
7
8 config_dl_vartmp_dir must be writable for this user.
9
10 Check the rights of this user to prevent corruption of your system.
11
12
13 @copyright: 2004-04-10 by R.Bauer
14 code logic taken from latex.py (Won-kyu Park <wkpark@kldp.org>, Benny Siegert, R.Bauer)
15
16 @license: GNU GPL, see COPYING for details.
17
18 """
19
20 Dependencies = []
21
22 import sys, os, re, sha
23 from MoinMoin.Page import Page
24 from MoinMoin.action import AttachFile
25
26 config_external_language='idl'
27 config_external_dl = "/usr/local/bin/"+config_external_language
28 config_external_convert = "/usr/bin/convert"
29
30 config_umask = 022
31
32 config_dl_cache_dir = "./data"
33 config_dl_cache_url = "./data"
34 config_dl_header = ""
35 config_dl_vartmp_dir = "./data/tmp"
36 config_dl_image_type = 'jpg'
37 # normally I prefer png, but at the moment my standalone wiki server has
38 # some problems to show them perfect.
39
40 config_dl_user ="idl_user"
41
42 def process(request, formatter, lines):
43 if not config_dl_cache_dir:
44 return
45 if lines[0].strip() == "#!DataLanguage":
46 del lines[0]
47
48 texstr = '\n'.join(lines).strip()
49
50 imgname = re.sub('\s+', ' ', texstr)
51 imgname = sha.new(imgname).hexdigest()
52
53 attdir = config_dl_cache_dir + "/"+config_external_language+"/attachments"
54 atturl = config_dl_cache_url + "/"+config_external_language+"/attachments"
55 outpath = "%s/%s.%s" % (attdir, imgname,config_dl_image_type)
56 outurl = "%s/%s.%s" % (atturl, imgname,config_dl_image_type)
57 if not os.path.isdir(attdir):
58 os.makedirs(attdir, 0775)
59
60 pagename=formatter.page.page_name
61
62 url=AttachFile.getAttachUrl(pagename,imgname+'.'+config_dl_image_type,request)
63 attach_dir=AttachFile.getAttachDir(pagename,create=1)
64
65
66
67 if not os.path.isfile(attach_dir+'/'+imgname+'.'+config_dl_image_type):
68 if not os.path.exists(outpath):
69 vartmp = config_dl_vartmp_dir
70
71 data = open("%s/%s.pro" % (vartmp, imgname), "w")
72 data.write("%s\n set_plot,'ps'\n device,file='%s'\n%s\n device,/close\n exit" %(
73 config_dl_header, imgname+'.ps',texstr))
74 data.close()
75
76
77
78 cmd = "cd %(vartmp)s;%(dl)s %(options)s %(pro)s ;exit >/dev/null" % {
79 "dl": config_external_dl,
80 "vartmp": vartmp,
81 "options": '<',
82 "pro": imgname+'.pro'
83 }
84 #request.write(cmd)
85 data = open("%s/%s.sh" % (vartmp, imgname), "w")
86 data.write(cmd)
87 data.close()
88
89 cmd = "su %(dl_user)s %(vartmp)s/%(imgname)s" % {
90 "dl_user": config_dl_user,
91 "vartmp":vartmp,
92 "imgname":imgname+".sh"
93 }
94 #request.write(cmd)
95
96 os.umask(config_umask)
97 os.system(cmd)
98
99 os.system("%(convert)s -rotate 90 -crop 0x0 -density 72x72 %(vartmp)s/%(imgname)s.ps %(outpath)s" % {
100 "convert": config_external_convert,
101 "vartmp": vartmp,
102 "outpath": attach_dir+'/'+imgname+'.'+config_dl_image_type,
103 "imgname": imgname,
104 })
105
106 os.system("rm -f %(vartmp)s/%(imgname)s.*" % {
107 "vartmp": vartmp,
108 "imgname": imgname,
109 })
110
111 request.write(formatter.image(src="%s" % url, alt=texstr, align='absmiddle'))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.