From a748e4a9cc36795bf215c6da27405b19d0345167 Mon Sep 17 00:00:00 2001 From: Atte Isopuro Date: Tue, 5 Jun 2018 13:57:04 +0300 Subject: [PATCH] [11.0][MIG] Migrate dead_mans_switch_client to 11.0 - Model ir.cron has changed slightly - urllib2 no longer exists in Python 3 - Strings given to urllib.requests.Request must be encoded as bytes --- dead_mans_switch_client/__init__.py | 1 - dead_mans_switch_client/__manifest__.py | 2 +- dead_mans_switch_client/data/ir_actions.xml | 1 - dead_mans_switch_client/data/ir_cron.xml | 5 +++-- .../models/dead_mans_switch_client.py | 15 +++++++-------- .../tests/test_dead_mans_switch_client.py | 1 - 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/dead_mans_switch_client/__init__.py b/dead_mans_switch_client/__init__.py index 915f58d4d..8b959ae65 100644 --- a/dead_mans_switch_client/__init__.py +++ b/dead_mans_switch_client/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/dead_mans_switch_client/__manifest__.py b/dead_mans_switch_client/__manifest__.py index bb9e3c6af..c87605b44 100644 --- a/dead_mans_switch_client/__manifest__.py +++ b/dead_mans_switch_client/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Dead man's switch (client)", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Therp BV, Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Monitoring", diff --git a/dead_mans_switch_client/data/ir_actions.xml b/dead_mans_switch_client/data/ir_actions.xml index 017f44dc4..952c79a4d 100644 --- a/dead_mans_switch_client/data/ir_actions.xml +++ b/dead_mans_switch_client/data/ir_actions.xml @@ -5,7 +5,6 @@ context="{'default_key': 'dead_mans_switch_client.url'}"/> Configure the dead man's switch server - automatic diff --git a/dead_mans_switch_client/data/ir_cron.xml b/dead_mans_switch_client/data/ir_cron.xml index 7e04c2fb4..94f01eb28 100644 --- a/dead_mans_switch_client/data/ir_cron.xml +++ b/dead_mans_switch_client/data/ir_cron.xml @@ -5,7 +5,8 @@ 5 minutes -1 - dead.mans.switch.client - alive + + code + model.alive() diff --git a/dead_mans_switch_client/models/dead_mans_switch_client.py b/dead_mans_switch_client/models/dead_mans_switch_client.py index 9f11ac3dc..712357c53 100644 --- a/dead_mans_switch_client/models/dead_mans_switch_client.py +++ b/dead_mans_switch_client/models/dead_mans_switch_client.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015-2016 Therp BV # © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # © 2017 Avoin.Systems - Miku Laitinen @@ -10,7 +9,7 @@ try: import psutil except ImportError: # pragma: no cover psutil = None -import urllib2 +import urllib from odoo import api, models from odoo.tools.config import config @@ -72,15 +71,15 @@ class DeadMansSwitchClient(models.AbstractModel): 'dead_mans_switch_client.send_timeout', SEND_TIMEOUT) data = self._get_data() logger.debug('sending %s', data) - urllib2.urlopen( - urllib2.Request( - url, - json.dumps({ + urllib.request.urlopen( + urllib.request.Request( + url=url, + data=json.dumps({ 'jsonrpc': '2.0', 'method': 'call', 'params': data, - }), - { + }).encode('utf-8'), + headers={ 'Content-Type': 'application/json', }), timeout=timeout) diff --git a/dead_mans_switch_client/tests/test_dead_mans_switch_client.py b/dead_mans_switch_client/tests/test_dead_mans_switch_client.py index dffa49a3b..365aefd90 100644 --- a/dead_mans_switch_client/tests/test_dead_mans_switch_client.py +++ b/dead_mans_switch_client/tests/test_dead_mans_switch_client.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 Therp BV # © 2017 Avoin.Systems - Miku Laitinen # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).