Page MenuHomec4science

Upload_Pictures.py.wml
No OneTemporary

File Metadata

Created
Sat, Nov 16, 12:58

Upload_Pictures.py.wml

## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## read config variables:
#include "config.wml"
#include "configbis.wml"
## start Python:
<protect>## $Id$</protect>
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
"""CDSware Submission Web Interface."""
<protect>
def Upload_Pictures(parameters,curdir,form):
global doctype,access,act,dir
minsize=parameters['minsize']
maxsize=parameters['maxsize']
iconsize=parameters['iconsize']
t=""
# first check if a file has been requested for deletion
if form.has_key("deleted"):
deleted = form['deleted']
else:
deleted = "no"
if form.has_key("deletedfile"):
deletedfile = form['deletedfile']
else:
deletedfile = ""
if os.path.exists("%s/deleted" % curdir):
os.unlink("%s/deleted" % curdir)
if os.path.exists("%s/deletedfile" % curdir):
os.unlink("%s/deletedfile" % curdir)
if deleted == "yes":
file = re.sub(".*\/","",deletedfile)
name = re.sub("\..*","",file)
iconpath = deletedfile.replace(file,"icon-%s.gif" % name)
if os.path.exists(deletedfile):
os.unlink(deletedfile)
if os.path.exists(iconpath):
os.unlink(iconpath)
# then check if a file has been requested for addition
if os.path.exists("%s/myfile" % curdir):
fp = open("%s/myfile" % curdir,"r")
myfile=fp.read()
fp.close()
fp = open("%s/FileType" % curdir,"r")
fileType = fp.read()
fp.close()
extension = re.sub("^[^\.]*\.","",myfile)
if os.path.getsize("%s/files/myfile/%s" % (curdir,myfile)) < int(minsize):
os.unlink("%s/myfile" % curdir)
os.unlink("%s/files/myfile/%s" % (curdir,myfile))
t+= """
<script>
alert("your file was too small (<%s o) and was deleted");
</script>""" % minsize
elif os.path.getsize("%s/files/myfile/%s" % (curdir,myfile)) > int(maxsize):
os.unlink("%s/myfile" % curdir)
os.unlink("%s/files/myfile/%s" % (curdir,myfile))
t+= """
<script>
alert("your file was too big (>%s o) and was deleted");
</script>""" % maxsize
else:
if fileType == "Main File":
if not os.path.exists("%s/files/MainFiles" % curdir):
os.makedirs("%s/files/MainFiles" % curdir)
deleteMainFiles(curdir)
os.rename("%s/files/myfile/%s" % (curdir,myfile),"%s/files/MainFiles/%s" % (curdir,myfile))
createIcon("%s/files/MainFiles" % curdir,re.sub("\.%s" % extension,"",myfile),extension,iconsize)
elif fileType == "Additional File":
if not os.path.exists("%s/files/AdditionalFiles" % curdir):
os.makedirs("%s/files/AdditionalFiles" % curdir)
os.rename("%s/files/myfile/%s" % (curdir,myfile),"%s/files/AdditionalFiles/%s" % (curdir,myfile))
createIcon("%s/files/AdditionalFiles" % curdir,re.sub("\.%s" % extension,"",myfile),extension,iconsize)
os.unlink("%s/myfile" % curdir)
t=t+Display_Form()
t=t+Display_File_List(curdir)
return t
def Display_File_List(curdir):
MainFiles = []
AdditionalFiles = []
t=""
for root, dirs, files in os.walk("%s/files/MainFiles" % curdir):
for file in files:
if re.match("^icon-",file) == None:
MainFiles.append(file)
for root, dirs, files in os.walk("%s/files/AdditionalFiles" % curdir):
for file in files:
if re.match("^icon-",file) == None:
AdditionalFiles.append(file)
t=t+"<BR><BR><TABLE cellpadding=4 border=0 bgcolor=#ffffff width=80% align=center><TR align=left bgcolor=#eeeeee><TD><small><b>Main File</b></TD></TR>"
t=t+ "<TR><TD><table>"
if len(MainFiles) != 0:
for file in MainFiles:
t=t+"<TR>"
t=t+displayFile("%s/files/MainFiles" % curdir,file)
t=t+ "</TR>"
else:
t=t+ "<TR><TD><small>"
t=t+ "main file is missing..."
t=t+ "</small></TD></TR>"
t=t+ "</table></TD></TR><TR bgcolor=#eeeeee><TD><small><b>Additional Files</b></small></TD></TR><TR><TD><table>"
if len(AdditionalFiles) != 0:
for file in AdditionalFiles:
t=t+"<TR>"
t=t+displayFile("%s/files/AdditionalFiles" % curdir,file)
t=t+ "</TR>"
else:
t=t+ "<TR><TD><small>"
t=t+ "no additional files..."
t=t+ "</small></TD></TR>"
t=t+ "</table></small></TD></TR></TABLE><br><CENTER><small><INPUT TYPE=\"button\" HEIGHT=35 WIDTH=250 NAME=\"Submit\" VALUE=\"End Submission\" onClick=\"step2();\"></small></CENTER>"
return t
def Display_Form():
#output the upload files form.
t=""
t=t+"""
<B>Don't forget to click on the \"End Submission\" button when you have finished managing the files.</b><br><br>
<TABLE cellpadding=0 cellspacing=0 border=0 bgcolor=#dddddd width=80% align=center>
<TR>
<TD>
<SMALL>Please complete the form below to upload a new file:</SMALL>
</TD></TR>
<TR><TD>
<INPUT name=deletedfile value=\"\" type=hidden>
<TABLE>
<TR>
<TD ALIGN=center bgcolor=white width=20>
<small><B>1</B></small>
</TD>
<TD>
<small><SELECT name=FileType>
<option selected> Select:
<option> Main File
<option> Additional File
</SELECT></small>
</TD>
<TD></TD>
</TR>
<TR>
<TD ALIGN=center bgcolor=white width=20>
<small><b>2</B></small>
</TD>
<TD>
<small><INPUT NAME=myfile TYPE=\"file\"> </small>
</TD>
</TR>
<TR>
<TD ALIGN=center bgcolor=white width=20>
<small><B>3</B></small>
</TD>
<TD ALIGN=LEFT>
<small><INPUT TYPE=\"Submit\" WIDTH=150 VALUE=\"Click to send file\"></small>
</TD>
</TR>
</TABLE>
</TD></TR></TABLE>
<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\">
function step2()
{
if(confirm(\"You are about to submit the files and end the upload process.\"))
{
document.forms[0].step.value = 2;
document.forms[0].submit();
}
return true;
}
</SCRIPT> """
return t
def displayFile(filepath,file):
t=""
name = re.sub("\..*","",file)
if os.path.exists("%s/icon-%s.gif" % (filepath,name)):
iconurl = "%s/storage/%s/icon-%s.gif" % (urlpath,filepath.replace(storage,""),name)
icontext = "<img src=%s border=0>" % iconurl
else:
icontext = ""
t=t+ "<TD><small>%s&nbsp;%s</small></TD>" % (icontext,file)
t=t+ "<TD><small>&nbsp;<font color=green>["+time.strftime("%d/%m/%Y %H:%M",time.gmtime(os.path.getmtime("%s/%s" %(filepath,file))))+"]</font></small></TD>"
fileurl = "%s/storage/%s/%s" % (urlpath,filepath.replace(storage,""),file)
t=t+ "<TD><small>[&nbsp;<A href=\"%s\"><IMG src=%s/iconeye.gif border=0></a>&nbsp;<A href=\"\" onClick=\"if (confirm('Are you sure you want to delete %s?')) { document.forms[0].deletedfile.value='%s/%s';document.forms[0].deleted.value='yes';document.forms[0].submit();return false;} else { return false; }\"><IMG src=%s/smallbin.gif border=0></a>&nbsp;]<br></small></TD>" % (fileurl,images,file,filepath,file,images)
return t
def deleteMainFiles(curdir):
for root, dirs, files in os.walk("%s/files/MainFiles" % curdir):
for file in files:
os.unlink("%s/files/MainFiles/%s" %(curdir,file))
def createIcon(dir,file,extension,iconsize):
global convert
myfile = "%s.%s" % (file,extension)
if os.path.exists("%s/%s" % (dir,myfile)):
os.system("%s -scale %s %s/%s %s/icon-%s.gif" % (convert,iconsize,dir,myfile,dir,file))
</protect>

Event Timeline