Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91992770
Set_Archive_Files.py.wml
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, 11:05
Size
4 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 11:05 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22358181
Attached To
R3600 invenio-infoscience
Set_Archive_Files.py.wml
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>
## Description: function Set_Archive_Files
## This function creates two files containing 1/ the future
## of the submitted file 2/ The directory in which this file
## will be saved
## Author: T.Baron
## PARAMETERS: pathARCHIVE: path to the final storage directory
## formatARCHIVE: final name of the file
## variablesARCHIVE: variables derived from the reference
## of the document. THese variables may then be
## used to derive the first two parameters
def Set_Archive_Files (parameters,curdir,form):
#Set all local variables
path = parameters['pathARCHIVE']
format = parameters['formatARCHIVE']
#case sensitive file name?
if re.match("<CS>",format):
cs = 1
format = format.replace("<CS>","")
else:
cs = 0
vartext = parameters['variablesARCHIVE']
repno = rn
if cs == 0:
repno = repno.upper()
repno = repno.replace(" ","")
repno = repno.replace("\r","")
repno = repno.replace("\n","")
# if we find <LANG> in the format, replace it with the language
if re.match("<LANG>",format):
if os.path.exists("%s/LANG" % curdir):
fp = open("%s/LANG" % curdir)
language = fp.read()
fp.close()
elif os.path.exists("%s/LANG2" % curdir):
fp = open("%s/LANG2" % curdir)
language = fp.read()
fp.close()
else:
language = "e"
language=language.replace("\n","")
if language == "eng":
language="e"
if language == "fre":
language="f"
format = format.replace("<LANG>",language)
# retrieve all regexp from repno
regexp = re.sub("<[^<]*>","(.*)",vartext)
varnames = re.search(regexp,vartext)
if varnames != None:
varvalues = re.search(regexp,repno)
if varvalues != None:
if len(varvalues.groups()) == len(varnames.groups()):
variables = {}
for i in range (0,len(varvalues.groups())):
variables[varnames.group(i)] = varvalues.group(i)
if cs == 0:
variables[varnames.group(i)] = variables[varnames.group(i)] .lower()
# creates formatted file name
regexp = re.sub("<[^<]*>","(.*)",format)
names = re.search(regexp,format)
if names != None:
for name in names.groups():
filename = re.sub("[<>]+","",name)
# General case when a varibale with this name exists
if variables.has_key(name):
format = format.replace(name,variables[name])
elif os.path.exists("%s/%s" % (curdir,filename)):
fp = open("%s/%s" % (curdir,filename),"r")
value = fp.read()
fp.close()
format = format.replace(name,value)
if cs == 0:
format = format.lower()
format = format.replace("\r","")
format = format.replace("\n","")
#save it
fp = open("%s/formatfile" % curdir,"w+")
fp.write(format)
fp.close()
#creates formatted file path
regexp = re.sub("<[^<]*>","(.*)",path)
names = re.search(regexp,path)
if names != None:
for name in names.groups():
filename = re.sub("[<>]+","",name)
# General case when a varibale with this name exists
if variables.has_key(name):
path = path.replace(name,variables[name])
elif os.path.exists("%s/%s" % (curdir,filename)):
fp = open("%s/%s" % (curdir,filename),"r")
value = fp.read()
fp.close()
path = path.replace(name,value)
#save it
path = path.replace("\r","")
path = path.replace("\n","")
fp = open("%s/archivepath" % curdir,"w+")
fp.write("%s/%s" % (archive,path))
fp.close ()
return ""
</protect>
Event Timeline
Log In to Comment