server/sources/storages.py
branchstable
changeset 5693 8af6623f3d4e
parent 5625 6ee2a7b6f194
child 5696 98d390c28edb
child 5857 1a24c62aefc5
equal deleted inserted replaced
5692:59ceed788bdb 5693:8af6623f3d4e
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """custom storages for the system source"""
    18 """custom storages for the system source"""
       
    19 
    19 from os import unlink, path as osp
    20 from os import unlink, path as osp
    20 
    21 
    21 from yams.schema import role_name
    22 from yams.schema import role_name
    22 
    23 
    23 from cubicweb import Binary
    24 from cubicweb import Binary, ValidationError
    24 from cubicweb.server import hook
    25 from cubicweb.server import hook
    25 
    26 
    26 def set_attribute_storage(repo, etype, attr, storage):
    27 def set_attribute_storage(repo, etype, attr, storage):
    27     repo.system_source.set_storage(etype, attr, storage)
    28     repo.system_source.set_storage(etype, attr, storage)
    28 
    29 
   155         if name is not None:
   156         if name is not None:
   156             basename.append(name.encode(self.fsencoding))
   157             basename.append(name.encode(self.fsencoding))
   157         fspath = uniquify_path(self.default_directory, '_'.join(basename))
   158         fspath = uniquify_path(self.default_directory, '_'.join(basename))
   158         if fspath is None:
   159         if fspath is None:
   159             msg = entity._cw._('failed to uniquify path (%s, %s)') % (
   160             msg = entity._cw._('failed to uniquify path (%s, %s)') % (
   160                 dirpath, '_'.join(basename))
   161                 self.default_directory, '_'.join(basename))
   161             raise ValidationError(entity.eid, {role_name(attr, 'subject'): msg})
   162             raise ValidationError(entity.eid, {role_name(attr, 'subject'): msg})
   162         return fspath
   163         return fspath
   163 
   164 
   164     def current_fs_path(self, entity, attr):
   165     def current_fs_path(self, entity, attr):
   165         sysource = entity._cw.pool.source('system')
   166         sysource = entity._cw.pool.source('system')