1 # |
1 # |
2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 # Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 # All rights reserved. |
3 # All rights reserved. |
4 # This component and the accompanying materials are made available |
4 # This component and the accompanying materials are made available |
5 # under the terms of the License "Eclipse Public License v1.0" |
5 # under the terms of the License "Eclipse Public License v1.0" |
6 # which accompanies this distribution, and is available |
6 # which accompanies this distribution, and is available |
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
187 def Error(self, format, *extras): |
189 def Error(self, format, *extras): |
188 "Send an error message to the configured channel" |
190 "Send an error message to the configured channel" |
189 return |
191 return |
190 |
192 |
191 nulllog = NullLog() |
193 nulllog = NullLog() |
|
194 |
|
195 def copyfile(_source, _destination): |
|
196 """Copy the source file to the destination file (create a directory |
|
197 to copy into if it does not exist). Don't copy if the destination |
|
198 file exists and has an equal or newer modification time.""" |
|
199 source = generic_path.Path(str(_source).replace('%20',' ')) |
|
200 destination = generic_path.Path(str(_destination).replace('%20',' ')) |
|
201 dest_str = str(destination) |
|
202 source_str = str(source) |
|
203 |
|
204 try: |
|
205 |
|
206 |
|
207 destDir = destination.Dir() |
|
208 if not destDir.isDir(): |
|
209 os.makedirs(str(destDir)) |
|
210 shutil.copyfile(source_str, dest_str) |
|
211 return |
|
212 # Destination file exists so we have to think about updating it |
|
213 sourceMTime = 0 |
|
214 destMTime = 0 |
|
215 sourceStat = 0 |
|
216 try: |
|
217 sourceStat = os.stat(source_str) |
|
218 sourceMTime = sourceStat[stat.ST_MTIME] |
|
219 except OSError, e: |
|
220 message = "Source of copyfile does not exist: " + str(source) |
|
221 raise IOError(message) |
|
222 try: |
|
223 destMTime = os.stat(dest_str)[stat.ST_MTIME] |
|
224 except OSError, e: |
|
225 pass # destination doesn't have to exist |
|
226 |
|
227 if destMTime == 0 or destMTime < sourceMTime: |
|
228 if os.path.exists(dest_str): |
|
229 os.chmod(dest_str,stat.S_IREAD | stat.S_IWRITE) |
|
230 shutil.copyfile(source_str, dest_str) |
|
231 |
|
232 # Ensure that the destination file remains executable if the source was also: |
|
233 os.chmod(dest_str,sourceStat[stat.ST_MODE] | stat.S_IREAD | stat.S_IWRITE | stat.S_IWGRP ) |
|
234 |
|
235 |
|
236 except Exception,e: |
|
237 message = "Could not update " + dest_str + " from " + source_str + " : " + str(e) |
|
238 raise IOError(message) |
|
239 |
|
240 return |