<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
#    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 base64
import os
import security
import thread
import threading
import time
import sys
import platform
from openerp.tools.translate import _
import openerp.netsvc as netsvc
import openerp.pooler as pooler
import openerp.release as release
import openerp.sql_db as sql_db
import openerp.tools as tools
import openerp.modules
import locale
import logging
from cStringIO import StringIO

#.apidoc title: Exported Service methods
#.apidoc module-mods: member-order: bysource

""" This python module defines the RPC methods available to remote clients.

    Each 'Export Service' is a group of 'methods', which in turn are RPC
    procedures to be called. Each method has its own arguments footprint.
"""

class db(netsvc.ExportService):
    def __init__(self, name="db"):
        netsvc.ExportService.__init__(self, name)
        self.joinGroup("web-services")
        self.actions = {}
        self.id = 0
        self.id_protect = threading.Semaphore()

        self._pg_psw_env_var_is_set = False # on win32, pg_dump need the PGPASSWORD env var

    def dispatch(self, method, auth, params):
        if method in [ 'create', 'get_progress', 'drop', 'dump',
            'restore', 'rename',
            'change_admin_password', 'migrate_databases' ]:
            passwd = params[0]
            params = params[1:]
            security.check_super(passwd)
        elif method in [ 'db_exist', 'list', 'list_lang', 'server_version' ]:
            # params = params
            # No security check for these methods
            pass
        else:
            raise KeyError("Method not found: %s" % method)
        fn = getattr(self, 'exp_'+method)
        return fn(*params)

    def new_dispatch(self,method,auth,params):
        pass
    def _create_empty_database(self, name):
        db = sql_db.db_connect('template1')
        cr = db.cursor()
        try:
            cr.autocommit(True) # avoid transaction block
            cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "template0" """ % name)
        finally:
            cr.close()

    def _initialize_db(self, serv, id, db_name, demo, lang, user_password='<PASSWORD>'):
        cr = None
        try:
            serv.actions[id]['progress'] = 0
            cr = sql_db.db_connect(db_name).cursor()
            openerp.modules.db.initialize(cr) # TODO this should be removed as it is done by pooler.restart_pool.
            tools.config['lang'] = lang
            cr.commit()
            cr.close()

            pool = pooler.restart_pool(db_name, demo, serv.actions[id],
                                       update_module=True)[1]

            cr = sql_db.db_connect(db_name).cursor()

            if lang:
                modobj = pool.get('ir.module.module')
                mids = modobj.search(cr, 1, [('state', '=', 'installed')])
                modobj.update_translations(cr, 1, mids, lang)

            cr.execute('UPDATE res_users SET password=%s, context_lang=%s, active=True WHERE login=%s', (
                user_password, lang, 'admin'))
            cr.execute('SELECT login, password, name ' \
                       '  FROM res_users ' \
                       ' ORDER BY login')
            serv.actions[id]['users'] = cr.dictfetchall()
            serv.actions[id]['clean'] = True
            cr.commit()
            cr.close()
        except Exception, e:
            serv.actions[id]['clean'] = False
            serv.actions[id]['exception'] = e
            import traceback
            e_str = StringIO()
            traceback.print_exc(file=e_str)
            traceback_str = e_str.getvalue()
            e_str.close()
            netsvc.Logger().notifyChannel('web-services', netsvc.LOG_ERROR, 'CREATE DATABASE\n%s' % (traceback_str))
            serv.actions[id]['traceback'] = traceback_str
            if cr:
                cr.close()

    def exp_create(self, db_name, demo, lang, user_password='<PASSWORD>'):
        self.id_protect.acquire()
        self.id += 1
        id = self.id
        self.id_protect.release()
<commit_msg>[IMP] use dict.update instead of __setitem__ sequences<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
#    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 base64
import os
import security
import thread
import threading
import time
import sys
import platform
from openerp.tools.translate import _
import openerp.netsvc as netsvc
import openerp.pooler as pooler
import openerp.release as release
import openerp.sql_db as sql_db
import openerp.tools as tools
import openerp.modules
import locale
import logging
from cStringIO import StringIO

#.apidoc title: Exported Service methods
#.apidoc module-mods: member-order: bysource

""" This python module defines the RPC methods available to remote clients.

    Each 'Export Service' is a group of 'methods', which in turn are RPC
    procedures to be called. Each method has its own arguments footprint.
"""

class db(netsvc.ExportService):
    def __init__(self, name="db"):
        netsvc.ExportService.__init__(self, name)
        self.joinGroup("web-services")
        self.actions = {}
        self.id = 0
        self.id_protect = threading.Semaphore()

        self._pg_psw_env_var_is_set = False # on win32, pg_dump need the PGPASSWORD env var

    def dispatch(self, method, auth, params):
        if method in [ 'create', 'get_progress', 'drop', 'dump',
            'restore', 'rename',
            'change_admin_password', 'migrate_databases' ]:
            passwd = params[0]
            params = params[1:]
            security.check_super(passwd)
        elif method in [ 'db_exist', 'list', 'list_lang', 'server_version' ]:
            # params = params
            # No security check for these methods
            pass
        else:
            raise KeyError("Method not found: %s" % method)
        fn = getattr(self, 'exp_'+method)
        return fn(*params)

    def new_dispatch(self,method,auth,params):
        pass
    def _create_empty_database(self, name):
        db = sql_db.db_connect('template1')
        cr = db.cursor()
        try:
            cr.autocommit(True) # avoid transaction block
            cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "template0" """ % name)
        finally:
            cr.close()

    def _initialize_db(self, serv, id, db_name, demo, lang, user_password='<PASSWORD>'):
        cr = None
        try:
            serv.actions[id]['progress'] = 0
            cr = sql_db.db_connect(db_name).cursor()
            openerp.modules.db.initialize(cr) # TODO this should be removed as it is done by pooler.restart_pool.
            tools.config['lang'] = lang
            cr.commit()
            cr.close()

            pool = pooler.restart_pool(db_name, demo, serv.actions[id],
                                       update_module=True)[1]

            cr = sql_db.db_connect(db_name).cursor()

            if lang:
                modobj = pool.get('ir.module.module')
                mids = modobj.search(cr, 1, [('state', '=', 'installed')])
                modobj.update_translations(cr, 1, mids, lang)

            cr.execute('UPDATE res_users SET password=%s, context_lang=%s, active=True WHERE login=%s', (
                user_password, lang, 'admin'))
            cr.execute('SELECT login, password, name ' \
                       '  FROM res_users ' \
                       ' ORDER BY login')
            serv.actions[id].update(
                users=cr.dictfetchall(),
                clean=True)
            cr.commit()
            cr.close()
        except Exception, e:
            serv.actions[id].update(
                clean=False,
                exception=e)
            import traceback
            e_str = StringIO()
            traceback.print_exc(file=e_str)
            traceback_str = e_str.getvalue()
            e_str.close()
            netsvc.Logger().notifyChannel('web-services', netsvc.LOG_ERROR, 'CREATE DATABASE\n%s' % (traceback_str))
            serv.actions[id]['traceback'] = traceback_str
            if cr:
                cr.close()

    def exp_create(self, db_name, demo, lang, user_password='<PASSWORD>'):
        self.id_protect.acquire()
        self.id += 1
        id = self.id
        self.id_protect.release()

{'fraction_non_alphanumeric': 0.13002270707868496, 'fraction_numerical': 0.004738868595122915, 'mean_word_length': 2.3947721179624666, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2863171', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2769, 'n_words': 844}