Commits

Crispin Wellington committed 4132571

remote cache class

Comments (0)

Files changed (1)

 import os
 import errno
 
+from fabric.contrib import file
+
 from parcel.tools import dl
 
 class FileCache(object):
         return os.path.join(self.cache_dir,filename)
 
 cache = FileCache()
+
+
+class RemoteCache(object):
+    def __init__(self, remote_path):
+        self.remote_path = remote_path
+
+    def location(self, key):
+        return '{path}/{key}'.format(path=remote_path, key=key)
+
+    def is_cached(self, key):
+        return file.exists(self.location(key))
+
+    def delete(self, key):
+        run('rm -rf "{location}"'.format(location=self.location(key)))
+
+    def purge(self):
+        """empty the cache of all stored folders"""
+        run('rm -rf "{remote_path}/*"'.format(remote_path=remote_path))
+
+    def store(self, remote_path, key):
+        """Store a full backup of `remote_path` under the `key`"""
+        run('cp -Rl "{remote_path}" "{location}"'.format(remote_path=remote_path,
+                                                         location=self.location(key)))
+
+    def get(self, key, remote_path):
+        """restore a folder aved under `key` to `remote_path`"""
+        run('cp -Rl "{location}" "{remote_path}"'.format(remote_path=remote_path,
+                                                         location=selflocation(key)))
+