@@ -0,0 +1,2046 @@
+%22%22%22%0AFile system directory oriented data store.%0A%22%22%22%0A%0Aimport os%0Aimport shutil%0A%0Afrom .base import BaseDataDirectory, BaseDataStream%0Afrom .autoserialize import DataValuePickle%0A%0A%0Adef mkdirp(path):%0A    %22%22%22Do %60%60mkdir -p %7Bpath%7D%60%60%22%22%22%0A    if not os.path.isdir(path):%0A        os.makedirs(path)%0A%0A%0Aclass DataFile(BaseDataStream):%0A%0A    def open(self, *args, **kwds):%0A        return open(self.path, *args, **kwds)%0A%0A%0Aclass DataDirectory(BaseDataDirectory):%0A%0A    default_substore_type = DataFile%0A    default_valuestore_type = DataValuePickle%0A%0A    def __init__(self, *args, **kwds):%0A        super(DataDirectory, self).__init__(*args, **kwds)%0A        mkdirp(self.path)%0A%0A    def aspath(self, key):%0A        return os.path.join(self.path, key)%0A%0A    def _listdir(self):%0A        return os.listdir(self.path)%0A%0A    def __len__(self):%0A        return len(self._listdir)%0A%0A    def __iter__(self):%0A        sep = os.path.sep%0A        for key in self._listdir():%0A            if os.path.isdir(self.aspath(key)) and not key.endswith(sep):%0A                yield key + sep%0A            else:%0A                yield key%0A%0A    def _del_store(self, key):%0A        path = self.aspath(key)%0A        if not os.path.exists(path):%0A            raise KeyError(%0A                'Key %7B0%7D (path: %7B1%7D) does not exist'.format(key, path))%0A        if os.path.isdir(path):%0A            shutil.rmtree(self.aspath(key))%0A        else:%0A            os.remove(path)%0A%0A    def _get_store(self, key):%0A        path = self.aspath(key)%0A        if key.endswith(os.path.sep):%0A            cls = self.default_substore_type or self.__class__%0A            return cls(path=path)%0A        else:%0A            return self.default_streamstore_type(path=path)%0A%0A    def _set_store(self, key, value):%0A        path = self.aspath(key)%0A        if isinstance(value, BaseDataDirectory):%0A            mkdirp(path)%0A        elif isinstance(value, DataFile) and not os.path.exists(path):%0A            open(path, 'w').close()%0A        else:%0A            raise ValueError(%0A                'Value %7B0!r%7D is not supported data store type.'.format(value))%0A

Add buildlet.datastore.directory