Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92000834
Upload_Files.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 16, 12:33
Size
8 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 12:33 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22361433
Attached To
R3600 invenio-infoscience
Upload_Files.py
View Options
## $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_Files
(
parameters
,
curdir
,
form
):
global
doctype
,
access
,
act
,
dir
minsize
=
parameters
[
'minsize'
]
maxsize
=
parameters
[
'maxsize'
]
t
=
""
if
form
.
has_key
(
"deleted"
):
deleted
=
form
[
'deleted'
]
else
:
deleted
=
"no"
if
form
.
has_key
(
"deletedfile"
):
deletedfile
=
form
[
'deletedfile'
]
else
:
deletedfile
=
""
# first check if a file has been requested for deletion
if
os
.
path
.
exists
(
"
%s
/deleted"
%
curdir
):
fp
=
open
(
"
%s
/deleted"
%
curdir
,
"r"
)
deleted
=
fp
.
read
()
fp
.
close
()
os
.
unlink
(
"
%s
/deleted"
%
curdir
)
if
os
.
path
.
exists
(
"
%s
/deletedfile"
%
curdir
):
fp
=
open
(
"
%s
/deletedfile"
%
curdir
,
"r"
)
deletedfile
=
fp
.
read
()
fp
.
close
()
os
.
unlink
(
"
%s
/deletedfile"
%
curdir
)
if
deleted
==
"yes"
:
if
os
.
path
.
exists
(
deletedfile
):
os
.
unlink
(
deletedfile
)
# 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
))
createRelatedFormats
(
curdir
,
re
.
sub
(
"\.
%s
"
%
extension
,
""
,
myfile
),
extension
)
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
))
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
:
MainFiles
.
append
(
file
)
for
root
,
dirs
,
files
in
os
.
walk
(
"
%s
/files/AdditionalFiles"
%
curdir
):
for
file
in
files
:
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
=
""
t
=
t
+
"<TD><small><IMG src=
%s
/smallfiles.gif>
%s
</small></TD>"
%
(
images
,
file
)
t
=
t
+
"<TD><small> <font color=green>["
+
str
(
os
.
path
.
getsize
(
"
%s
/
%s
"
%
(
filepath
,
file
)))
+
" o]</font></small></TD>"
t
=
t
+
"<TD><small> <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>[ <A href=
\"
%s
\"
><IMG src=
%s
/iconeye.gif border=0></a> <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> ]<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
createRelatedFormats
(
curdir
,
file
,
extension
):
if
extension
==
"pdf"
:
# Create PostScript
os
.
system
(
"
%s
-toPostScript
%s
/files/MainFiles/
%s
.pdf"
%
(
acroread
,
curdir
,
file
))
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps"
%
(
gzip
,
curdir
,
file
))
if
extension
==
"ps"
:
# Create PDF
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps
%s
/files/MainFiles/
%s
.pdf"
%
(
distiller
,
curdir
,
file
,
curdir
,
file
))
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps"
%
(
gzip
,
curdir
,
file
))
if
extension
==
"ps.gz"
:
#gunzip file
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps.gz"
%
(
gunzip
,
curdir
,
file
))
# Create PDF
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps
%s
/files/MainFiles/
%s
.pdf"
%
(
distiller
,
curdir
,
file
,
curdir
,
file
))
#gzip file
os
.
system
(
"
%s
%s
/files/MainFiles/
%s
.ps"
%
(
gzip
,
curdir
,
file
))
</
protect
>
Event Timeline
Log In to Comment