Example #1
0
 def _run_test(self, cr, module_name, filename):
     _, ext = os.path.splitext(filename)
     pathname = os.path.join(module_name, filename)
     open_file = tools.file_open(pathname)
     if ext == '.sql':
         queries = open_file.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_name,
                                  pathname,
                                  open_file.read(),
                                  idref=None,
                                  mode='update',
                                  noupdate=False)
     elif ext == '.yml':
         tools.convert_yaml_import(cr,
                                   module_name,
                                   open_file,
                                   idref=None,
                                   mode='update',
                                   noupdate=False)
     else:
         tools.convert_xml_import(cr,
                                  module_name,
                                  open_file,
                                  idref=None,
                                  mode='update',
                                  noupdate=False)
Example #2
0
 def load_init_update_xml(cr, m, idref, mode, kind):
     for filename in package.data.get('%s_xml' % kind, []):
         logger.notifyChannel('init', netsvc.LOG_INFO,
                              'module %s: loading %s' % (m, filename))
         _, ext = os.path.splitext(filename)
         fp = tools.file_open(opj(m, filename))
         try:
             if ext == '.csv':
                 noupdate = (kind == 'init')
                 tools.convert_csv_import(cr,
                                          m,
                                          os.path.basename(filename),
                                          fp.read(),
                                          idref,
                                          mode=mode,
                                          noupdate=noupdate)
             elif ext == '.sql':
                 process_sql_file(cr, fp)
             elif ext == '.yml':
                 tools.convert_yaml_import(cr,
                                           m,
                                           fp,
                                           idref,
                                           mode=mode,
                                           **kwargs)
             else:
                 tools.convert_xml_import(cr,
                                          m,
                                          fp,
                                          idref,
                                          mode=mode,
                                          **kwargs)
         finally:
             fp.close()
Example #3
0
 def load_demo_xml(cr, m, idref, mode):
     for xml in package.data.get('demo_xml', []):
         name, ext = os.path.splitext(xml)
         logger.notifyChannel('init', netsvc.LOG_INFO,
                              'module %s: loading %s' % (m, xml))
         fp = tools.file_open(opj(m, xml))
         try:
             if ext == '.csv':
                 tools.convert_csv_import(cr,
                                          m,
                                          os.path.basename(xml),
                                          fp.read(),
                                          idref,
                                          mode=mode,
                                          noupdate=True)
             elif ext == '.yml':
                 tools.convert_yaml_import(cr,
                                           m,
                                           fp,
                                           idref,
                                           mode=mode,
                                           noupdate=True,
                                           **kwargs)
             else:
                 tools.convert_xml_import(cr,
                                          m,
                                          fp,
                                          idref,
                                          mode=mode,
                                          noupdate=True,
                                          **kwargs)
         finally:
             fp.close()
Example #4
0
 def load_demo_xml(cr, m, idref, mode):
     for xml in package.data.get('demo_xml', []):
         name, ext = os.path.splitext(xml)
         logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, xml))
         fp = tools.file_open(opj(m, xml))
         if ext == '.csv':
             tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True)
         elif ext == '.yml':
             tools.convert_yaml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
         else:
             tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
         fp.close()
Example #5
0
 def load_init_update_xml(cr, m, idref, mode, kind):
     for filename in package.data.get('%s_xml' % kind, []):
         logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, filename))
         _, ext = os.path.splitext(filename)
         fp = tools.file_open(opj(m, filename))
         if ext == '.csv':
             noupdate = (kind == 'init')
             tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate)
         elif ext == '.sql':
             process_sql_file(cr, fp)
         elif ext == '.yml':
             tools.convert_yaml_import(cr, m, fp, idref, mode=mode, **kwargs)
         else:
             tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs)
         fp.close()
Example #6
0
 def _run_test(self, cr, module_name, filename):
     _, ext = os.path.splitext(filename)
     pathname = os.path.join(module_name, filename)
     open_file = tools.file_open(pathname)
     if ext == '.sql':
         queries = open_file.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_name, pathname, open_file.read(), idref=None, mode='update', noupdate=False)
     elif ext == '.yml':
         tools.convert_yaml_import(cr, module_name, open_file, idref=None, mode='update', noupdate=False)
     else:
         tools.convert_xml_import(cr, module_name, open_file, idref=None, mode='update', noupdate=False)
Example #7
0
 def _load_data(cr, module_name, id_map, mode, kind):
     noupdate = (kind == 'demo')
     for filename in package.data.get(kind, []):
         _, ext = os.path.splitext(filename)
         log.info("module %s: loading %s", module_name, filename)
         pathname = os.path.join(module_name, filename)
         file = tools.file_open(pathname)
         # TODO manage .csv file with noupdate == (kind == 'init')
         if ext == '.sql':
             process_sql_file(cr, file)
         elif ext == '.csv':
             noupdate = (kind == 'init')
             tools.convert_csv_import(cr, module_name, pathname, file.read(), id_map, mode, noupdate)
         elif ext == '.yml':
             tools.convert_yaml_import(cr, module_name, file, id_map, mode, noupdate)
         else:
             tools.convert_xml_import(cr, module_name, file, id_map, mode, noupdate)
         file.close()
Example #8
0
def load_data(cr, module_name, filename, idref=None, mode="init"):
    """
    Load an xml or csv 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'.

    """
    import tools

    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)
        else:
            tools.convert_xml_import(cr, module_name, fp, idref, mode=mode)
    finally:
        fp.close()
Example #9
0
 def _load_data(cr, module_name, id_map, mode, kind):
     noupdate = (kind == 'demo')
     for filename in package.data.get(kind, []):
         _, ext = os.path.splitext(filename)
         log.info("module %s: loading %s", module_name, filename)
         pathname = os.path.join(module_name, filename)
         file = tools.file_open(pathname)
         # TODO manage .csv file with noupdate == (kind == 'init')
         if ext == '.sql':
             process_sql_file(cr, file)
         elif ext == '.csv':
             noupdate = (kind == 'init')
             tools.convert_csv_import(cr, module_name, pathname,
                                      file.read(), id_map, mode, noupdate)
         elif ext == '.yml':
             tools.convert_yaml_import(cr, module_name, file, id_map, mode,
                                       noupdate)
         else:
             tools.convert_xml_import(cr, module_name, file, id_map, mode,
                                      noupdate)
         file.close()
Example #10
0
def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs):
    # **kwargs is passed directly to convert_xml_import
    if not status:
        status = {}

    status = status.copy()
    package_todo = []
    statusi = 0
    pool = pooler.get_pool(cr.dbname)

    migrations = MigrationManager(cr, graph)

    has_updates = False
    modobj = None

    for package in graph:
        logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading objects' % package.name)
        migrations.migrate_module(package, 'pre')
        register_class(package.name)
        modules = pool.instanciate(package.name, cr)
        if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
            init_module_objects(cr, package.name, modules)
        cr.commit()
        
    for package in graph:
        status['progress'] = (float(statusi)+0.1) / len(graph)
        m = package.name
        mid = package.id

        if modobj is None:
            modobj = pool.get('ir.module.module')

        if modobj and perform_checks:
            modobj.check(cr, 1, [mid])

        idref = {}
        status['progress'] = (float(statusi)+0.4) / len(graph)

        mode = 'update'
        if hasattr(package, 'init') or package.state == 'to install':
            mode = 'init'

        if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
            has_updates = True
            for kind in ('init', 'update'):
                if package.state=='to upgrade':
                    # upgrading the module information
                    modobj.write(cr, 1, [mid], {
                    'description': package.data.get('description', ''),
                    'shortdesc': package.data.get('name', ''),
                    'author': package.data.get('author', 'Unknown'),
                    'website': package.data.get('website', ''),
                    'license': package.data.get('license', 'GPL-2'),
                    'certificate': package.data.get('certificate') or None,
                    })
                for filename in package.data.get('%s_xml' % kind, []):
                    logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, filename))
                    name, ext = os.path.splitext(filename)
                    fp = tools.file_open(opj(m, filename))
                    if ext == '.csv':
                        tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode)
                    elif ext == '.sql':
                        queries = fp.read().split(';')
                        for query in queries:
                            new_query = ' '.join(query.split())
                            if new_query:
                                cr.execute(new_query)
                    else:
                        tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs)
                    fp.close()
            if hasattr(package, 'demo') or (package.dbdemo and package.state != 'installed'):
                status['progress'] = (float(statusi)+0.75) / len(graph)
                for xml in package.data.get('demo_xml', []):
                    name, ext = os.path.splitext(xml)
                    logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, xml))
                    fp = tools.file_open(opj(m, xml))
                    if ext == '.csv':
                        tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True)
                    else:
                        tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
                    fp.close()
                cr.execute('update ir_module_module set demo=%s where id=%s', (True, mid))
            package_todo.append(package.name)

            migrations.migrate_module(package, 'post')

            if modobj:
                ver = release.major_version + '.' + package.data.get('version', '1.0')
                # Set new modules and dependencies
                modobj.write(cr, 1, [mid], {'state': 'installed', 'latest_version': ver})
                cr.commit()
                # Update translations for all installed languages
                modobj.update_translations(cr, 1, [mid], None)
                cr.commit()

            package.state = 'installed'
            for kind in ('init', 'demo', 'update'):
                if hasattr(package, kind):
                    delattr(package, kind)

        statusi += 1

    cr.execute('select model from ir_model where state=%s', ('manual',))
    for model in cr.dictfetchall():
        pool.get('ir.model').instanciate(cr, 1, model['model'], {})

    pool.get('ir.model.data')._process_end(cr, 1, package_todo)
    cr.commit()

    return has_updates