diff options
-rw-r--r-- | morphlib/localartifactcache.py | 13 | ||||
-rw-r--r-- | morphlib/localartifactcache_tests.py | 13 |
2 files changed, 26 insertions, 0 deletions
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py index 893359d8..7ad53db0 100644 --- a/morphlib/localartifactcache.py +++ b/morphlib/localartifactcache.py @@ -71,3 +71,16 @@ class LocalArtifactCache(object): def _source_metadata_filename(self, source, cachekey, name): basename = '%s.%s' % (cachekey, name) return os.path.join(self.cachedir, basename) + + def clear(self): + '''Clear everything from the artifact cache directory. + + After calling this, the artifact cache will be entirely empty. + Caveat caller. + + ''' + + for dirname, subdirs, basenames in os.walk(self.cachedir): + for basename in basenames: + os.remove(os.path.join(dirname, basename)) + diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py index 8e25e5c9..36b5e891 100644 --- a/morphlib/localartifactcache_tests.py +++ b/morphlib/localartifactcache_tests.py @@ -142,3 +142,16 @@ class LocalArtifactCacheTests(unittest.TestCase): self.assertEqual(stored_metadata, 'source log line 1\nsource log line 2\n') + + def test_clears_artifact_cache(self): + cache = morphlib.localartifactcache.LocalArtifactCache( + self.tempdir.dirname) + + handle = cache.put(self.runtime_artifact) + handle.write('runtime') + handle.close() + + self.assertTrue(cache.has(self.runtime_artifact)) + cache.clear() + self.assertFalse(cache.has(self.runtime_artifact)) + |