Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.0 pep8 #27

Merged
merged 4 commits into from
Jul 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
language: python

python:
- "2.7"

env:
- VERSION="7.0" ODOO_REPO="odoo/odoo"
- VERSION="7.0" ODOO_REPO="OCA/OCB"

virtualenv:
system_site_packages: true

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:
- travis_run_flake8
- travis_run_tests 7.0 /tmp/odoo.cfg
- travis_run_flake8
- travis_run_tests ${VERSION}

after_success:
coveralls
6 changes: 3 additions & 3 deletions base_external_dbsource/base_external_dbsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
import pymssql
CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
assert pymssql
except ImportError, AssertionError:
except (ImportError, AssertionError):
_logger.info('MS SQL Server not available. Please install "pymssql"\
python package.')
try:
import MySQLdb
CONNECTORS.append(('mysql', 'MySQL'))
assert MySQLdb
except ImportError, AssertionError:
except (ImportError, AssertionError):
_logger.info('MySQL not available. Please install "mysqldb"\
python package.')
except:
Expand Down Expand Up @@ -159,7 +159,7 @@ def connection_test(self, cr, uid, ids, context=None):
conn = False
try:
conn = self.conn_open(cr, uid, obj.id)
except Exception, e:
except Exception as e:
raise orm.except_orm(_("Connection test failed!"),
_("Here is what we got instead:\n %s")
% tools.ustr(e))
Expand Down
6 changes: 5 additions & 1 deletion base_external_dbsource/test/dbsource_connect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
Connect to local Postgres.
-
!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 changes: 1 addition & 1 deletion cron_run_manually/model/ir_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run_manually(self, cr, uid, ids, context=None):
args = safe_eval('tuple(%s)' % (job['args'] or ''))
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
if e.pgcode == '55P03':
raise orm.except_orm(
Expand Down
4 changes: 2 additions & 2 deletions disable_openerp_online/data/ir_ui_menu.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<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'))]" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change this? I prefer removal by id.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it will cause an exception when init (not update) is run twice, which travis tests do.
I don't like leaving any code that can spontaneously crash.
This is not an easy problem to solve. Either we delete with a search or we tell users to never init twice AND change the Odoo test code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a good reason indeed. OK, let's change this then.

Regards.

<delete model="ir.ui.menu" search="[('parent_id', '=', ref('base.menu_management'), ('name', '=', 'Updates'))]" />
</data>
</openerp>
4 changes: 2 additions & 2 deletions fetchmail_attach_from_folder/match_algorithm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
##############################################################################


class base(object):
name = None
'''Name shown to the user'''
Expand All @@ -30,7 +31,6 @@ class base(object):
readonly_fields = []
'''Fields on fetchmail_server folder that are readonly for this algorithm'''


def search_matches(self, cr, uid, conf, mail_message, mail_message_org):
'''Returns ids found for model with mail_message'''
return []
Expand All @@ -40,4 +40,4 @@ def handle_match(
mail_message, mail_message_org, msgid, context=None):
'''Do whatever it takes to handle a match'''
return folder.server_id.attach_mail(connection, object_id, folder,
mail_message, msgid)
mail_message, msgid)
15 changes: 8 additions & 7 deletions fetchmail_attach_from_folder/match_algorithm/email_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@

from email_exact import email_exact


class email_domain(email_exact):
'''Search objects by domain name of email address.
Beware of match_first here, this is most likely to get it wrong (gmail)'''
name = 'Domain of email address'

def search_matches(self, cr, uid, conf, mail_message, mail_message_org):
ids = super(email_domain, self).search_matches(
cr, uid, conf, mail_message, mail_message_org)
cr, uid, conf, mail_message, mail_message_org)
if not ids:
domains = []
for addr in self._get_mailaddresses(conf, mail_message):
domains.append(addr.split('@')[-1])
ids = conf.pool.get(conf.model_id.model).search(
cr, uid,
self._get_mailaddress_search_domain(
conf, mail_message,
operator='like',
values=['%@'+domain for domain in set(domains)]),
order=conf.model_order)
cr, uid,
self._get_mailaddress_search_domain(
conf, mail_message,
operator='like',
values=['%@'+domain for domain in set(domains)]),
order=conf.model_order)
return ids
9 changes: 5 additions & 4 deletions fetchmail_attach_from_folder/match_algorithm/email_exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from openerp.tools.safe_eval import safe_eval
from openerp.tools.mail import email_split


class email_exact(base):
'''Search for exactly the mailadress as noted in the email'''

Expand All @@ -36,17 +37,17 @@ def _get_mailaddresses(self, conf, mail_message):
for field in fields:
if field in mail_message:
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(
self, conf, mail_message, operator='=', values=None):
mailaddresses = values or self._get_mailaddresses(
conf, mail_message)
conf, mail_message)
if not mailaddresses:
return [(0, '=', 1)]
search_domain = ((['|'] * (len(mailaddresses) - 1)) + [
(conf.model_field, operator, addr) for addr in mailaddresses] +
safe_eval(conf.domain or '[]'))
(conf.model_field, operator, addr) for addr in mailaddresses] +
safe_eval(conf.domain or '[]'))
return search_domain

def search_matches(self, cr, uid, conf, mail_message, mail_message_org):
Expand Down
23 changes: 15 additions & 8 deletions fetchmail_attach_from_folder/match_algorithm/openerp_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
##############################################################################

from base import base
from openerp.tools.safe_eval import safe_eval


class openerp_standard(base):
'''No search at all. Use OpenERP's standard mechanism to attach mails to
mail.thread objects. Note that this algorithm always matches.'''

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):
'''Always match. Duplicates will be fished out by message_id'''
Expand All @@ -39,11 +45,12 @@ def handle_match(
self, cr, uid, connection, object_id, folder,
mail_message, mail_message_org, msgid, context):
result = folder.pool.get('mail.thread').message_process(
cr, uid,
folder.model_id.model, mail_message_org,
save_original=folder.server_id.original,
strip_attachments=(not folder.server_id.attach),
context=context)
cr, uid,
folder.model_id.model, mail_message_org,
save_original=folder.server_id.original,
strip_attachments=(not folder.server_id.attach),
context=context
)

if folder.delete_matching:
connection.store(msgid, '+FLAGS', '\\DELETED')
Expand Down
72 changes: 35 additions & 37 deletions fetchmail_attach_from_folder/model/fetchmail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@
import base64
import simplejson
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.osv import fields
from openerp.addons.fetchmail.fetchmail import _logger as logger
from openerp.tools.misc import UnquoteEvalContext
from openerp.tools.safe_eval import safe_eval


class fetchmail_server(Model):
_inherit = 'fetchmail.server'

_columns = {
'folder_ids': fields.one2many(
'fetchmail.server.folder', 'server_id', 'Folders'),
'fetchmail.server.folder', 'server_id', 'Folders'),
}

_defaults = {
Expand Down Expand Up @@ -95,20 +94,19 @@ def handle_folder(self, cr, uid, ids, connection, folder, context=None):

if connection.select(folder.path)[0] != 'OK':
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()
continue
result, msgids = this.get_msgids(connection)
if result != 'OK':
logger.error(
'Could not search mailbox %s on %s' % (
folder.path, this.server))
folder.path, this.server))
continue

for msgid in msgids[0].split():
matched_object_ids += this.apply_matching(
connection, folder, msgid, match_algorithm)
connection, folder, msgid, match_algorithm)

logger.info('finished checking for emails in %s server %s',
folder.path, this.name)
Expand All @@ -130,16 +128,16 @@ def apply_matching(self, cr, uid, ids, connection, folder, msgid,

if result != 'OK':
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

mail_message = self.pool.get('mail.thread').message_parse(
cr, uid, msgdata[0][1], save_original=this.original,
context=context)
cr, uid, msgdata[0][1], save_original=this.original,
context=context)

if self.pool.get('mail.message').search(cr, uid, [
('message_id', '=', mail_message['message_id'])]):
if self.pool.get('mail.message').search(
cr, uid, [
('message_id', '=', mail_message['message_id'])]):
continue

found_ids = match_algorithm.search_matches(
Expand All @@ -156,7 +154,7 @@ def apply_matching(self, cr, uid, ids, connection, folder, msgid,
msgdata[0][1], msgid, context)
cr.execute('release savepoint apply_matching')
matched_object_ids += found_ids[:1]
except Exception, e:
except Exception:
cr.execute('rollback to savepoint apply_matching')
logger.exception(
"Failed to fetch mail %s from %s",
Expand All @@ -183,40 +181,40 @@ def attach_mail(
cr, uid, object_id, context
).partner_id.id

attachments=[]
attachments = []
if this.attach and mail_message.get('attachments'):
for attachment in mail_message['attachments']:
fname, fcontent = attachment
if isinstance(fcontent, unicode):
fcontent = fcontent.encode('utf-8')
data_attach = {
'name': fname,
'datas': base64.b64encode(str(fcontent)),
'datas_fname': fname,
'description': _('Mail attachment'),
'res_model': folder.model_id.model,
'res_id': object_id,
}
'name': fname,
'datas': base64.b64encode(str(fcontent)),
'datas_fname': fname,
'description': _('Mail attachment'),
'res_model': folder.model_id.model,
'res_id': object_id,
}
attachments.append(
self.pool.get('ir.attachment').create(
cr, uid, data_attach, context=context))

mail_message_ids.append(
self.pool.get('mail.message').create(
cr, uid,
{
'author_id': partner_id,
'model': folder.model_id.model,
'res_id': object_id,
'type': 'email',
'body': mail_message.get('body'),
'subject': mail_message.get('subject'),
'email_from': mail_message.get('from'),
'date': mail_message.get('date'),
'message_id': mail_message.get('message_id'),
'attachment_ids': [(6, 0, attachments)],
},
context))
self.pool.get('mail.message').create(
cr, uid,
{
'author_id': partner_id,
'model': folder.model_id.model,
'res_id': object_id,
'type': 'email',
'body': mail_message.get('body'),
'subject': mail_message.get('subject'),
'email_from': mail_message.get('from'),
'date': mail_message.get('date'),
'message_id': mail_message.get('message_id'),
'attachment_ids': [(6, 0, attachments)],
},
context))

if folder.delete_matching:
connection.store(msgid, '+FLAGS', '\\DELETED')
Expand Down
Loading