Macro Gallery du wiki

darcs-hash:20071209153226-d0547-cb4042d5bacaef59768fd65d3911d814d4b005bc.gz
This commit is contained in:
glondu 2007-12-09 16:32:26 +01:00
parent fe735cf71d
commit f3be755857
2 changed files with 1257 additions and 121 deletions

View file

@ -50,7 +50,7 @@
""" """
__author__ = "Simon D. Ryan" __author__ = "Simon D. Ryan"
__version__ = "0.86" __version__ = "0.87"
from MoinMoin import config, wikiutil from MoinMoin import config, wikiutil
import string, cStringIO, os import string, cStringIO, os
@ -118,7 +118,8 @@ def navibar(target,querystring):
# Returns a navigational bar with PREV,THUMBS,NEXT # Returns a navigational bar with PREV,THUMBS,NEXT
positions=Globs.originals.keys() positions=Globs.originals.keys()
positions.sort() positions.sort()
thumbs='<a href="'+Globs.subname+'">THUMBS</a>' # Append the action to the end of the URLS. This allows us to keep modes such as action=print
thumbs='<a href="'+Globs.subname+'?'+Globs.bcomp+'">THUMBS</a>'
index=positions.index(target) index=positions.index(target)
back,forward='','' back,forward='',''
if not index==0: if not index==0:
@ -133,9 +134,10 @@ def toolbar(target,naillevel):
if Globs.admin: if Globs.admin:
rotateleft='<input type="submit" name="rotate" value="rotate left">' rotateleft='<input type="submit" name="rotate" value="rotate left">'
rotateright='<input type="submit" name="rotate" value="rotate right">' rotateright='<input type="submit" name="rotate" value="rotate right">'
deleteitem='<input type="submit" name="delete" value="delete">'
htarget='<input type=hidden value="'+target+'" name="'+naillevel+'">' htarget='<input type=hidden value="'+target+'" name="'+naillevel+'">'
compat='<input type=hidden value="show" name="action">' compat='<input type=hidden value="show" name="action">'
return '<form METHOD=POST><table><tr><td>'+rotateleft+'</td><td>'+rotateright+'</td></tr></table>\n'+htarget+compat+'</form>' return '<form METHOD=POST><table><tr><td>'+rotateleft+'</td><td>'+rotateright+'</td><td>'+deleteitem+'</td></tr></table>\n'+htarget+compat+'</form>'
else: else:
return '' return ''
@ -250,6 +252,44 @@ def buildnails(items):
open(Globs.attachmentdir+'/delete.me.to.regenerate.thumbnails.and.webnails','w').close() open(Globs.attachmentdir+'/delete.me.to.regenerate.thumbnails.and.webnails','w').close()
def deletefromdisk(target):
# Rotate the images
# Don't go further if there is a lock in place
if os.path.isfile(Globs.attachmentdir+'/tmp.lock'):
message("I'm currently busy generating thumbnails and webnails. Please try your delete request again later.",0)
return ''
# Ok do the actual delete
if 1:
# Delete first the temp dir webnail and thumbnail
try:
os.unlink(Globs.gallerytempdir+'/tmp.webnail.'+target+'.jpg')
except:
pass
try:
os.unlink(Globs.gallerytempdir+'/tmp.thumbnail.'+target+'.jpg')
except:
pass
try:
os.unlink(Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg')
except:
pass
# Now delete the original (except we actually just move it to /tmp)
# TODO: insert a random number in the destination filename to cope with deleting files with same name
origfn=Globs.originals[target]
try:
#shutil.copy(Globs.attachmentdir+'/'+origfn,'/tmp/deleted.'+origfn)
shutil.copy(Globs.attachmentdir+'/'+origfn,'/tmp/'+origfn)
os.unlink(Globs.attachmentdir+'/'+origfn)
except:
pass
try:
#shutil.copy(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','/tmp/deleted.tmp.annotation.'+target+'.txt')
shutil.copy(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','/tmp/tmp.annotation.'+target+'.txt')
os.unlink(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt')
except:
pass
def rotate(target,direction): def rotate(target,direction):
# Rotate the images # Rotate the images
# Don't go further if there is a lock in place # Don't go further if there is a lock in place
@ -278,11 +318,12 @@ def rotate(target,direction):
if not Globs.convertbin == 'Image': if not Globs.convertbin == 'Image':
convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.webnail.'+target+'.jpg"') convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.webnail.'+target+'.jpg"')
convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.thumbnail.'+target+'.jpg"') convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.thumbnail.'+target+'.jpg"')
if not os.path.isfile(Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg'): # Don't bother rotating the original. Since we don't want to reduce its quality incase it is used for printing
# Generate from original #if not os.path.isfile(Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg'):
pathtooriginal=Globs.attachmentdir+'/'+Globs.originals[target] # # Generate from original
shutil.copy(pathtooriginal,Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg') # pathtooriginal=Globs.attachmentdir+'/'+Globs.originals[target]
convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg"') # shutil.copy(pathtooriginal,Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg')
#convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg"')
else: else:
# Use PIL (strip off the "") # Use PIL (strip off the "")
if direction=='rotate right': if direction=='rotate right':
@ -308,7 +349,10 @@ def getannotation(target):
# Annotations are stored as a file for now (later to be stored in images) # Annotations are stored as a file for now (later to be stored in images)
atext='' atext=''
if Globs.annotated.has_key(target): if Globs.annotated.has_key(target):
try:
atext=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt').readline() atext=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt').readline()
except:
atext=''
message('was annotated') message('was annotated')
else: else:
message('was not annotated') message('was not annotated')
@ -405,8 +449,6 @@ def execute(macro, args):
tleft='<table><tr><td><center>' tleft='<table><tr><td><center>'
tmidd='</center></td><td><center>' tmidd='</center></td><td><center>'
trigh='</center></td></tr></table>\n' trigh='</center></td></tr></table>\n'
# Add this to the end of each URL to keep some versions of moinmoin happy
Globs.bcomp='&action=show'
# Process any form items into a dictionary (values become unique) # Process any form items into a dictionary (values become unique)
for item in macro.form.items(): for item in macro.form.items():
@ -418,6 +460,16 @@ def execute(macro, args):
except AttributeError: except AttributeError:
pass pass
# Add this to the end of each URL to keep some versions of moinmoin happy
if formvals.has_key('action'):
if formvals['action']=='content':
# translate content action to print action for now
Globs.bcomp='&action=print'
else:
Globs.bcomp='&action='+formvals['action']
else:
Globs.bcomp='&action=show'
# Figure out if we have delete privs # Figure out if we have delete privs
try: try:
# If a user can delete the page containing the Gallery, then they are considered a Gallery administrator # If a user can delete the page containing the Gallery, then they are considered a Gallery administrator
@ -445,7 +497,11 @@ def execute(macro, args):
for component in spagename: for component in spagename:
compbit=compbit+'/'+component compbit=compbit+'/'+component
try: try:
# The following line stops an exception being raised when trying
# to create a directory that already exists (thanks Magnus Wahrenberg)
if not os.access(Globs.gallerytempdirroot+compbit, os.F_OK):
os.mkdir(Globs.gallerytempdirroot+compbit) os.mkdir(Globs.gallerytempdirroot+compbit)
except: except:
message('Please check permissions on temp dir:'+Globs.gallerytempdirroot,0) message('Please check permissions on temp dir:'+Globs.gallerytempdirroot,0)
return macro.formatter.rawHTML( return macro.formatter.rawHTML(
@ -540,7 +596,6 @@ def execute(macro, args):
target=formvals['target'] target=formvals['target']
# Write an annotation file # Write an annotation file
atext=string.replace(formvals['annotate'],'"','&quot;') atext=string.replace(formvals['annotate'],'"','&quot;')
target=formvals['target']
ouf=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','w') ouf=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','w')
ouf.write(atext) ouf.write(atext)
ouf.close() ouf.close()
@ -556,11 +611,15 @@ def execute(macro, args):
rotend='' rotend=''
if Globs.originals.has_key(target): if Globs.originals.has_key(target):
out.write(navibar(target,'webnail')) out.write(navibar(target,'webnail'))
out.write(toolbar(target,'webnail'))
if formvals.has_key('rotate'): if formvals.has_key('rotate'):
direction=formvals['rotate'] direction=formvals['rotate']
message(direction) message(direction)
rotate(target,direction) rotate(target,direction)
rotend=Globs.galleryrotchar+'rot='+repr(randint(1,10000)) rotend=Globs.galleryrotchar+'rot='+repr(randint(1,10000))
if formvals.has_key('delete'):
message('Deleted <i>'+target+'</i>',0)
deletefromdisk(target)
# Put things in a table # Put things in a table
out.write(tleft) out.write(tleft)
# Lets build up an image tag # Lets build up an image tag
@ -582,7 +641,7 @@ def execute(macro, args):
else: else:
out.write(atext) out.write(atext)
out.write(trigh) out.write(trigh)
out.write(toolbar(target,'webnail')) #out.write(toolbar(target,'webnail'))
else: else:
message('I do not have file: '+target,0) message('I do not have file: '+target,0)

File diff suppressed because it is too large Load diff