summaryrefslogtreecommitdiff
path: root/addons/document
diff options
context:
space:
mode:
authorStephane Wirtel <stephane@tinyerp.com>2009-03-19 13:50:15 +0100
committerStephane Wirtel <stephane@tinyerp.com>2009-03-19 13:50:15 +0100
commite2e8b1941ed49865646edec0f2908d3aa2516277 (patch)
treeb56842f73986a4d0873943403ab4d8fce5659dd1 /addons/document
parent01c974e40da76c36f9f47102fcc5befab392cbb3 (diff)
parent8f1d6918d24dd139e0d4340c6739a41b6ff6348a (diff)
[MERGE] Branch from Christophe Chauvat (Sylëam)
[IMP] * Correct bug with locale, use string.ascii_letters instead of string.letters * Remove mixing tabs with spaces (PEP8 compliant) * Add UTF8 header in python file * Add vim comment at the end of file * Add license header that missing on many files bzr revid: stephane@tinyerp.com-20090319125015-221hyuhyb9s0vfcq
Diffstat (limited to 'addons/document')
-rw-r--r--addons/document/__init__.py2
-rw-r--r--addons/document/__terp__.py1
-rw-r--r--addons/document/content_index.py52
-rw-r--r--addons/document/document.py14
-rw-r--r--addons/document/ftpserver/__init__.py23
-rw-r--r--addons/document/ftpserver/abstracted_fs.py3
-rw-r--r--addons/document/ftpserver/authorizer.py4
-rw-r--r--addons/document/ftpserver/ftpserver.py3
-rw-r--r--addons/document/odt2txt.py46
9 files changed, 93 insertions, 55 deletions
diff --git a/addons/document/__init__.py b/addons/document/__init__.py
index 135e4ac1635..2b9d7747b91 100644
--- a/addons/document/__init__.py
+++ b/addons/document/__init__.py
@@ -22,3 +22,5 @@
import document
import ftpserver
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/__terp__.py b/addons/document/__terp__.py
index f7e326bbc65..27c917f3deb 100644
--- a/addons/document/__terp__.py
+++ b/addons/document/__terp__.py
@@ -45,4 +45,5 @@
'active': False,
'certificate': '0070515416461',
}
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/content_index.py b/addons/document/content_index.py
index 96297ff7a8b..a8d864905f4 100644
--- a/addons/document/content_index.py
+++ b/addons/document/content_index.py
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
-# OpenERP, Open Source Management Solution
+# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@@ -29,27 +29,29 @@ import tempfile
# This should be the indexer
#
def content_index(content, filename=None, content_type=None):
- fname,ext = os.path.splitext(filename)
- result = ''
- if ext in ('.doc'): #or content_type ?
- (stdin,stdout) = os.popen2('antiword -', 'b')
- stdin.write(content)
- stdin.close()
- result = stdout.read().decode('latin1','replace').encode('utf-8','replace')
- elif ext == '.pdf':
- file_descriptor, file_name = tempfile.mkstemp(suffix=ext)
- os.write(file_descriptor, content)
- os.close(file_descriptor)
- fp = os.popen('pdftotext -enc UTF-8 -nopgbrk '+file_name+' -', 'r')
- result = fp.read()
- fp.close()
- elif ext in ('.xls','.ods','.odt','.odp'):
- s = StringIO.StringIO(content)
- o = odt2txt.OpenDocumentTextFile(s)
- result = o.toString().encode('ascii','replace')
- s.close()
- elif ext in ('.txt','.py','.patch','.html','.csv','.xml'):
- result = content
- else:
- result = content
- return result
+ fname,ext = os.path.splitext(filename)
+ result = ''
+ if ext in ('.doc'): #or content_type ?
+ (stdin,stdout) = os.popen2('antiword -', 'b')
+ stdin.write(content)
+ stdin.close()
+ result = stdout.read().decode('latin1','replace').encode('utf-8','replace')
+ elif ext == '.pdf':
+ file_descriptor, file_name = tempfile.mkstemp(suffix=ext)
+ os.write(file_descriptor, content)
+ os.close(file_descriptor)
+ fp = os.popen('pdftotext -enc UTF-8 -nopgbrk '+file_name+' -', 'r')
+ result = fp.read()
+ fp.close()
+ elif ext in ('.xls','.ods','.odt','.odp'):
+ s = StringIO.StringIO(content)
+ o = odt2txt.OpenDocumentTextFile(s)
+ result = o.toString().encode('ascii','replace')
+ s.close()
+ elif ext in ('.txt','.py','.patch','.html','.csv','.xml'):
+ result = content
+ else:
+ result = content
+ return result
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/document.py b/addons/document/document.py
index e86d90e4643..31ab13ae4df 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -492,11 +492,11 @@ class document_file(osv.osv):
result = {}
cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str,ids))+')')
for id,r,l in cr.fetchall():
- try:
- value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()
- result[id] = base64.encodestring(value)
- except:
- result[id]=''
+ try:
+ value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()
+ result[id] = base64.encodestring(value)
+ except:
+ result[id]=''
if context.get('bin_size', False):
result[id] = tools.human_size(len(result[id]))
@@ -581,7 +581,7 @@ class document_file(osv.osv):
res_id=file.res_id and file.res_id or 0
res=self.search(cr,uid,[('id','<>',file.id),('name','=',name),('parent_id','=',parent_id),('res_model','=',res_model),('res_id','=',res_id)])
if len(res):
- return False
+ return False
if op=='create':
res=self.search(cr,uid,[('name','=',name),('parent_id','=',parent_id),('res_id','=',res_id),('res_model','=',res_model)])
if len(res):
@@ -771,3 +771,5 @@ class document_configuration_wizard(osv.osv_memory):
'target':'new',
}
document_configuration_wizard()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/ftpserver/__init__.py b/addons/document/ftpserver/__init__.py
index dcac53d6061..35d1107ad81 100644
--- a/addons/document/ftpserver/__init__.py
+++ b/addons/document/ftpserver/__init__.py
@@ -1,3 +1,25 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+# $Id$
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
import threading
import ftpserver
import authorizer
@@ -31,3 +53,4 @@ class ftp_server(threading.Thread):
ds = ftp_server()
ds.start()
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py
index 9b8b78b6e8a..155c68ae515 100644
--- a/addons/document/ftpserver/abstracted_fs.py
+++ b/addons/document/ftpserver/abstracted_fs.py
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
import os
import time
from tarfile import filemode
@@ -788,3 +790,4 @@ class abstracted_fs:
yield "%s%s%s%s%s%s%s%s%s %s\r\n" %(type, size, perm, modify, create,
mode, uid, gid, unique, basename)
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/ftpserver/authorizer.py b/addons/document/ftpserver/authorizer.py
index fa45f0c3183..5a64ca8f7a0 100644
--- a/addons/document/ftpserver/authorizer.py
+++ b/addons/document/ftpserver/authorizer.py
@@ -1,4 +1,4 @@
-#import pooler
+# -*- encoding: utf-8 -*-
class authorizer:
read_perms = "elr"
@@ -68,4 +68,4 @@ class authorizer:
"""Return the user's quitting message."""
return 'Bye.'
-
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/ftpserver/ftpserver.py b/addons/document/ftpserver/ftpserver.py
index 07f60344b74..ae0fc38e1e1 100644
--- a/addons/document/ftpserver/ftpserver.py
+++ b/addons/document/ftpserver/ftpserver.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
# ftpserver.py
#
# pyftpdlib is released under the MIT license, reproduced below:
@@ -3094,3 +3095,5 @@ def test():
if __name__ == '__main__':
test()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document/odt2txt.py b/addons/document/odt2txt.py
index 7cc10bf04cd..55c228498fa 100644
--- a/addons/document/odt2txt.py
+++ b/addons/document/odt2txt.py
@@ -2,7 +2,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
-# OpenERP, Open Source Management Solution
+# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@@ -25,28 +25,30 @@ import sys, zipfile, xml.dom.minidom
import StringIO
class OpenDocumentTextFile :
- def __init__ (self, filepath) :
- zip = zipfile.ZipFile(filepath)
- self.content = xml.dom.minidom.parseString(zip.read("content.xml"))
+ def __init__ (self, filepath) :
+ zip = zipfile.ZipFile(filepath)
+ self.content = xml.dom.minidom.parseString(zip.read("content.xml"))
- def toString (self) :
- """ Converts the document to a string. """
- buffer = u""
- for val in ["text:p", "text:h", "text:list"]:
- for paragraph in self.content.getElementsByTagName(val) :
- buffer += self.textToString(paragraph) + "\n"
- return buffer
+ def toString (self) :
+ """ Converts the document to a string. """
+ buffer = u""
+ for val in ["text:p", "text:h", "text:list"]:
+ for paragraph in self.content.getElementsByTagName(val) :
+ buffer += self.textToString(paragraph) + "\n"
+ return buffer
- def textToString(self, element) :
- buffer = u""
- for node in element.childNodes :
- if node.nodeType == xml.dom.Node.TEXT_NODE :
- buffer += node.nodeValue
- elif node.nodeType == xml.dom.Node.ELEMENT_NODE :
- buffer += self.textToString(node)
- return buffer
+ def textToString(self, element) :
+ buffer = u""
+ for node in element.childNodes :
+ if node.nodeType == xml.dom.Node.TEXT_NODE :
+ buffer += node.nodeValue
+ elif node.nodeType == xml.dom.Node.ELEMENT_NODE :
+ buffer += self.textToString(node)
+ return buffer
if __name__ == "__main__" :
- s =StringIO.StringIO(file(sys.argv[1]).read())
- odt = OpenDocumentTextFile(s)
- print odt.toString().encode('ascii','replace')
+ s =StringIO.StringIO(file(sys.argv[1]).read())
+ odt = OpenDocumentTextFile(s)
+ print odt.toString().encode('ascii','replace')
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: