Macro Gallery du wiki
darcs-hash:20071209153226-d0547-cb4042d5bacaef59768fd65d3911d814d4b005bc.gz
This commit is contained in:
parent
fe735cf71d
commit
f3be755857
2 changed files with 1257 additions and 121 deletions
|
@ -50,7 +50,7 @@
|
|||
"""
|
||||
|
||||
__author__ = "Simon D. Ryan"
|
||||
__version__ = "0.86"
|
||||
__version__ = "0.87"
|
||||
|
||||
from MoinMoin import config, wikiutil
|
||||
import string, cStringIO, os
|
||||
|
@ -118,7 +118,8 @@ def navibar(target,querystring):
|
|||
# Returns a navigational bar with PREV,THUMBS,NEXT
|
||||
positions=Globs.originals.keys()
|
||||
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)
|
||||
back,forward='',''
|
||||
if not index==0:
|
||||
|
@ -133,9 +134,10 @@ def toolbar(target,naillevel):
|
|||
if Globs.admin:
|
||||
rotateleft='<input type="submit" name="rotate" value="rotate left">'
|
||||
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+'">'
|
||||
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:
|
||||
return ''
|
||||
|
||||
|
@ -250,6 +252,44 @@ def buildnails(items):
|
|||
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):
|
||||
# Rotate the images
|
||||
# Don't go further if there is a lock in place
|
||||
|
@ -278,11 +318,12 @@ def rotate(target,direction):
|
|||
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.thumbnail.'+target+'.jpg"')
|
||||
if not os.path.isfile(Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg'):
|
||||
# Generate from original
|
||||
pathtooriginal=Globs.attachmentdir+'/'+Globs.originals[target]
|
||||
shutil.copy(pathtooriginal,Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg')
|
||||
convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+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
|
||||
#if not os.path.isfile(Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg'):
|
||||
# # Generate from original
|
||||
# pathtooriginal=Globs.attachmentdir+'/'+Globs.originals[target]
|
||||
# shutil.copy(pathtooriginal,Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg')
|
||||
#convout=commands.getoutput(Globs.convertbin+' -rotate '+degs+' "'+Globs.gallerytempdir+'/tmp.rotated.'+target+'.jpg"')
|
||||
else:
|
||||
# Use PIL (strip off the "")
|
||||
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)
|
||||
atext=''
|
||||
if Globs.annotated.has_key(target):
|
||||
try:
|
||||
atext=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt').readline()
|
||||
except:
|
||||
atext=''
|
||||
message('was annotated')
|
||||
else:
|
||||
message('was not annotated')
|
||||
|
@ -405,8 +449,6 @@ def execute(macro, args):
|
|||
tleft='<table><tr><td><center>'
|
||||
tmidd='</center></td><td><center>'
|
||||
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)
|
||||
for item in macro.form.items():
|
||||
|
@ -418,6 +460,16 @@ def execute(macro, args):
|
|||
except AttributeError:
|
||||
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
|
||||
try:
|
||||
# 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:
|
||||
compbit=compbit+'/'+component
|
||||
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)
|
||||
|
||||
except:
|
||||
message('Please check permissions on temp dir:'+Globs.gallerytempdirroot,0)
|
||||
return macro.formatter.rawHTML(
|
||||
|
@ -540,7 +596,6 @@ def execute(macro, args):
|
|||
target=formvals['target']
|
||||
# Write an annotation file
|
||||
atext=string.replace(formvals['annotate'],'"','"')
|
||||
target=formvals['target']
|
||||
ouf=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','w')
|
||||
ouf.write(atext)
|
||||
ouf.close()
|
||||
|
@ -556,11 +611,15 @@ def execute(macro, args):
|
|||
rotend=''
|
||||
if Globs.originals.has_key(target):
|
||||
out.write(navibar(target,'webnail'))
|
||||
out.write(toolbar(target,'webnail'))
|
||||
if formvals.has_key('rotate'):
|
||||
direction=formvals['rotate']
|
||||
message(direction)
|
||||
rotate(target,direction)
|
||||
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
|
||||
out.write(tleft)
|
||||
# Lets build up an image tag
|
||||
|
@ -582,7 +641,7 @@ def execute(macro, args):
|
|||
else:
|
||||
out.write(atext)
|
||||
out.write(trigh)
|
||||
out.write(toolbar(target,'webnail'))
|
||||
#out.write(toolbar(target,'webnail'))
|
||||
|
||||
else:
|
||||
message('I do not have file: '+target,0)
|
||||
|
|
1273
wiki/parser/EXIF.py
1273
wiki/parser/EXIF.py
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue