mirror of
https://github.com/odoo/runbot.git
synced 2025-03-20 18:05:46 +07:00

The previous code of runbot and runbot_cla was made for Odoo API version 8.0. This commit makes it work with Odoo API 11.0 and Python 3. Also, the present refactoring splits the code into multiple files to make it easier to read (I hope). The main change due to Python 3 is the job locking mechanism: Since PEP-446 file descriptors are non-inheritable by default. A new method (os.set_inheritable) was introduced to explicitely make fd inheritable. Also, the close_fds parameter of the subprocess.Popen method is now True by default. Finally, PEP-3151 changed the exception raised by fcntl.flock from IOError to OSError (and IOError became an alias of OSError). As a consequence of all that, the runbot locking mechanism to check if a job is finished was not working in python3.
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
from odoo import models, fields, api
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
TYPES = [(t, t.capitalize()) for t in 'client server runbot'.split()]
|
|
|
|
|
|
class runbot_event(models.Model):
|
|
|
|
_inherit = "ir.logging"
|
|
_order = 'id'
|
|
|
|
build_id = fields.Many2one('runbot.build', 'Build', index=True, ondelete='cascade')
|
|
type = fields.Selection(TYPES, string='Type', required=True, index=True)
|
|
|
|
@api.model_cr
|
|
def init(self):
|
|
parent_class = super(runbot_event, self)
|
|
if hasattr(parent_class, 'init'):
|
|
parent_class.init()
|
|
|
|
self._cr.execute("""
|
|
CREATE OR REPLACE FUNCTION runbot_set_logging_build() RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
IF (new.build_id IS NULL AND new.dbname IS NOT NULL AND new.dbname != current_database()) THEN
|
|
UPDATE ir_logging l
|
|
SET build_id = split_part(new.dbname, '-', 1)::integer
|
|
WHERE l.id = new.id;
|
|
END IF;
|
|
RETURN NULL;
|
|
END;
|
|
$$ language plpgsql;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE TRIGGER runbot_new_logging
|
|
AFTER INSERT ON ir_logging
|
|
FOR EACH ROW
|
|
EXECUTE PROCEDURE runbot_set_logging_build();
|
|
EXCEPTION
|
|
WHEN duplicate_object THEN
|
|
END;
|
|
$$;
|
|
""")
|