Page MenuHomec4science

archive.py.wml
No OneTemporary

File Metadata

Created
Thu, Apr 24, 12:42

archive.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"
pylibdir = "<LIBDIR>/python"
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
## import interesting modules:
import string
import os
import sys
import time
import types
import re
sys.path.append('%s' % pylibdir)
from cdsware.config import *
from cdsware.access_control_engine import acc_authorize_action
from cdsware.access_control_admin import acc_isRole
from cdsware.webpage import page, create_error_box
from cdsware.webuser import getUid, get_email
from cdsware.messages import *
from mod_python import apache
from cdsware.websubmit_config import *
def index(req,c=cdsname,ln=cdslang,base="",id=""):
# get user ID:
try:
uid = getUid(req)
uid_email = get_email(uid)
except MySQLdb.Error, e:
return errorMsg(e.value,req)
t = "<center><table><tr><td>"
if base == "":
return warningMsg("Sorry... Parameter <i>base</i> needed",req)
elif id == "":
return warningMsg("Sorry... Parameter <i>id</i> needed",req)
elif not os.path.exists("%s/%s" % (archive,base)):
return warningMsg("Sorry... Cannot find base %s" % base, req)
else:
id = id.lower()
# initialise variables
numfiles = 0
nummainfiles = 0
numadditionalfiles = 0
mainfiletext = "<blockquote><table border=0 cellspacing=2>"
additionalfiletext = "<blockquote><table border=0 cellspacing=2>"
# first open base directory
for root, dirs, files in os.walk("%s/%s" % (archive,base)):
if root == "%s/%s" % (archive,base):
for file in files:
if re.search("^%s\..*" % id,file):
numfiles += 1
nummainfiles += 1
size = os.path.getsize("%s/%s/%s" % (archive,base,file))
fileurl = "%s/%s/%s" % (archive,base,file)
filename = re.sub("([^\.]*)\..*","\\1",file)
if os.path.exists("%s/%s/icon-%s.gif" % (archive,base,filename)):
imagesrc = "%s/%s/icon-%s.gif" % (archive,base,filename)
else:
imagesrc = "%s/smallfiles.gif" % images
mainfiletext += "<tr><td align=right><img src='%s' border=0></td><td valign=top><small><a href='%s'>%s</a></td><td valign=top><font size=-2 color=green>[%s o]</font></small></td></tr>" % (imagesrc,fileurl,file,size)
elif root == "%s/%s/%s" % (archive,base,id):
for file in files:
if not re.match("^icon-.*.gif",file):
numfiles+=1
numadditionalfiles+=1
size = os.path.getsize("%s/%s/%s/%s" % (archive,base,id,file))
fileurl = "%s/%s/%s/%s" % (archive,base,id,file)
filename = re.sub("([^\.]*)\..*","\\1",file)
if os.path.exists("%s/%s/%s/icon-%s.gif" % (archive,base,id,filename)):
imagesrc = "%s/%s/%s/icon-%s.gif" % (archive,base,id,filename)
else:
imagesrc = "%s/smallfiles.gif" % images
additionalfiletext += "<tr><td align=right><img src='%s' border=0></td><td valign=top><small><a href='%s'>%s</a></td><td valign=top><font size=-2 color=green>[%s o]</font></small></td></tr>" % (imagesrc,fileurl,file,size)
mainfiletext += "</table></blockquote>"
additionalfiletext += "</table></blockquote>"
if numfiles != 0:
if nummainfiles != 0:
t+="<small><p>found %s <b>main</b> file(s):</small>" % nummainfiles
t+=mainfiletext
if numadditionalfiles != 0:
t+="<small><p>found <font color=green>%s</font> <b>additional</b> file(s):</small>" % numadditionalfiles
t+=additionalfiletext
else:
return warningMsg("no file found...",req)
t+="</td></tr></table></center>"
return page(title="Archive %s %s" % (base,id),
body=t,
description="toto",
keywords="keywords",
uid=uid,
language=ln,
urlargs=req.args
)
def errorMsg(title,req,c=cdsname,ln=cdslang):
return page(title="error",
body = create_error_box(req, title=title,verbose=0, ln=ln),
description="%s - Internal Error" % c,
keywords="%s, CDSware, Internal Error" % c,
language=ln,
urlargs=req.args)
def warningMsg(title,req,c=cdsname,ln=cdslang):
return page(title="warning",
body = title,
description="%s - Internal Error" % c,
keywords="%s, CDSware, Internal Error" % c,
language=ln,
urlargs=req.args)
</protect>

Event Timeline