def run(host, port, db_name, password, modules):
    print '>>> UPGRADE-MODULES IN PROGRESS ...'
    print '---'

    if not password:
        password = getpass.getpass('Password: ')
    username = 'admin'
    oorpc = OpenObjectRPC(host, db_name, username, password, port)
    modules_ids = []
    modules_names = []

    print 'Updating module list ...'
    oorpc.execute(module_model, 'update_list')

    for module_name in modules:
        if module_name not in modules_names:
            print 'Searching for module [%s] ...' % (module_name,)
            ids = search_modules_ids_by_name(oorpc, module_name)
            if not ids:
                print 'WARNING: this module was not found!'
            else:
                modules_names.append(module_name)
                modules_ids.extend(ids)
    modules_ids = list(set(modules_ids))
    upgrade_modules(oorpc, modules_ids)

    print '---'
    print '>>> UPGRADE-MODULES ENDED.'
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})