summaryrefslogtreecommitdiff
path: root/addons/document
diff options
context:
space:
mode:
authorJiten (OpenERP) <jra@tinyerp.com>2012-06-27 13:25:08 +0530
committerJiten (OpenERP) <jra@tinyerp.com>2012-06-27 13:25:08 +0530
commit18dd2dfcab7ee866f5e344ea5c26d4e78faba2f2 (patch)
tree068dcc026be4048b1bf56df1c6a61a28dcf34b0c /addons/document
parentea46eb264517fac17720f3a9a524c766e891ac1d (diff)
parent6c0bdc167b1c6a5b2cbb36a045bfd1abc1cd121a (diff)
[MERGE] Merged from openobject-addons.
bzr revid: jra@tinyerp.com-20120627075508-kko9c9dr67695hzw
Diffstat (limited to 'addons/document')
-rw-r--r--addons/document/content_index.py17
-rw-r--r--addons/document/document.py11
-rw-r--r--addons/document/document_data.xml1
-rw-r--r--addons/document/document_directory.py9
-rw-r--r--addons/document/document_storage.py66
-rw-r--r--addons/document/nodes.py27
-rw-r--r--addons/document/std_index.py7
7 files changed, 68 insertions, 70 deletions
diff --git a/addons/document/content_index.py b/addons/document/content_index.py
index 64b480ee736..f24c033a7ec 100644
--- a/addons/document/content_index.py
+++ b/addons/document/content_index.py
@@ -22,7 +22,7 @@ import logging
import os
import tempfile
from subprocess import Popen, PIPE
-
+_logger = logging.getLogger(__name__)
class NhException(Exception):
pass
@@ -116,7 +116,7 @@ def mime_match(mime, mdict):
return (None, None)
class contentIndex(object):
- __logger = logging.getLogger('addons.document.content_index')
+
def __init__(self):
self.mimes = {}
self.exts = {}
@@ -132,7 +132,7 @@ class contentIndex(object):
f = True
if f:
- self.__logger.debug('Register content indexer: %r', obj)
+ _logger.debug('Register content indexer: %r', obj)
if not f:
raise Exception("Your indexer should at least suport a mimetype or extension")
@@ -169,22 +169,22 @@ class contentIndex(object):
(result, _) = pop.communicate()
mime2 = result.split(';')[0]
- self.__logger.debug('File gave us: %s', mime2)
+ _logger.debug('File gave us: %s', mime2)
# Note that the temporary file still exists now.
mime,fobj = mime_match(mime2, self.mimes)
if not mime:
mime = mime2
except Exception:
- self.__logger.exception('Cannot determine mime type')
+ _logger.exception('Cannot determine mime type')
try:
if fobj:
res = (mime, fobj.indexContent(content,filename,fname or realfname) )
else:
- self.__logger.debug("Have no object, return (%s, None)", mime)
+ _logger.debug("Have no object, return (%s, None)", mime)
res = (mime, None )
except Exception:
- self.__logger.exception("Could not index file %s (%s)",
+ _logger.exception("Could not index file %s (%s)",
filename, fname or realfname)
res = None
@@ -193,8 +193,7 @@ class contentIndex(object):
try:
os.unlink(fname)
except Exception:
- self.__logger.exception("Could not unlink %s", fname)
-
+ _logger.exception("Could not unlink %s", fname)
return res
cntIndex = contentIndex()
diff --git a/addons/document/document.py b/addons/document/document.py
index 92ece063a47..fa65f8d9966 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -30,12 +30,15 @@ from tools.translate import _
import nodes
import logging
+_logger = logging.getLogger(__name__)
+
DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config['root_path'], 'filestore'))
class document_file(osv.osv):
_inherit = 'ir.attachment'
_rec_name = 'datas_fname'
-
+
+
def _attach_parent_id(self, cr, uid, ids=None, context=None):
"""Migrate ir.attachments to the document module.
@@ -54,7 +57,7 @@ class document_file(osv.osv):
parent_id = self.pool.get('document.directory')._get_root_directory(cr,uid)
if not parent_id:
- logging.getLogger('document').warning("at _attach_parent_id(), still not able to set the parent!")
+ _logger.warning("at _attach_parent_id(), still not able to set the parent!")
return False
if ids is not None:
@@ -140,8 +143,8 @@ class document_file(osv.osv):
_defaults = {
'user_id': lambda self, cr, uid, ctx:uid,
+ 'parent_id': __get_def_directory,
'file_size': lambda self, cr, uid, ctx:0,
- 'parent_id': __get_def_directory
}
_sql_constraints = [
# filename_uniq is not possible in pure SQL
@@ -336,7 +339,7 @@ class document_file(osv.osv):
if r:
unres.append(r)
else:
- logging.getLogger('document').warning("Unlinking attachment #%s %s that has no storage",
+ self.loggerdoc.warning("Unlinking attachment #%s %s that has no storage",
f.id, f.name)
res = super(document_file, self).unlink(cr, uid, ids, context)
stor.do_unlink(cr, uid, unres)
diff --git a/addons/document/document_data.xml b/addons/document/document_data.xml
index ac7a174b05f..a7bc98de6f3 100644
--- a/addons/document/document_data.xml
+++ b/addons/document/document_data.xml
@@ -104,6 +104,5 @@
<!-- After we have setup the root directory, migrate the attachments
to point to that. -->
<function model="ir.attachment" name="_attach_parent_id"/>
-
</data>
</openerp>
diff --git a/addons/document/document_directory.py b/addons/document/document_directory.py
index d09d2cc86d5..03b2dcc47bf 100644
--- a/addons/document/document_directory.py
+++ b/addons/document/document_directory.py
@@ -22,10 +22,10 @@
from osv import osv, fields
from osv.orm import except_orm
-
+import logging
import nodes
from tools.translate import _
-
+_logger = logging.getLogger(__name__)
class document_directory(osv.osv):
_name = 'document.directory'
_description = 'Directory'
@@ -78,9 +78,8 @@ class document_directory(osv.osv):
root_id = objid.read(cr, uid, mid, ['res_id'])['res_id']
return root_id
except Exception, e:
- import netsvc
- logger = netsvc.Logger()
- logger.notifyChannel("document", netsvc.LOG_WARNING, 'Cannot set directory root:'+ str(e))
+
+ _logger.warning('Cannot set directory root:'+ str(e))
return False
return objid.browse(cr, uid, mid, context=context).res_id
diff --git a/addons/document/document_storage.py b/addons/document/document_storage.py
index fe757e7876d..339b320e9a7 100644
--- a/addons/document/document_storage.py
+++ b/addons/document/document_storage.py
@@ -29,18 +29,15 @@ import logging
import shutil
from StringIO import StringIO
import psycopg2
-
from tools.misc import ustr
from tools.translate import _
-
from osv.orm import except_orm
-
import random
import string
import pooler
import nodes
from content_index import cntIndex
-
+_logger = logging.getLogger(__name__)
DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config.get('root_path'), 'filestore'))
@@ -130,7 +127,7 @@ class nodefd_file(nodes.node_descriptor):
mime, icont = cntIndex.doIndex(None, filename=filename,
content_type=None, realfname=fname)
except Exception:
- logging.getLogger('document.storage').debug('Cannot index file:', exc_info=True)
+ _logger.debug('Cannot index file:', exc_info=True)
pass
try:
@@ -150,7 +147,7 @@ class nodefd_file(nodes.node_descriptor):
cr.commit()
cr.close()
except Exception:
- logging.getLogger('document.storage').warning('Cannot save file indexed content:', exc_info=True)
+ _logger.warning('Cannot save file indexed content:', exc_info=True)
elif self.mode in ('a', 'a+' ):
try:
@@ -164,7 +161,7 @@ class nodefd_file(nodes.node_descriptor):
cr.commit()
cr.close()
except Exception:
- logging.getLogger('document.storage').warning('Cannot save file appended content:', exc_info=True)
+ _logger.warning('Cannot save file appended content:', exc_info=True)
@@ -191,7 +188,7 @@ class nodefd_db(StringIO, nodes.node_descriptor):
elif mode == 'a':
StringIO.__init__(self, None)
else:
- logging.getLogger('document.storage').error("Incorrect mode %s specified", mode)
+ _logger.error("Incorrect mode %s specified", mode)
raise IOError(errno.EINVAL, "Invalid file mode")
self.mode = mode
@@ -217,7 +214,7 @@ class nodefd_db(StringIO, nodes.node_descriptor):
mime, icont = cntIndex.doIndex(data, filename=filename,
content_type=None, realfname=None)
except Exception:
- logging.getLogger('document.storage').debug('Cannot index file:', exc_info=True)
+ _logger.debug('Cannot index file:', exc_info=True)
pass
try:
@@ -241,7 +238,7 @@ class nodefd_db(StringIO, nodes.node_descriptor):
(out, len(data), par.file_id))
cr.commit()
except Exception:
- logging.getLogger('document.storage').exception('Cannot update db file #%d for close:', par.file_id)
+ _logger.exception('Cannot update db file #%d for close:', par.file_id)
raise
finally:
cr.close()
@@ -271,7 +268,7 @@ class nodefd_db64(StringIO, nodes.node_descriptor):
elif mode == 'a':
StringIO.__init__(self, None)
else:
- logging.getLogger('document.storage').error("Incorrect mode %s specified", mode)
+ _logger.error("Incorrect mode %s specified", mode)
raise IOError(errno.EINVAL, "Invalid file mode")
self.mode = mode
@@ -297,7 +294,7 @@ class nodefd_db64(StringIO, nodes.node_descriptor):
mime, icont = cntIndex.doIndex(data, filename=filename,
content_type=None, realfname=None)
except Exception:
- logging.getLogger('document.storage').debug('Cannot index file:', exc_info=True)
+ self.logger.debug('Cannot index file:', exc_info=True)
pass
try:
@@ -320,7 +317,7 @@ class nodefd_db64(StringIO, nodes.node_descriptor):
(base64.encodestring(data), len(data), par.file_id))
cr.commit()
except Exception:
- logging.getLogger('document.storage').exception('Cannot update db file #%d for close:', par.file_id)
+ _logger.exception('Cannot update db file #%d for close:', par.file_id)
raise
finally:
cr.close()
@@ -339,7 +336,6 @@ class document_storage(osv.osv):
"""
_name = 'document.storage'
_description = 'Storage Media'
- _doclog = logging.getLogger('document')
_columns = {
'name': fields.char('Name', size=64, required=True, select=1),
@@ -402,7 +398,7 @@ class document_storage(osv.osv):
npath = filter(lambda x: x is not None, npath)
# if self._debug:
- # self._doclog.debug('Npath: %s', npath)
+ # self._logger.debug('Npath: %s', npath)
for n in npath:
if n == '..':
raise ValueError("Invalid '..' element in path")
@@ -413,7 +409,7 @@ class document_storage(osv.osv):
dpath += npath[:-1]
path = os.path.join(*dpath)
if not os.path.isdir(path):
- self._doclog.debug("Create dirs: %s", path)
+ _logger.debug("Create dirs: %s", path)
os.makedirs(path)
return path, npath
@@ -451,7 +447,7 @@ class document_storage(osv.osv):
# try to fix their directory.
if mode in ('r','r+'):
if ira.file_size:
- self._doclog.warning( "ir.attachment #%d does not have a filename, but is at filestore, fix it!" % ira.id)
+ _logger.warning( "ir.attachment #%d does not have a filename, but is at filestore, fix it!" % ira.id)
raise IOError(errno.ENOENT, 'No file can be located')
else:
store_fname = self.__get_random_fname(boo.path)
@@ -493,7 +489,7 @@ class document_storage(osv.osv):
# On a migrated db, some files may have the wrong storage type
# try to fix their directory.
if ira.file_size:
- self._doclog.warning( "ir.attachment #%d does not have a filename, but is at filestore, fix it!" % ira.id)
+ _logger.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()
@@ -517,7 +513,7 @@ class document_storage(osv.osv):
# On a migrated db, some files may have the wrong storage type
# try to fix their directory.
if ira.file_size:
- self._doclog.warning("ir.attachment #%d does not have a filename, trying the name." %ira.id)
+ _logger.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):
@@ -550,7 +546,7 @@ class document_storage(osv.osv):
if boo.readonly:
raise IOError(errno.EPERM, "Readonly medium")
- self._doclog.debug( "Store data for ir.attachment #%d" % ira.id)
+ _logger.debug( "Store data for ir.attachment #%d" % ira.id)
store_fname = None
fname = None
if boo.type == 'filestore':
@@ -563,13 +559,13 @@ class document_storage(osv.osv):
fp.write(data)
finally:
fp.close()
- self._doclog.debug( "Saved data to %s" % fname)
+ _logger.debug( "Saved data to %s" % fname)
filesize = len(data) # os.stat(fname).st_size
# TODO Here, an old file would be left hanging.
except Exception, e:
- self._doclog.warning( "Couldn't save data to %s", path, exc_info=True)
+ _logger.warning( "Couldn't save data to %s", path, exc_info=True)
raise except_orm(_('Error!'), str(e))
elif boo.type == 'db':
filesize = len(data)
@@ -592,12 +588,12 @@ class document_storage(osv.osv):
fp.write(data)
finally:
fp.close()
- self._doclog.debug("Saved data to %s", fname)
+ _logger.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 :
- self._doclog.warning("Couldn't save data:", exc_info=True)
+ _logger.warning("Couldn't save data:", exc_info=True)
raise except_orm(_('Error!'), str(e))
elif boo.type == 'virtual':
@@ -616,7 +612,7 @@ class document_storage(osv.osv):
mime, icont = cntIndex.doIndex(data, ira.datas_fname,
ira.file_type or None, fname)
except Exception:
- self._doclog.debug('Cannot index file:', exc_info=True)
+ _logger.debug('Cannot index file:', exc_info=True)
pass
try:
@@ -633,7 +629,7 @@ class document_storage(osv.osv):
file_node.content_type = mime
return True
except Exception, e :
- self._doclog.warning("Couldn't save data:", exc_info=True)
+ self._logger.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))
@@ -671,9 +667,9 @@ class document_storage(osv.osv):
try:
os.unlink(fname)
except Exception:
- self._doclog.warning("Could not remove file %s, please remove manually.", fname, exc_info=True)
+ _logger.warning("Could not remove file %s, please remove manually.", fname, exc_info=True)
else:
- self._doclog.warning("Unknown unlink key %s" % ktype)
+ _logger.warning("Unknown unlink key %s" % ktype)
return True
@@ -703,9 +699,9 @@ class document_storage(osv.osv):
fname = ira.store_fname
if not fname:
- self._doclog.warning("Trying to rename a non-stored file")
+ _logger.warning("Trying to rename a non-stored file")
if fname != os.path.join(*npath):
- self._doclog.warning("inconsistency in realstore: %s != %s" , fname, repr(npath))
+ _logger.warning("inconsistency in realstore: %s != %s" , fname, repr(npath))
oldpath = os.path.join(path, npath[-1])
newpath = os.path.join(path, new_name)
@@ -743,7 +739,7 @@ class document_storage(osv.osv):
break
par = par.parent_id
if file_node.storage_id != psto:
- self._doclog.debug('Cannot move file %r from %r to %r', file_node, file_node.parent, ndir_bro.name)
+ _logger.debug('Cannot move file %r from %r to %r', file_node, file_node.parent, ndir_bro.name)
raise NotImplementedError('Cannot move files between storage media')
if sbro.type in ('filestore', 'db', 'db64'):
@@ -756,9 +752,9 @@ class document_storage(osv.osv):
fname = ira.store_fname
if not fname:
- self._doclog.warning("Trying to rename a non-stored file")
+ _logger.warning("Trying to rename a non-stored file")
if fname != os.path.join(*opath):
- self._doclog.warning("inconsistency in realstore: %s != %s" , fname, repr(opath))
+ _logger.warning("inconsistency in realstore: %s != %s" , fname, repr(opath))
oldpath = os.path.join(path, opath[-1])
@@ -766,12 +762,12 @@ class document_storage(osv.osv):
npath = filter(lambda x: x is not None, npath)
newdir = os.path.join(*npath)
if not os.path.isdir(newdir):
- self._doclog.debug("Must create dir %s", newdir)
+ _logger.debug("Must create dir %s", newdir)
os.makedirs(newdir)
npath.append(opath[-1])
newpath = os.path.join(*npath)
- self._doclog.debug("Going to move %s from %s to %s", opath[-1], oldpath, newpath)
+ _logger.debug("Going to move %s from %s to %s", opath[-1], oldpath, newpath)
shutil.move(oldpath, newpath)
store_path = npath[1:] + [opath[-1],]
diff --git a/addons/document/nodes.py b/addons/document/nodes.py
index ee89f3d4c6c..273be7effa4 100644
--- a/addons/document/nodes.py
+++ b/addons/document/nodes.py
@@ -41,8 +41,7 @@ from StringIO import StringIO
# file: objct = ir.attachement
# root: if we are at the first directory of a ressource
#
-
-logger = logging.getLogger('doc2.nodes')
+_logger = logging.getLogger(__name__)
def _str2time(cre):
""" Convert a string with time representation (from db) into time (float)
@@ -328,7 +327,7 @@ class node_class(object):
if self.DAV_M_NS.has_key(ns):
prefix = self.DAV_M_NS[ns]
else:
- logger.debug('No namespace: %s ("%s")',ns, prop)
+ _logger.debug('No namespace: %s ("%s")',ns, prop)
return None
mname = prefix + "_" + prop.replace('-','_')
@@ -341,7 +340,7 @@ class node_class(object):
r = m(cr)
return r
except AttributeError:
- logger.debug('Property %s not supported' % prop, exc_info=True)
+ _logger.debug('Property %s not supported' % prop, exc_info=True)
return None
def get_dav_resourcetype(self, cr):
@@ -384,13 +383,13 @@ class node_class(object):
def create_child(self, cr, path, data=None):
""" Create a regular file under this node
"""
- logger.warning("Attempted to create a file under %r, not possible.", self)
+ _logger.warning("Attempted to create a file under %r, not possible.", self)
raise IOError(errno.EPERM, "Not allowed to create files here")
def create_child_collection(self, cr, objname):
""" Create a child collection (directory) under self
"""
- logger.warning("Attempted to create a collection under %r, not possible.", self)
+ _logger.warning("Attempted to create a collection under %r, not possible.", self)
raise IOError(errno.EPERM, "Not allowed to create folders here")
def rm(self, cr):
@@ -725,7 +724,7 @@ class node_dir(node_database):
assert self.parent
if self.parent != ndir_node:
- logger.debug('Cannot move dir %r from %r to %r', self, self.parent, ndir_node)
+ _logger.debug('Cannot move dir %r from %r to %r', self, self.parent, ndir_node)
raise NotImplementedError('Cannot move dir to another dir')
ret = {}
@@ -998,7 +997,7 @@ class node_res_obj(node_class):
def get_dav_eprop_DEPR(self, cr, ns, prop):
# Deprecated!
if ns != 'http://groupdav.org/' or prop != 'resourcetype':
- logger.warning("Who asked for %s:%s?" % (ns, prop))
+ _logger.warning("Who asked for %s:%s?" % (ns, prop))
return None
cntobj = self.context._dirobj.pool.get('document.directory.content')
uid = self.context.uid
@@ -1328,7 +1327,7 @@ class node_file(node_class):
ret = {}
if ndir_node and self.parent != ndir_node:
if not (isinstance(self.parent, node_dir) and isinstance(ndir_node, node_dir)):
- logger.debug('Cannot move file %r from %r to %r', self, self.parent, ndir_node)
+ _logger.debug('Cannot move file %r from %r to %r', self, self.parent, ndir_node)
raise NotImplementedError('Cannot move files between dynamic folders')
if not ndir_obj:
@@ -1452,6 +1451,7 @@ class node_content(node_class):
return ''
class nodefd_content(StringIO, node_descriptor):
+
""" A descriptor to content nodes
"""
def __init__(self, parent, cr, mode, ctx):
@@ -1473,7 +1473,7 @@ class nodefd_content(StringIO, node_descriptor):
elif mode == 'a':
StringIO.__init__(self, None)
else:
- logging.getLogger('document.content').error("Incorrect mode %s specified", mode)
+ _logger.error("Incorrect mode %s specified", mode)
raise IOError(errno.EINVAL, "Invalid file mode")
self.mode = mode
@@ -1499,13 +1499,14 @@ class nodefd_content(StringIO, node_descriptor):
raise NotImplementedError
cr.commit()
except Exception:
- logging.getLogger('document.content').exception('Cannot update db content #%d for close:', par.cnt_id)
+ _logger.exception('Cannot update db content #%d for close:', par.cnt_id)
raise
finally:
cr.close()
StringIO.close(self)
class nodefd_static(StringIO, node_descriptor):
+
""" A descriptor to nodes with static data.
"""
def __init__(self, parent, cr, mode, ctx=None):
@@ -1526,7 +1527,7 @@ class nodefd_static(StringIO, node_descriptor):
elif mode == 'a':
StringIO.__init__(self, None)
else:
- logging.getLogger('document.nodes').error("Incorrect mode %s specified", mode)
+ _logger.error("Incorrect mode %s specified", mode)
raise IOError(errno.EINVAL, "Invalid file mode")
self.mode = mode
@@ -1551,7 +1552,7 @@ class nodefd_static(StringIO, node_descriptor):
raise NotImplementedError
cr.commit()
except Exception:
- logging.getLogger('document.nodes').exception('Cannot update db content #%d for close:', par.cnt_id)
+ _logger.exception('Cannot update db content #%d for close:', par.cnt_id)
raise
finally:
cr.close()
diff --git a/addons/document/std_index.py b/addons/document/std_index.py
index e153d018bf0..49ac9a5c906 100644
--- a/addons/document/std_index.py
+++ b/addons/document/std_index.py
@@ -25,6 +25,7 @@ import StringIO
import odt2txt
import sys, zipfile, xml.dom.minidom
import logging
+_logger = logging.getLogger(__name__)
def _to_unicode(s):
try:
@@ -101,9 +102,9 @@ class DocIndex(indexer):
(data, _) = pop.communicate()
return _to_unicode(data)
except OSError:
- logger = logging.getLogger('document.DocIndex')
- logger.warn("Failed attempt to execute antiword (MS Word reader). Antiword is necessary to index the file %s of MIME type %s. Detailed error available at DEBUG level.", fname, self._getMimeTypes()[0])
- logger.debug("Trace of the failed file indexing attempt: ", exc_info=True)
+
+ _logger.warn("Failed attempt to execute antiword (MS Word reader). Antiword is necessary to index the file %s of MIME type %s. Detailed error available at DEBUG level.", fname, self._getMimeTypes()[0])
+ _logger.debug("Trace of the failed file indexing attempt: ", exc_info=True)
return False
cntIndex.register(DocIndex())