<commit_before>"""Utilities to start a server process."""
import warnings
import sys
import logging
try:
    import openerp
except ImportError:
    warnings.warn("This must be imported with a buildout openerp recipe "
                  "driven sys.path", RuntimeWarning)
else:
    from openerp.cli import server as startup
    from openerp.tools import config
from optparse import OptionParser  # we support python >= 2.6

logger = logging.getLogger(__name__)


class Session(object):
    """A class to represent the server object.

    you should have exactly one per process.

    Before actual use, call the ``bootstrap`` method.
    Then you have useful attributes/methods behaving like unit test classes:

    self.cr: a cursor
    self.uid: user id
    """

    def __init__(self, conffile):
        self._registry = self.cr = None
        config.parse_config(['-c', conffile])

    def ready(self):
        return self._registry is not None

    def open(self, db=None):
        if db is None:
            db = config['db_name']
        if not db:
            db = ''  # default to OpenERP/psycopg2/lipbq default behaviour
        startup.check_root_user()
        startup.check_postgres_user()
        openerp.netsvc.init_logger()
        self._registry = openerp.modules.registry.RegistryManager.get(
            db, update_module=False)
        self.init_cursor()

    def init_cursor(self):
        self.cr = self._registry.db.cursor()

    def registry(self, model):
        """Return the model object."""
        return self._registry.get(model)

    def rollback(self):
        self.cr.rollback()

    def close(self):
        self.cr.close()

    def handle_command_line_options(self, to_handle):
        """Handle prescribed command line options and eat them.

        Anything before first occurrence of '--' is ours and removed from<commit_msg>launchpad #1222482 (upgrade toolkit): Session method to update modules list<commit_after>"""Utilities to start a server process."""
import warnings
import sys
import logging
try:
    import openerp
except ImportError:
    warnings.warn("This must be imported with a buildout openerp recipe "
                  "driven sys.path", RuntimeWarning)
else:
    from openerp.cli import server as startup
    from openerp.tools import config
    from openerp import SUPERUSER_ID
from optparse import OptionParser  # we support python >= 2.6

logger = logging.getLogger(__name__)


class Session(object):
    """A class to represent the server object.

    you should have exactly one per process.

    Before actual use, call the ``bootstrap`` method.
    Then you have useful attributes/methods behaving like unit test classes:

    self.cr: a cursor
    self.uid: user id
    """

    def __init__(self, conffile):
        self._registry = self.cr = None
        config.parse_config(['-c', conffile])

    def ready(self):
        return self._registry is not None

    def open(self, db=None):
        if db is None:
            db = config['db_name']
        if not db:
            db = ''  # default to OpenERP/psycopg2/lipbq default behaviour
        startup.check_root_user()
        startup.check_postgres_user()
        openerp.netsvc.init_logger()
        self._registry = openerp.modules.registry.RegistryManager.get(
            db, update_module=False)
        self.init_cursor()
        self.uid = SUPERUSER_ID

    def update_modules_list(self):
        """Update the list of available OpenERP modules, like the UI allows to.

        This is necessary prior to install of any new module.
        """
        self.registry('ir.module.module').update_list(self.cr, self.uid)

    def init_cursor(self):
        self.cr = self._registry.db.cursor()

    def registry(self, model):
        """Return the model object."""
        return self._registry.get(model)

    def rollback(self):
        self.cr.rollback()

    def close(self):
        self.cr.close()

    def handle_command_line_options(self, to_handle):
        """Handle prescribed command line options and eat them.

        Anything before first occurrence of '--' is ours and removed from
{'fraction_non_alphanumeric': 0.08909929594561787, 'fraction_numerical': 0.0031561058509346927, 'mean_word_length': 2.6687444345503115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2468117', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1115, 'n_words': 380}