| 347 | self.cachefile = cachefile |
| 348 | |
| 349 | def needs_build(self): |
| 350 | if not self.destination.exists(): |
| 351 | return True, "destination does not exist" |
| 352 | if not self.cachefile.exists(): |
| 353 | return True, "cache file does not exist" |
| 354 | # Last modified time of destination (which must exist) |
| 355 | dest_mtime = os.path.getmtime(self.destination) |
| 356 | # Build if any source is newer than destination |
| 357 | for source in self.sources: |
| 358 | if os.path.getmtime(source) >= dest_mtime: |
| 359 | return True, f"source file {source} is newer than destination" |
| 360 | # Check source list if cachefile exists |
| 361 | if self.cachefile.exists(): |
| 362 | previous_sources = pickle.load(self.cachefile.open('rb'))['sorted_sources'] |
| 363 | if sorted(self.sources) != previous_sources: |
| 364 | return True, "source list has changed" |
| 365 | return False, "" |
| 366 | |
| 367 | def write_cache(self): |
| 368 | with self.cachefile.open('wb') as fp: |