190 "Send an error message to the configured channel" |
190 "Send an error message to the configured channel" |
191 return |
191 return |
192 |
192 |
193 nulllog = NullLog() |
193 nulllog = NullLog() |
194 |
194 |
195 |
|
196 def copyfile(_source, _destination): |
195 def copyfile(_source, _destination): |
197 """Copy the source file to the destination file (create a directory |
196 """Copy the source file to the destination file (create a directory |
198 to copy into if it does not exist). Don't copy if the destination |
197 to copy into if it does not exist). Don't copy if the destination |
199 file exists and has an equal or newer modification time.""" |
198 file exists and has an equal or newer modification time.""" |
200 source = generic_path.Path(str(_source).replace('%20',' ')) |
199 source = generic_path.Path(str(_source).replace('%20',' ')) |
208 destDir = destination.Dir() |
207 destDir = destination.Dir() |
209 if not destDir.isDir(): |
208 if not destDir.isDir(): |
210 os.makedirs(str(destDir)) |
209 os.makedirs(str(destDir)) |
211 shutil.copyfile(source_str, dest_str) |
210 shutil.copyfile(source_str, dest_str) |
212 return |
211 return |
213 |
|
214 # Destination file exists so we have to think about updating it |
212 # Destination file exists so we have to think about updating it |
215 sourceMTime = 0 |
213 sourceMTime = 0 |
216 destMTime = 0 |
214 destMTime = 0 |
217 sourceStat = 0 |
215 sourceStat = 0 |
218 try: |
216 try: |
219 sourceStat = os.stat(source_str) |
217 sourceStat = os.stat(source_str) |
220 sourceMTime = sourceStat[stat.ST_MTIME] |
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: |
221 destMTime = os.stat(dest_str)[stat.ST_MTIME] |
223 destMTime = os.stat(dest_str)[stat.ST_MTIME] |
222 except OSError, e: |
224 except OSError, e: |
223 if sourceMTime == 0: |
225 pass # destination doesn't have to exist |
224 message = "Source of copyfile does not exist: " + str(source) |
|
225 print message |
|
226 |
226 |
227 if destMTime == 0 or destMTime < sourceMTime: |
227 if destMTime == 0 or destMTime < sourceMTime: |
228 if os.path.exists(dest_str): |
228 if os.path.exists(dest_str): |
229 os.chmod(dest_str,stat.S_IREAD | stat.S_IWRITE) |
229 os.chmod(dest_str,stat.S_IREAD | stat.S_IWRITE) |
230 shutil.copyfile(source_str, dest_str) |
230 shutil.copyfile(source_str, dest_str) |