diff -r e6381a1f4952 -r 9fe7d0ab0f8f sbsv2/raptor/python/raptor_utilities.py --- a/sbsv2/raptor/python/raptor_utilities.py Tue May 11 13:33:47 2010 +0100 +++ b/sbsv2/raptor/python/raptor_utilities.py Tue May 11 14:36:11 2010 +0100 @@ -1,5 +1,5 @@ # -# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). # All rights reserved. # This component and the accompanying materials are made available # under the terms of the License "Eclipse Public License v1.0" @@ -20,6 +20,8 @@ import os.path import re import sys +import stat +import shutil dosSlashRegEx = re.compile(r'\\') unixSlashRegEx = re.compile(r'/') @@ -189,3 +191,49 @@ return nulllog = NullLog() + + +def copyfile(_source, _destination): + """Copy the source file to the destination file (create a directory + to copy into if it does not exist). Don't copy if the destination + file exists and has an equal or newer modification time.""" + source = generic_path.Path(str(_source).replace('%20',' ')) + destination = generic_path.Path(str(_destination).replace('%20',' ')) + dest_str = str(destination) + source_str = str(source) + + try: + + + destDir = destination.Dir() + if not destDir.isDir(): + os.makedirs(str(destDir)) + shutil.copyfile(source_str, dest_str) + return + + # Destination file exists so we have to think about updating it + sourceMTime = 0 + destMTime = 0 + sourceStat = 0 + try: + sourceStat = os.stat(source_str) + sourceMTime = sourceStat[stat.ST_MTIME] + destMTime = os.stat(dest_str)[stat.ST_MTIME] + except OSError, e: + if sourceMTime == 0: + message = "Source of copyfile does not exist: " + str(source) + print message + + if destMTime == 0 or destMTime < sourceMTime: + if os.path.exists(dest_str): + os.chmod(dest_str,stat.S_IREAD | stat.S_IWRITE) + shutil.copyfile(source_str, dest_str) + + # Ensure that the destination file remains executable if the source was also: + os.chmod(dest_str,sourceStat[stat.ST_MODE] | stat.S_IREAD | stat.S_IWRITE | stat.S_IWGRP ) + + + except Exception,e: + message = "Could not export " + source_str + " to " + dest_str + " : " + str(e) + + return