# Path: infrastructure/models/server.py
# def custom_sudo(command, user=False, group=False, dont_raise=False):
#     # TODO esto habria que pasrlo con *args, **kwargs
#     env.warn_only = True
#     if user and group:
#         res = sudo(command, user=user, group=group)
#     elif user:
#         res = sudo(command, user=user)
#     elif group:
#         res = sudo(command, group=group)
#     else:
#         res = sudo(command)
#     if res.failed:
#         if dont_raise:
#             _logger.warning((
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#         else:
#             raise ValidationError(_(
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#     env.warn_only = False
#     return res


from openerp import models, fields, api, SUPERUSER_ID, _
from openerp.exceptions import except_orm
from openerp.tools.parse_version import parse_version
from dateutil.relativedelta import relativedelta
from openerp.addons.server_mode.mode import get_mode
from datetime import datetime
from datetime import date
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
from erppeek import Client
from openerp.exceptions import ValidationError
import xmlrpclib
import operator
import socket
import urlparse
import urllib
import time
import uuid
import os
import requests
import simplejson
import logging
        res = client.model('db.configuration').fix_db(
            raise_msg, uninstall_modules, restart_if_needed)
        if res.get('error'):
            raise ValidationError(res.get('error'))
        self.refresh_update_state()
        return True

    @api.multi
    def reinit_modules(self, modules_names):
        """
        modules_names is a list of modules names to be reinit
        """
        # TODO lo ideal sería hacer un metodo algo mas lindo pero no encontre
        # la manera
        _logger.info('Initializing modules: %s' % modules_names)

        # update module list
        self.update_module_list()

        # remove odoo server
        self.server_id.get_env()
        self.instance_id.remove_odoo_service()

        # prepare and run odoo initializing modules
        init_command = ('%s -i %s -d %s' % (
            self.instance_id.update_cmd,
            ','.join(modules_names),
            self.name)
        )
        _logger.info('Running init modules commmand: %s' % init_command)

# Path: infrastructure/models/server.py
# def custom_sudo(command, user=False, group=False, dont_raise=False):
#     # TODO esto habria que pasrlo con *args, **kwargs
#     env.warn_only = True
#     if user and group:
#         res = sudo(command, user=user, group=group)
#     elif user:
#         res = sudo(command, user=user)
#     elif group:
#         res = sudo(command, group=group)
#     else:
#         res = sudo(command)
#     if res.failed:
#         if dont_raise:
#             _logger.warning((
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#         else:
#             raise ValidationError(_(
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#     env.warn_only = False
#     return res


# Path: infrastructure/models/database.py
from openerp import models, fields, api, SUPERUSER_ID, _
from openerp.exceptions import except_orm
from openerp.tools.parse_version import parse_version
from dateutil.relativedelta import relativedelta
from openerp.addons.server_mode.mode import get_mode
from datetime import datetime
from datetime import date
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
from erppeek import Client
from openerp.exceptions import ValidationError
import xmlrpclib
import operator
import socket
import urlparse
import urllib
import time
import uuid
import os
import requests
import simplejson
import logging

        res = client.model('db.configuration').fix_db(
            raise_msg, uninstall_modules, restart_if_needed)
        if res.get('error'):
            raise ValidationError(res.get('error'))
        self.refresh_update_state()
        return True

    @api.multi
    def reinit_modules(self, modules_names):
        """
        modules_names is a list of modules names to be reinit
        """
        # TODO lo ideal sería hacer un metodo algo mas lindo pero no encontre
        # la manera
        _logger.info('Initializing modules: %s' % modules_names)

        # update module list
        self.update_module_list()

        # remove odoo server
        self.server_id.get_env()
        self.instance_id.remove_odoo_service()

        # prepare and run odoo initializing modules
        init_command = ('%s -i %s -d %s' % (
            self.instance_id.update_cmd,
            ','.join(modules_names),
            self.name)
        )
        _logger.info('Running init modules commmand: %s' % init_command)

        sudo(init_command)