def upgrade_modules(oorpc, modules_ids):
    to_be_installed_ids = []
    for module in oorpc.execute(module_model, 'read', modules_ids, ['state', 'name']):
        if module['state'] == 'uninstalled':
            print 'Marking module [%s] to be installed ...' % (module['name'])
            oorpc.execute(module_model, 'button_install', [module['id']])
            to_be_installed_ids.append(module['id'])
            modules_ids.remove(module['id'])
    print 'Marking modules to be upgraded ...'
    oorpc.execute(module_model, 'button_upgrade', modules_ids)

    ids_module = oorpc.search(module_model, [('state', 'in', ('to upgrade', 'to install'))])
    print 'Upgrading modules ...'
    oorpc.execute(module_upgrade_model, 'upgrade_module', modules_ids + to_be_installed_ids)

    print 'Starting post objects ...'
    oorpc.execute(module_upgrade_model, 'config', [], {'ids_module': ids_module})
def search_modules_ids_by_name(oorpc, module_name):
    args = [('name', '=', module_name)]
    return oorpc.search(module_model, args) or None