import os
import tools
import base64
+import logging
+
from tools.misc import ustr
from tools.translate import _
"""
_name = 'document.storage'
_description = 'Storage Media'
+ _doclog = logging.getLogger('document')
+
_columns = {
'name': fields.char('Name', size=64, required=True, select=1),
'write_date': fields.datetime('Date Modified', readonly=True),
# On a migrated db, some files may have the wrong storage type
# try to fix their directory.
if ira.file_size:
- netsvc.Logger().notifyChannel('document', netsvc.LOG_WARNING, "ir.attachment #%d does not have a filename, but is at filestore, fix it!" % ira.id)
+ self._doclog.warning( "ir.attachment #%d does not have a filename, but is at filestore, fix it!" % ira.id)
return None
fpath = os.path.join(boo.path, ira.store_fname)
return file(fpath, 'rb').read()
# On a migrated db, some files may have the wrong storage type
# try to fix their directory.
if ira.file_size:
- netsvc.Logger().notifyChannel('document',netsvc.LOG_WARNING,"ir.attachment #%d does not have a filename, trying the name." %ira.id)
+ self._doclog.warning("ir.attachment #%d does not have a filename, trying the name." %ira.id)
sfname = ira.name
fpath = os.path.join(boo.path,ira.store_fname or ira.name)
if os.path.exists(fpath):
if not context:
context = {}
boo = self.browse(cr, uid, id, context)
- logger = netsvc.Logger()
if fil_obj:
ira = fil_obj
else:
if not boo.online:
raise RuntimeError('media offline')
- logger.notifyChannel('document', netsvc.LOG_DEBUG, "Store data for ir.attachment #%d" % ira.id)
+ self._doclog.debug( "Store data for ir.attachment #%d" % ira.id)
store_fname = None
fname = None
if boo.type == 'filestore':
fp = file(fname, 'wb')
fp.write(data)
fp.close()
- logger.notifyChannel('document', netsvc.LOG_DEBUG, "Saved data to %s" % fname)
+ self._doclog.debug( "Saved data to %s" % fname)
filesize = len(data) # os.stat(fname).st_size
store_fname = os.path.join(flag, filename)
# TODO Here, an old file would be left hanging.
- except Exception, e :
- netsvc.Logger().notifyChannel('document', netsvc.LOG_WARNING, "Couldn't save data: %s" % str(e))
+ except Exception, e:
+ self._doclog.warning( "Couldn't save data to %s", path, exc_info=True)
raise except_orm(_('Error!'), str(e))
elif boo.type == 'db':
filesize = len(data)
fp = file(fname,'wb')
fp.write(data)
fp.close()
- logger.notifyChannel('document',netsvc.LOG_DEBUG,"Saved data to %s" % fname)
+ self._doclog.debug("Saved data to %s", fname)
filesize = len(data) # os.stat(fname).st_size
store_fname = os.path.join(*npath)
# TODO Here, an old file would be left hanging.
except Exception,e :
- import traceback
- traceback.print_exc()
- netsvc.Logger().notifyChannel('document',netsvc.LOG_WARNING,"Couldn't save data: %s" % e)
+ self._doclog.warning("Couldn't save data:", exc_info=True)
raise except_orm(_('Error!'), str(e))
else:
raise TypeError("No %s storage" % boo.type)
try:
mime, icont = cntIndex.doIndex(data, ira.datas_fname,
ira.file_type or None, fname)
- except Exception, e:
- logger.notifyChannel('document', netsvc.LOG_DEBUG, 'Cannot index file: %s' % str(e))
+ except Exception:
+ self._doclog.debug('Cannot index file:', exc_info=True)
pass
# a hack: /assume/ that the calling write operation will not try
file_node.content_type = mime
return True
except Exception, e :
- netsvc.Logger().notifyChannel('document', netsvc.LOG_WARNING, "Couldn't save data: %s" % str(e))
+ self._doclog.warning( "Couldn't save data:", exc_info=True)
# should we really rollback once we have written the actual data?
# at the db case (only), that rollback would be safe
raise except_orm(_('Error at doc write!'), str(e))
try:
os.unlink(fname)
except Exception, e:
- netsvc.Logger().notifyChannel('document', netsvc.LOG_WARNING, "Could not remove file %s, please remove manually." % fname)
+ self._doclog.warning("Could not remove file %s, please remove manually.", fname, exc_info=True)
else:
- netsvc.Logger().notifyChannel('document', netsvc.LOG_WARNING, "Unknown unlink key %s" % ktype)
+ self._doclog.warning("Unknown unlink key %s" % ktype)
return True