Page MenuHomec4science

Move_Files_Archive.py
No OneTemporary

File Metadata

Created
Wed, Jul 10, 09:30

Move_Files_Archive.py

## $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"
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
import shutil
def Move_Files_Archive(parameters,curdir,form):
#Set local variables
if os.path.exists("%s/archivepath" % curdir):
fp = open("%s/archivepath" % curdir,"r")
archivepath = fp.read()
fp.close()
else:
raise functionError("Set_Archive_Files should be called before Move_Files_Archive")
if os.path.exists("%s/formatfile" % curdir):
fp = open("%s/formatfile" % curdir,"r")
formatfile = fp.read()
fp.close()
else:
raise functionError("Set_Archive_Files should be called before Move_Files_Archive")
MainDir = "%s/files/MainFiles" % curdir
IncludeDir = "%s/files/AdditionalFiles" %curdir
IconDir = "%s/files/icons" % curdir
# create archive directories if needed
if not os.path.exists("%s/%s" % (archivepath,formatfile)):
os.makedirs("%s/%s" % (archivepath,formatfile))
# create "obsolete" directory in archive in order to avoid preexisting file destruction
if not os.path.exists("%s/obsolete" % archivepath):
os.mkdir("%s/obsolete" % archivepath)
now=time.strftime("%Y-%m-%d_%H:%M:%S")
# icon files
if os.path.exists(IconDir):
for root, dirs, files in os.walk(IconDir):
for file in files:
if os.path.exists("%s/%s/%s" % (archivepath,formatfile,file)):
os.rename("%s/%s/%s" % (archivepath,formatfile,file),"%s/obsolete/%s_%s" % (archivepath,file,now))
shutil.copy("%s/%s" % (IconDir,file),"%s/%s/%s" % (archivepath,formatfile,file))
# additional Files
if os.path.exists(IncludeDir):
for root, dirs, files in os.walk(IncludeDir):
for file in files:
if os.path.exists("%s/%s/%s" % (archivepath,formatfile,file)):
os.rename("%s/%s/%s" % (archivepath,formatfile,file),"%s/obsolete/%s_%s" % (archivepath,file,now))
shutil.copy("%s/%s" % (IncludeDir,file),"%s/%s/%s" % (archivepath,formatfile,file))
extension = re.sub("^[^\.]*\.","",file).lower()
if extension == "ps" and gzip != "":
os.system("%s %s/%s/%s" % (gzip,archivepath,formatfile,file))
# main Files
if os.path.exists(MainDir):
for root, dirs, files in os.walk(MainDir):
for file in files:
extension = re.sub("^[^\.]*\.","",file).lower()
if os.path.exists("%s/%s.%s" % (archivepath,formatfile,extension)):
os.rename("%s/%s.%s" % (archivepath,formatfile,extension),"%s/obsolete/%s.%s_%s" % (archivepath,formatfile,extension,now))
shutil.copy("%s/%s" % (MainDir,file),"%s/%s.%s" % (archivepath,formatfile,extension))
extension = re.sub("^[^\.]*\.","",file).lower()
if extension.lower() == "ps" and gzip != "":
os.system("%s %s/%s" % (gzip,archivepath,file))
return ""
</protect>

Event Timeline