server/sources/storages.py
changeset 8695 358d8bed9626
parent 8662 60a13447f389
child 8900 010a59e12d89
equal deleted inserted replaced
8694:d901c36bcfce 8695:358d8bed9626
   142         accessed
   142         accessed
   143         """
   143         """
   144         fpath = source.binary_to_str(value)
   144         fpath = source.binary_to_str(value)
   145         try:
   145         try:
   146             return Binary.from_file(fpath)
   146             return Binary.from_file(fpath)
   147         except EnvironmentError, ex:
   147         except EnvironmentError as ex:
   148             source.critical("can't open %s: %s", value, ex)
   148             source.critical("can't open %s: %s", value, ex)
   149             return None
   149             return None
   150 
   150 
   151     def entity_added(self, entity, attr):
   151     def entity_added(self, entity, attr):
   152         """an entity using this storage for attr has been added"""
   152         """an entity using this storage for attr has been added"""
   262 class AddFileOp(hook.DataOperationMixIn, hook.Operation):
   262 class AddFileOp(hook.DataOperationMixIn, hook.Operation):
   263     def rollback_event(self):
   263     def rollback_event(self):
   264         for filepath in self.get_data():
   264         for filepath in self.get_data():
   265             try:
   265             try:
   266                 unlink(filepath)
   266                 unlink(filepath)
   267             except Exception, ex:
   267             except Exception as ex:
   268                 self.error('cant remove %s: %s' % (filepath, ex))
   268                 self.error('cant remove %s: %s' % (filepath, ex))
   269 
   269 
   270 class DeleteFileOp(hook.DataOperationMixIn, hook.Operation):
   270 class DeleteFileOp(hook.DataOperationMixIn, hook.Operation):
   271     def postcommit_event(self):
   271     def postcommit_event(self):
   272         for filepath in self.get_data():
   272         for filepath in self.get_data():
   273             try:
   273             try:
   274                 unlink(filepath)
   274                 unlink(filepath)
   275             except Exception, ex:
   275             except Exception as ex:
   276                 self.error('cant remove %s: %s' % (filepath, ex))
   276                 self.error('cant remove %s: %s' % (filepath, ex))