Exemplo n.º 1
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            log = logging.getLogger('init')
            log.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
            finally:
                fp.close()
Exemplo n.º 2
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                ext = ext.lower()
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, kind, idref, mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
                elif ext == '.js':
                    pass # .js files are valid but ignored here.
                else:
                    _logger.warning("Can't load unknown file type %s.", filename)
            finally:
                fp.close()
Exemplo n.º 3
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                ext = ext.lower()
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, kind, idref, mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
                elif ext == '.js':
                    pass # .js files are valid but ignored here.
                else:
                    _logger.warning("Can't load unknown file type %s.", filename)
            finally:
                fp.close()
Exemplo n.º 4
0
 def _import_file(self, cr, mode, f_obj, module):
     root, ext = os.path.splitext(f_obj.name)
     if ext == '.sql':
         self._sql_import(cr, f_obj)
     elif mode != 'pre-load' and ext == '.yml':
         with api.Environment.manage():
             tools.convert_yaml_import(cr, module, f_obj, 'upgrade')
     elif mode != 'pre-load' and ext == '.csv':
         tools.convert_csv_import(cr, module, f_obj.name, f_obj.read(),
                                  'upgrade')
     elif mode != 'pre-load' and ext == '.xml':
         tools.convert_xml_import(cr, module, f_obj, 'upgrade')
     else:
         _logger.error('%s extension is not supported in upgrade %sing',
                       ext, mode)
         pass
Exemplo n.º 5
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """

        skip_list = []
        ignore_xml_on_installed = package.data.get('ignore_xml_on_installed')
        if ignore_xml_on_installed:
            check_modules = ignore_xml_on_installed.keys()
            if check_modules:
                cr.execute(''' SELECT name FROM ir_module_module
                 WHERE name = ANY(ARRAY%s)
                 AND state in ('installed','to_upgrade')''' % check_modules)
                for installed_module, in cr.fetchall():
                    skip_list.extend(ignore_xml_on_installed[installed_module])

        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            if filename in skip_list:
                continue
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname,
                                             fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode,
                                              noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode,
                                             noupdate, report)
            finally:
                fp.close()
Exemplo n.º 6
0
def load_data(cr, module_name, filename, idref=None, mode='init'):
    """
    Load an xml, csv or yml data file from your post script. The usual case for
    this is the
    occurrence of newly added essential or useful data in the module that is
    marked with "noupdate='1'" and without "forcecreate='1'" so that it will
    not be loaded by the usual upgrade mechanism. Leaving the 'mode' argument
    to its default 'init' will load the data from your migration script.

    Theoretically, you could simply load a stock file from the module, but be
    careful not to reinitialize any data that could have been customized.
    Preferably, select only the newly added items. Copy these to a file
    in your migrations directory and load that file.
    Leave it to the user to actually delete existing resources that are
    marked with 'noupdate' (other named items will be deleted
    automatically).


    :param module_name: the name of the module
    :param filename: the path to the filename, relative to the module \
    directory.
    :param idref: optional hash with ?id mapping cache?
    :param mode: one of 'init', 'update', 'demo'. Always use 'init' \
    for adding new items from files that are marked with 'noupdate'. Defaults \
    to 'init'.
    """

    if idref is None:
        idref = {}
    logger.info('%s: loading %s' % (module_name, filename))
    _, ext = os.path.splitext(filename)
    pathname = os.path.join(module_name, filename)
    fp = tools.file_open(pathname)
    try:
        if ext == '.csv':
            noupdate = True
            tools.convert_csv_import(
                cr, module_name, pathname, fp.read(), idref, mode, noupdate)
        elif ext == '.yml':
            yaml_import(cr, module_name, fp, None, idref=idref, mode=mode)
        else:
            tools.convert_xml_import(cr, module_name, fp, idref, mode=mode)
    finally:
        fp.close()
Exemplo n.º 7
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """

        skip_list = []
        ignore_xml_on_installed = package.data.get('ignore_xml_on_installed')
        if ignore_xml_on_installed:
            check_modules = ignore_xml_on_installed.keys()
            if check_modules:
                cr.execute(''' SELECT name FROM ir_module_module
                 WHERE name = ANY(ARRAY%s)
                 AND state in ('installed','to_upgrade')''' % check_modules)
                for installed_module, in cr.fetchall():
                    skip_list.extend(ignore_xml_on_installed[installed_module])

        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            if filename in skip_list:
                continue
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
            finally:
                fp.close()
Exemplo n.º 8
0
def load_data(cr, module_name, filename, idref=None, mode='init'):
    """
    Load an xml, csv or yml data file from your post script. The usual case for
    this is the
    occurrence of newly added essential or useful data in the module that is
    marked with "noupdate='1'" and without "forcecreate='1'" so that it will
    not be loaded by the usual upgrade mechanism. Leaving the 'mode' argument
    to its default 'init' will load the data from your migration script.

    Theoretically, you could simply load a stock file from the module, but be
    careful not to reinitialize any data that could have been customized.
    Preferably, select only the newly added items. Copy these to a file
    in your migrations directory and load that file.
    Leave it to the user to actually delete existing resources that are
    marked with 'noupdate' (other named items will be deleted
    automatically).


    :param module_name: the name of the module
    :param filename: the path to the filename, relative to the module \
    directory.
    :param idref: optional hash with ?id mapping cache?
    :param mode: one of 'init', 'update', 'demo'. Always use 'init' \
    for adding new items from files that are marked with 'noupdate'. Defaults \
    to 'init'.
    """

    if idref is None:
        idref = {}
    logger.info('%s: loading %s' % (module_name, filename))
    _, ext = os.path.splitext(filename)
    pathname = os.path.join(module_name, filename)
    fp = tools.file_open(pathname)
    try:
        if ext == '.csv':
            noupdate = True
            tools.convert_csv_import(cr, module_name, pathname, fp.read(),
                                     idref, mode, noupdate)
        elif ext == '.yml':
            yaml_import(cr, module_name, fp, None, idref=idref, mode=mode)
        else:
            tools.convert_xml_import(cr, module_name, fp, idref, mode=mode)
    finally:
        fp.close()
Exemplo n.º 9
0
def _run_test(cr, module, filename):
    _, ext = os.path.splitext(filename)
    pathname = os.path.join(module, filename)
    with tools.file_open(pathname) as fp:
        if ext == '.sql':
            if hasattr(tools, 'convert_sql_import'):
                tools.convert_sql_import(cr, fp)
            else:
                queries = fp.read().split(';')
                for query in queries:
                    new_query = ' '.join(query.split())
                    if new_query:
                        cr.execute(new_query)
        elif ext == '.csv':
            tools.convert_csv_import(cr, module, pathname, fp.read(), idref=None, mode='update', noupdate=False)
        elif ext == '.yml':
            if LooseVersion(release.major_version) >= LooseVersion('7.0'):
                tools.convert_yaml_import(cr, module, fp, kind='test', idref=None, mode='update', noupdate=False)
            else:
                tools.convert_yaml_import(cr, module, fp, idref=None, mode='update', noupdate=False)
        elif ext == '.xml':
            tools.convert_xml_import(cr, module, fp, idref=None, mode='update', noupdate=False)
Exemplo n.º 10
0
 def _load_data(self,
                module_name,
                kind='demo',
                mode='update',
                noupdate=False):
     cr = self._cr
     info = load_information_from_description_file(module_name)
     for filename in info.get(kind, []):
         _logger.info('loading %s/%s...' % (module_name, filename))
         _, ext = os.path.splitext(filename)
         pathname = os.path.join(module_name, filename)
         with tools.file_open(pathname) as fp:
             if ext == '.sql':
                 tools.convert_sql_import(cr, fp)
             elif ext == '.csv':
                 tools.convert_csv_import(cr,
                                          module_name,
                                          pathname,
                                          fp.read(),
                                          idref=None,
                                          mode=mode,
                                          noupdate=noupdate)
             elif ext == '.yml':
                 tools.convert_yaml_import(cr,
                                           module_name,
                                           fp,
                                           kind=kind,
                                           idref=None,
                                           mode=mode,
                                           noupdate=noupdate)
             elif ext == '.xml':
                 tools.convert_xml_import(cr,
                                          module_name,
                                          fp,
                                          idref=None,
                                          mode=mode,
                                          noupdate=noupdate)
     return True
Exemplo n.º 11
0
    def load_data(self, cr, uid, load=[]):
        """
        Load data defined on test case `data` attribute
        """
        module = self.get_current_instance_module()

        for file in load:

            if not isinstance(file, dict):
                data = {'module': module, 'file': file}
            else:
                data = file

            if not [name for name in ['module', 'file'] if name in data]:
                raise Exception('Test case data entry is not valid: %s', data)

            if data.get('uid', False):
                data.update({'uid': self.full_ref(data['uid'])})
            else:
                data.update({'uid': SUPERUSER_ID})
            self.log.debug("module %s: loading %s (User ID: %s)",
                           data['module'], data['file'], data['uid'])

            _, ext = os.path.splitext(data['file'])
            pathname = os.path.join(data['module'], data['file'])
            fp = tools.file_open(pathname)

            noupdate = False

            # fake these incomprehensible params...
            idref = {}
            mode = 'update'
            kind = 'data'
            report = None

            # copy from server/openerp/modules/loading.py:66...
            def process_sql_file(cr, fp):
                queries = fp.read().split(';')
                for query in queries:
                    new_query = ' '.join(query.split())
                    if new_query:
                        cr.execute(new_query)

            try:
                ext = ext.lower()
                if ext == '.csv':
                    # TODO: Migrate the feature below to v8
                    # allow to specify a user when importing data. By default,
                    # use the superuser.
                    tools.convert_csv_import(cr, module, pathname, fp.read(),
                                             idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module, fp, kind, idref,
                                              mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module, fp, idref, mode,
                                             noupdate, report)
                else:
                    self.log.warning("Can't load unknown file type %s.",
                                     data['file'])
            finally:
                fp.close()