[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
This commit is contained in:
Stephane Wirtel
2009-03-19 13:50:15 +01:00
10 changed files with 95 additions and 55 deletions
+2
View File
@@ -22,3 +22,5 @@
import document
import ftpserver
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+1
View File
@@ -45,4 +45,5 @@
'active': False,
'certificate': '0070515416461',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+27 -25
View File
@@ -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:
+8 -6
View File
@@ -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:
+23
View File
@@ -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:
@@ -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:
+2 -2
View File
@@ -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:
+3
View File
@@ -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:
+24 -22
View File
@@ -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:
+2
View File
@@ -21,3 +21,5 @@
##############################################################################
import document
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: