Browse Source

Merge pull request #27 from savoirfairelinux/7.0-pep8

7.0 pep8
pull/29/head
Pedro M. Baeza 10 years ago
parent
commit
7454621c47
  1. 18
      .travis.yml
  2. 6
      base_external_dbsource/base_external_dbsource.py
  3. 6
      base_external_dbsource/test/dbsource_connect.yml
  4. 2
      cron_run_manually/model/ir_cron.py
  5. 4
      disable_openerp_online/data/ir_ui_menu.xml
  6. 2
      fetchmail_attach_from_folder/match_algorithm/base.py
  7. 1
      fetchmail_attach_from_folder/match_algorithm/email_domain.py
  8. 3
      fetchmail_attach_from_folder/match_algorithm/email_exact.py
  9. 15
      fetchmail_attach_from_folder/match_algorithm/openerp_standard.py
  10. 16
      fetchmail_attach_from_folder/model/fetchmail_server.py
  11. 33
      fetchmail_attach_from_folder/model/fetchmail_server_folder.py
  12. 49
      fetchmail_attach_from_folder/wizard/attach_mail_manually.py
  13. 2
      server_environment/serv_config.py
  14. 2
      server_environment/system_info.py

18
.travis.yml

@ -1,21 +1,25 @@
language: python language: python
python: python:
- "2.7" - "2.7"
env:
- VERSION="7.0" ODOO_REPO="odoo/odoo"
- VERSION="7.0" ODOO_REPO="OCA/OCB"
virtualenv: virtualenv:
system_site_packages: true system_site_packages: true
install: install:
- git clone https://github.com/yvaucher/maintainer-quality-tools.git $HOME/maintainer-quality-tools
- export PATH=$HOME/maintainer-quality-tools/travis:$PATH
- travis_install_nightly 7.0
- pip install coveralls flake8
- pip install python-ldap
- printf '[options]\n\nrunning_env = dev' > /tmp/odoo.cfg
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly ${VERSION}
- sudo pip install python-ldap
- printf '[options]\n\nrunning_env = dev' > ${HOME}/.openerp_serverrc
script: script:
- travis_run_flake8 - travis_run_flake8
- travis_run_tests 7.0 /tmp/odoo.cfg
- travis_run_tests ${VERSION}
after_success: after_success:
coveralls coveralls

6
base_external_dbsource/base_external_dbsource.py

@ -35,14 +35,14 @@ try:
import pymssql import pymssql
CONNECTORS.append(('mssql', 'Microsoft SQL Server')) CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
assert pymssql assert pymssql
except ImportError, AssertionError:
except (ImportError, AssertionError):
_logger.info('MS SQL Server not available. Please install "pymssql"\ _logger.info('MS SQL Server not available. Please install "pymssql"\
python package.') python package.')
try: try:
import MySQLdb import MySQLdb
CONNECTORS.append(('mysql', 'MySQL')) CONNECTORS.append(('mysql', 'MySQL'))
assert MySQLdb assert MySQLdb
except ImportError, AssertionError:
except (ImportError, AssertionError):
_logger.info('MySQL not available. Please install "mysqldb"\ _logger.info('MySQL not available. Please install "mysqldb"\
python package.') python package.')
except: except:
@ -159,7 +159,7 @@ Sample connection strings:
conn = False conn = False
try: try:
conn = self.conn_open(cr, uid, obj.id) conn = self.conn_open(cr, uid, obj.id)
except Exception, e:
except Exception as e:
raise orm.except_orm(_("Connection test failed!"), raise orm.except_orm(_("Connection test failed!"),
_("Here is what we got instead:\n %s") _("Here is what we got instead:\n %s")
% tools.ustr(e)) % tools.ustr(e))

6
base_external_dbsource/test/dbsource_connect.yml

@ -2,4 +2,8 @@
Connect to local Postgres. Connect to local Postgres.
- -
!python {model: base.external.dbsource}: | !python {model: base.external.dbsource}: |
self.connection_test(cr, uid, [ref("demo_postgresql")]
from openerp.osv.orm import except_orm
try:
self.connection_test(cr, uid, [ref("demo_postgre")])
except except_orm as e:
assert e.value == u'Everything seems properly set up!'

2
cron_run_manually/model/ir_cron.py

@ -70,7 +70,7 @@ class irCron(orm.Model):
args = safe_eval('tuple(%s)' % (job['args'] or '')) args = safe_eval('tuple(%s)' % (job['args'] or ''))
method(cr, job['user_id'], *args) method(cr, job['user_id'], *args)
except psycopg2.OperationalError, e:
except psycopg2.OperationalError as e:
# User friendly error if the lock could not be claimed # User friendly error if the lock could not be claimed
if e.pgcode == '55P03': if e.pgcode == '55P03':
raise orm.except_orm( raise orm.except_orm(

4
disable_openerp_online/data/ir_ui_menu.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<openerp> <openerp>
<data> <data>
<delete model="ir.ui.menu" id="base.module_mi" />
<delete model="ir.ui.menu" id="base.menu_module_updates" />
<delete model="ir.ui.menu" search="[('parent_id', '=', ref('base.menu_management'), ('name', '=', 'Apps'))]" />
<delete model="ir.ui.menu" search="[('parent_id', '=', ref('base.menu_management'), ('name', '=', 'Updates'))]" />
</data> </data>
</openerp> </openerp>

2
fetchmail_attach_from_folder/match_algorithm/base.py

@ -20,6 +20,7 @@
# #
############################################################################## ##############################################################################
class base(object): class base(object):
name = None name = None
'''Name shown to the user''' '''Name shown to the user'''
@ -30,7 +31,6 @@ class base(object):
readonly_fields = [] readonly_fields = []
'''Fields on fetchmail_server folder that are readonly for this algorithm''' '''Fields on fetchmail_server folder that are readonly for this algorithm'''
def search_matches(self, cr, uid, conf, mail_message, mail_message_org): def search_matches(self, cr, uid, conf, mail_message, mail_message_org):
'''Returns ids found for model with mail_message''' '''Returns ids found for model with mail_message'''
return [] return []

1
fetchmail_attach_from_folder/match_algorithm/email_domain.py

@ -22,6 +22,7 @@
from email_exact import email_exact from email_exact import email_exact
class email_domain(email_exact): class email_domain(email_exact):
'''Search objects by domain name of email address. '''Search objects by domain name of email address.
Beware of match_first here, this is most likely to get it wrong (gmail)''' Beware of match_first here, this is most likely to get it wrong (gmail)'''

3
fetchmail_attach_from_folder/match_algorithm/email_exact.py

@ -24,6 +24,7 @@ from base import base
from openerp.tools.safe_eval import safe_eval from openerp.tools.safe_eval import safe_eval
from openerp.tools.mail import email_split from openerp.tools.mail import email_split
class email_exact(base): class email_exact(base):
'''Search for exactly the mailadress as noted in the email''' '''Search for exactly the mailadress as noted in the email'''
@ -36,7 +37,7 @@ class email_exact(base):
for field in fields: for field in fields:
if field in mail_message: if field in mail_message:
mailaddresses += email_split(mail_message[field]) mailaddresses += email_split(mail_message[field])
return [ addr.lower() for addr in mailaddresses ]
return [addr.lower() for addr in mailaddresses]
def _get_mailaddress_search_domain( def _get_mailaddress_search_domain(
self, conf, mail_message, operator='=', values=None): self, conf, mail_message, operator='=', values=None):

15
fetchmail_attach_from_folder/match_algorithm/openerp_standard.py

@ -21,15 +21,21 @@
############################################################################## ##############################################################################
from base import base from base import base
from openerp.tools.safe_eval import safe_eval
class openerp_standard(base): class openerp_standard(base):
'''No search at all. Use OpenERP's standard mechanism to attach mails to '''No search at all. Use OpenERP's standard mechanism to attach mails to
mail.thread objects. Note that this algorithm always matches.''' mail.thread objects. Note that this algorithm always matches.'''
name = 'OpenERP standard' name = 'OpenERP standard'
readonly_fields = ['model_field', 'mail_field', 'match_first', 'domain',
'model_order', 'flag_nonmatching']
readonly_fields = [
'model_field',
'mail_field',
'match_first',
'domain',
'model_order',
'flag_nonmatching',
]
def search_matches(self, cr, uid, conf, mail_message, mail_message_org): def search_matches(self, cr, uid, conf, mail_message, mail_message_org):
'''Always match. Duplicates will be fished out by message_id''' '''Always match. Duplicates will be fished out by message_id'''
@ -43,7 +49,8 @@ class openerp_standard(base):
folder.model_id.model, mail_message_org, folder.model_id.model, mail_message_org,
save_original=folder.server_id.original, save_original=folder.server_id.original,
strip_attachments=(not folder.server_id.attach), strip_attachments=(not folder.server_id.attach),
context=context)
context=context
)
if folder.delete_matching: if folder.delete_matching:
connection.store(msgid, '+FLAGS', '\\DELETED') connection.store(msgid, '+FLAGS', '\\DELETED')

16
fetchmail_attach_from_folder/model/fetchmail_server.py

@ -23,12 +23,11 @@
import base64 import base64
import simplejson import simplejson
from lxml import etree from lxml import etree
from openerp.osv.orm import Model, except_orm, browse_null
from openerp.osv.orm import Model, except_orm
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.osv import fields from openerp.osv import fields
from openerp.addons.fetchmail.fetchmail import _logger as logger from openerp.addons.fetchmail.fetchmail import _logger as logger
from openerp.tools.misc import UnquoteEvalContext from openerp.tools.misc import UnquoteEvalContext
from openerp.tools.safe_eval import safe_eval
class fetchmail_server(Model): class fetchmail_server(Model):
@ -95,8 +94,7 @@ class fetchmail_server(Model):
if connection.select(folder.path)[0] != 'OK': if connection.select(folder.path)[0] != 'OK':
logger.error( logger.error(
'Could not open mailbox %s on %s' % (
folder.path, this.server))
'Could not open mailbox %s on %s' % (folder.path, this.server))
connection.select() connection.select()
continue continue
result, msgids = this.get_msgids(connection) result, msgids = this.get_msgids(connection)
@ -130,15 +128,15 @@ class fetchmail_server(Model):
if result != 'OK': if result != 'OK':
logger.error( logger.error(
'Could not fetch %s in %s on %s' % (
msgid, folder.path, this.server))
'Could not fetch %s in %s on %s' % (msgid, folder.path, this.server))
continue continue
mail_message = self.pool.get('mail.thread').message_parse( mail_message = self.pool.get('mail.thread').message_parse(
cr, uid, msgdata[0][1], save_original=this.original, cr, uid, msgdata[0][1], save_original=this.original,
context=context) context=context)
if self.pool.get('mail.message').search(cr, uid, [
if self.pool.get('mail.message').search(
cr, uid, [
('message_id', '=', mail_message['message_id'])]): ('message_id', '=', mail_message['message_id'])]):
continue continue
@ -156,7 +154,7 @@ class fetchmail_server(Model):
msgdata[0][1], msgid, context) msgdata[0][1], msgid, context)
cr.execute('release savepoint apply_matching') cr.execute('release savepoint apply_matching')
matched_object_ids += found_ids[:1] matched_object_ids += found_ids[:1]
except Exception, e:
except Exception:
cr.execute('rollback to savepoint apply_matching') cr.execute('rollback to savepoint apply_matching')
logger.exception( logger.exception(
"Failed to fetch mail %s from %s", "Failed to fetch mail %s from %s",
@ -183,7 +181,7 @@ class fetchmail_server(Model):
cr, uid, object_id, context cr, uid, object_id, context
).partner_id.id ).partner_id.id
attachments=[]
attachments = []
if this.attach and mail_message.get('attachments'): if this.attach and mail_message.get('attachments'):
for attachment in mail_message['attachments']: for attachment in mail_message['attachments']:
fname, fcontent = attachment fname, fcontent = attachment

33
fetchmail_attach_from_folder/model/fetchmail_server_folder.py

@ -49,45 +49,55 @@ class fetchmail_server_folder(Model):
'path': fields.char( 'path': fields.char(
'Path', size=256, help='The path to your mail ' 'Path', size=256, help='The path to your mail '
"folder. Typically would be something like 'INBOX.myfolder'", "folder. Typically would be something like 'INBOX.myfolder'",
required=True),
required=True
),
'model_id': fields.many2one( 'model_id': fields.many2one(
'ir.model', 'Model', required=True, 'ir.model', 'Model', required=True,
help='The model to attach emails to'),
help='The model to attach emails to'
),
'model_field': fields.char( 'model_field': fields.char(
'Field (model)', size=128, 'Field (model)', size=128,
help='The field in your model that contains the field to match ' help='The field in your model that contains the field to match '
'against.\n' 'against.\n'
'Examples:\n' 'Examples:\n'
"'email' if your model is res.partner, or " "'email' if your model is res.partner, or "
"'partner_id.email' if you're matching sale orders"),
"'partner_id.email' if you're matching sale orders"
),
'model_order': fields.char( 'model_order': fields.char(
'Order (model)', size=128, 'Order (model)', size=128,
help='Fields to order by, this mostly useful in conjunction ' help='Fields to order by, this mostly useful in conjunction '
"with 'Use 1st match'"),
"with 'Use 1st match'"
),
'match_algorithm': fields.selection( 'match_algorithm': fields.selection(
_get_match_algorithms_sel, _get_match_algorithms_sel,
'Match algorithm', required=True, translate=True, 'Match algorithm', required=True, translate=True,
help='The algorithm used to determine which object an email ' help='The algorithm used to determine which object an email '
'matches.'),
'matches.'
),
'mail_field': fields.char( 'mail_field': fields.char(
'Field (email)', size=128, 'Field (email)', size=128,
help='The field in the email used for matching. Typically ' help='The field in the email used for matching. Typically '
"this is 'to' or 'from'"),
"this is 'to' or 'from'"
),
'server_id': fields.many2one('fetchmail.server', 'Server'), 'server_id': fields.many2one('fetchmail.server', 'Server'),
'delete_matching': fields.boolean( 'delete_matching': fields.boolean(
'Delete matches', 'Delete matches',
help='Delete matched emails from server'),
help='Delete matched emails from server'
),
'flag_nonmatching': fields.boolean( 'flag_nonmatching': fields.boolean(
'Flag nonmatching', 'Flag nonmatching',
help="Flag emails in the server that don't match any object " help="Flag emails in the server that don't match any object "
'in OpenERP'),
'in OpenERP'
),
'match_first': fields.boolean( 'match_first': fields.boolean(
'Use 1st match', 'Use 1st match',
help='If there are multiple matches, use the first one. If ' help='If there are multiple matches, use the first one. If '
'not checked, multiple matches count as no match at all'),
'not checked, multiple matches count as no match at all'
),
'domain': fields.char( 'domain': fields.char(
'Domain', size=128, help='Fill in a search ' 'Domain', size=128, help='Fill in a search '
'filter to narrow down objects to match'),
'filter to narrow down objects to match'
),
'msg_state': fields.selection( 'msg_state': fields.selection(
[ [
('sent', 'Sent'), ('sent', 'Sent'),
@ -95,7 +105,8 @@ class fetchmail_server_folder(Model):
], ],
'Message state', 'Message state',
help='The state messages fetched from this folder should be ' help='The state messages fetched from this folder should be '
'assigned in OpenERP'),
'assigned in OpenERP'
),
} }
_defaults = { _defaults = {

49
fetchmail_attach_from_folder/wizard/attach_mail_manually.py

@ -22,6 +22,8 @@
from openerp.osv import fields from openerp.osv import fields
from openerp.osv.orm import TransientModel from openerp.osv.orm import TransientModel
import logging
logger = logging.getLogger(__name__)
class attach_mail_manually(TransientModel): class attach_mail_manually(TransientModel):
@ -38,32 +40,36 @@ class attach_mail_manually(TransientModel):
if context is None: if context is None:
context = {} context = {}
defaults = super(attach_mail_manually, self).default_get(cr, uid,
fields_list, context)
defaults = super(attach_mail_manually, self).default_get(
cr, uid, fields_list, context
)
for folder in self.pool.get('fetchmail.server.folder').browse(cr, uid,
for folder in self.pool.get('fetchmail.server.folder').browse(
cr, uid,
[context.get('default_folder_id')], context): [context.get('default_folder_id')], context):
defaults['mail_ids']=[]
defaults['mail_ids'] = []
connection = folder.server_id.connect() connection = folder.server_id.connect()
connection.select(folder.path) connection.select(folder.path)
result, msgids = connection.search(None,
result, msgids = connection.search(
None,
'FLAGGED' if folder.flag_nonmatching else 'UNDELETED') 'FLAGGED' if folder.flag_nonmatching else 'UNDELETED')
if result != 'OK': if result != 'OK':
logger.error('Could not search mailbox %s on %s' % ( logger.error('Could not search mailbox %s on %s' % (
folder.path, this.server))
folder.path, folder.server_id.name))
continue continue
attach_mail_manually_mail._columns['object_id'].selection=[
attach_mail_manually_mail._columns['object_id'].selection = [
(folder.model_id.model, folder.model_id.name)] (folder.model_id.model, folder.model_id.name)]
for msgid in msgids[0].split(): for msgid in msgids[0].split():
result, msgdata = connection.fetch(msgid, '(RFC822)') result, msgdata = connection.fetch(msgid, '(RFC822)')
if result != 'OK': if result != 'OK':
logger.error('Could not fetch %s in %s on %s' % ( logger.error('Could not fetch %s in %s on %s' % (
msgid, folder.path, this.server))
msgid, folder.path, folder.server_id.name))
continue continue
mail_message = self.pool.get('mail.thread').message_parse( mail_message = self.pool.get('mail.thread').message_parse(
cr, uid, msgdata[0][1], cr, uid, msgdata[0][1],
save_original=folder.server_id.original, save_original=folder.server_id.original,
context=context)
context=context
)
defaults['mail_ids'].append((0, 0, { defaults['mail_ids'].append((0, 0, {
'msgid': msgid, 'msgid': msgid,
'subject': mail_message.get('subject', ''), 'subject': mail_message.get('subject', ''),
@ -82,7 +88,7 @@ class attach_mail_manually(TransientModel):
result, msgdata = connection.fetch(mail.msgid, '(RFC822)') result, msgdata = connection.fetch(mail.msgid, '(RFC822)')
if result != 'OK': if result != 'OK':
logger.error('Could not fetch %s in %s on %s' % ( logger.error('Could not fetch %s in %s on %s' % (
msgid, folder.path, this.server))
mail.msgid, this.folder_id.path, this.server))
continue continue
mail_message = self.pool.get('mail.thread').message_parse( mail_message = self.pool.get('mail.thread').message_parse(
@ -90,12 +96,15 @@ class attach_mail_manually(TransientModel):
save_original=this.folder_id.server_id.original, save_original=this.folder_id.server_id.original,
context=context) context=context)
this.folder_id.server_id.attach_mail(connection,
this.folder_id.server_id.attach_mail(
connection,
mail.object_id.id, this.folder_id, mail_message, mail.object_id.id, this.folder_id, mail_message,
mail.msgid)
mail.msgid
)
connection.close() connection.close()
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
class attach_mail_manually_mail(TransientModel): class attach_mail_manually_mail(TransientModel):
_name = 'fetchmail.attach.mail.manually.mail' _name = 'fetchmail.attach.mail.manually.mail'
@ -105,10 +114,16 @@ class attach_mail_manually_mail(TransientModel):
'msgid': fields.char('Message id', size=16, readonly=True), 'msgid': fields.char('Message id', size=16, readonly=True),
'subject': fields.char('Subject', size=128, readonly=True), 'subject': fields.char('Subject', size=128, readonly=True),
'date': fields.datetime('Date', readonly=True), 'date': fields.datetime('Date', readonly=True),
'object_id': fields.reference('Object',
selection=lambda self, cr, uid, context:
[(m.model, m.name) for m in
self.pool.get('ir.model').browse(cr, uid,
'object_id': fields.reference(
'Object',
selection=lambda self, cr, uid, context: [
(m.model, m.name)
for m in self.pool.get('ir.model').browse(
cr, uid,
self.pool.get('ir.model').search(cr, uid, []), self.pool.get('ir.model').search(cr, uid, []),
context)], size=128),
context
)
],
size=128,
),
} }

2
server_environment/serv_config.py

@ -93,7 +93,7 @@ def _load_config():
config_p.optionxform = str config_p.optionxform = str
try: try:
config_p.read(conf_files) config_p.read(conf_files)
except Exception, e:
except Exception as e:
raise Exception('Cannot read config files "%s": %s' % (conf_files, e)) raise Exception('Cannot read config files "%s": %s' % (conf_files, e))
return config_p return config_p

2
server_environment/system_info.py

@ -38,7 +38,7 @@ def get_server_environment():
# inspired by server/bin/service/web_services.py # inspired by server/bin/service/web_services.py
try: try:
rev_id = _get_output('bzr revision-info') rev_id = _get_output('bzr revision-info')
except Exception, e:
except Exception as e:
rev_id = 'Exception: %s' % (e,) rev_id = 'Exception: %s' % (e,)
os_lang = '.'.join([x for x in locale.getdefaultlocale() if x]) os_lang = '.'.join([x for x in locale.getdefaultlocale() if x])

Loading…
Cancel
Save