Attachment 'gallery2image-1.3.3-2.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - gallery2Image Actionmacro
4
5 PURPOSE:
6 This action macro is used to rotate the images from Gallery2
7
8 CALLING SEQUENCE:
9 called by Gallery2 POST Method
10
11 PROCEDURE:
12 see Gallery2
13
14 Please remove the version number from this file
15
16 RESTRICTIONS:
17 spaces in file names are not supported. I don't know how to escape them right.
18
19 MODIFICATION HISTORY:
20 Version 1.3.3.-1
21 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
22 @license: GNU GPL, see COPYING for details.
23 2005-06-24: 1.3.3.-2 feature reqeust of CraigJohnson added
24 os.path.join used to join platform independent pathes
25 os.unlink removed to get it more platform independend
26
27
28 """
29
30 import os,string,Image
31 from MoinMoin import config, wikiutil
32 from MoinMoin.PageEditor import PageEditor
33 from MoinMoin import user, util
34 from MoinMoin.Page import Page
35 from MoinMoin.action import AttachFile
36
37
38 action_name = __name__.split('.')[-1]
39
40 def execute(pagename, request):
41 """ Main dispatcher for the 'Gallery' action.
42 """
43 _ = request.getText
44
45 if(request.form['do'][0] == 'PS'):
46 images=string.split(request.form['target'][0],',')
47 attachment_path = AttachFile.getAttachDir(request,pagename)
48 # for img in images:
49 # infile=attachment_path+'/'+img
50 # im = Image.open(infile)
51 # src=im.tostring()
52
53 msg= _('not finished by now')
54
55 elif request.user.may.delete(pagename):
56 # only users which are allowed to delete should use this tool
57
58 target=request.form['target'][0]
59 file, ext = os.path.splitext(target)
60
61 if (ext == '.gif') or (ext == '.png'):
62 img_type='PNG'
63 thumbfile='thumbnail_'+file+".png"
64 webnail='webnail_'+file+".png"
65 else:
66 img_type="JPEG"
67 thumbfile='thumbnail_'+file+".jpg"
68 webnail='webnail_'+file+".jpg"
69
70
71 attachment_path = AttachFile.getAttachDir(request,pagename)
72 thumb=os.path.join(attachment_path,thumbfile)
73 webf=os.path.join(attachment_path,webnail)
74 infile=os.path.join(attachment_path,target)
75
76 msg = None
77 if action_name in request.cfg.excluded_actions:
78 msg = _('File attachments are not allowed in this wiki!')
79
80 elif (request.form['do'][0] == 'RM'):
81 if os.path.exists(infile+'.bak'):
82 os.unlink(infile+'.bak')
83 os.link(infile,infile+'.bak')
84 os.unlink(infile)
85 os.unlink(webf)
86 os.unlink(thumb)
87
88 msg= _('%(target)s deleted, backup in place' % {
89 'target':target})
90
91 elif (request.form['do'][0] == 'RL'):
92 im = Image.open(infile)
93 #os.unlink(infile)
94 im.rotate(90).save(infile,img_type)
95 nim = Image.open(infile)
96 nim.thumbnail((640,640), Image.ANTIALIAS)
97 #os.unlink(webf)
98 nim.save(webf, img_type)
99 nim.thumbnail((128, 128), Image.ANTIALIAS)
100 #os.unlink(thumb)
101 nim.save(thumb, img_type)
102 msg= _('%(target)s rotated to left 90 degrees' % {
103 'target':target})
104
105 elif (request.form['do'][0] == 'RR'):
106 im = Image.open(infile)
107 #os.unlink(infile)
108 im.rotate(270).save(infile,img_type)
109
110
111 nim = Image.open(infile)
112
113 nim.thumbnail((640,640), Image.ANTIALIAS)
114 #os.unlink(webf)
115 nim.save(webf, img_type)
116 nim.thumbnail((128, 128), Image.ANTIALIAS)
117 #os.unlink(thumb)
118 nim.save(thumb, img_type)
119 msg= _('%(target)s rotated to right 90 degrees' % {
120 'target':target})
121
122 else:
123 msg = _('action not implemented: %s') % (request.form['do'][0],)
124 else:
125 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
126
127 if msg:
128 AttachFile.error_msg(pagename, request, msg)
129
130 return()
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.