<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 <NAME>
#    (<http://www.savoirfairelinux.com>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import os
import shutil
import re
import pwd
import time
import psutil
import signal

from contextlib import closing

import logging
_logger = logging.getLogger(__name__)
_logger.setLevel(logging.DEBUG)

from openerp import models, api, SUPERUSER_ID, tools, sql_db


def exp_list_posix_user():
    """Rewrite/simplified version of openerp.service.exp_list()
    Lists all databases owned by the current posix user instead of the db_user
    from odoo config.
    The reason for this is because runbot creates databases with the posix
    user.
    :returns list of databases owned by the posix user
    """
    chosen_template = tools.config['db_template']
    templates_list = {'template0', 'template1', 'postgres', chosen_template}
    db = sql_db.db_connect('postgres')
    with closing(db.cursor()) as cr:
        db_user = pwd.getpwuid(os.getuid())[0]
        cr.execute("""
SELECT datname
FROM pg_database
WHERE datdba=(
    SELECT usesysid
    FROM pg_user
    WHERE usename=%s
) AND datname NOT IN %s order by datname""", (db_user, tuple(templates_list)))
        res = [tools.ustr(name) for (name,) in cr.fetchall()]
    res.sort()
    return res


class RunbotRepo(models.Model):
    """Aggressively clean filesystem databases and processes."""
    _inherit = "runbot.repo"

    def __init__(self, pool, cr):
        """On reinitialisation of db, mark all builds as done"""
        super(RunbotRepo, self).__init__(pool, cr)
        runbot_build = pool['runbot.build']
        ids = pool['runbot.build'].search(cr, SUPERUSER_ID, [])
        _logger.info('marking %d builds as done', len(ids))
        runbot_build.write(cr, SUPERUSER_ID, ids, {'state': 'done'})

    @api.model
    def cron(self):
        """Overcharge cron, add clean up subroutine before the general cron."""
        self.clean_up()
        return super(RunbotRepo, self).cron()
<commit_msg>only select build which are not done at init<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
#    (<http://www.savoirfairelinux.com>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import os
import shutil
import re
import pwd
import time
import psutil
import signal

from contextlib import closing

import logging
_logger = logging.getLogger(__name__)
_logger.setLevel(logging.DEBUG)

from openerp import models, api, SUPERUSER_ID, tools, sql_db


def exp_list_posix_user():
    """Rewrite/simplified version of openerp.service.exp_list()
    Lists all databases owned by the current posix user instead of the db_user
    from odoo config.
    The reason for this is because runbot creates databases with the posix
    user.
    :returns list of databases owned by the posix user
    """
    chosen_template = tools.config['db_template']
    templates_list = {'template0', 'template1', 'postgres', chosen_template}
    db = sql_db.db_connect('postgres')
    with closing(db.cursor()) as cr:
        db_user = pwd.getpwuid(os.getuid())[0]
        cr.execute("""
SELECT datname
FROM pg_database
WHERE datdba=(
    SELECT usesysid
    FROM pg_user
    WHERE usename=%s
) AND datname NOT IN %s order by datname""", (db_user, tuple(templates_list)))
        res = [tools.ustr(name) for (name,) in cr.fetchall()]
    res.sort()
    return res


class RunbotRepo(models.Model):
    """Aggressively clean filesystem databases and processes."""
    _inherit = "runbot.repo"

    def __init__(self, pool, cr):
        """On reinitialisation of db, mark all builds as done"""
        super(RunbotRepo, self).__init__(pool, cr)
        runbot_build = pool['runbot.build']
        ids = pool['runbot.build'].search(cr, SUPERUSER_ID, [('state', '!=', 'done')])
        _logger.info('marking %d builds as done', len(ids))
        runbot_build.write(cr, SUPERUSER_ID, ids, {'state': 'done'})

    @api.model
    def cron(self):
        """Overcharge cron, add clean up subroutine before the general cron."""
        self.clean_up()
        return super(RunbotRepo, self).cron()

{'fraction_non_alphanumeric': 0.14731990440423354, 'fraction_numerical': 0.004438374871969956, 'mean_word_length': 3.690952762209768, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4315601', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1646, 'n_words': 609}