示例#1
0
 def test_environment(self):
     """ ##################################################### CHECK VERSION
     """
     env = OeConfig().get_environment()
     self.assertEqual(env, 'prod')
     OeConfig().save_environment('debug')
     env = OeConfig().get_environment()
     self.assertEqual(env, 'debug')
示例#2
0
文件: options.py 项目: x1g1/odoo-env
def get_client(args):
    if args.client:
        OeConfig().save_client(args.client[0])
        return args.client[0]
    else:
        client = OeConfig().get_client()
        if client:
            return client
        else:
            Msg().err('Need -c option (client name). Process aborted')
示例#3
0
    def test_config(self):
        """ ####################################################### TEST CONFIG
        """
        OeConfig().unlink()

        path = OeConfig().get_client_path('test_client')
        self.assertFalse(path)

        OeConfig().save_client_path('test_client',
                                    '/odoo_ar/odoo-9.0/test_client')
        path = OeConfig().get_client_path('test_client')
        self.assertEqual(path, '/odoo_ar/odoo-9.0/test_client')
示例#4
0
 def get_manifest(self, path):
     """
     :param path: path base para buscar el cliente
     :return: manifiesto del cliente
     """
     # traer el path al cliente de la configuracion
     client_path = OeConfig().get_client_path(self._name)
     # si lo encuentro traigo el manifest rapidamente con el path
     if client_path:
         manifest, _ = self.get_manifest_from_struct(client_path)
         return manifest
     else:
         # no lo encuentro, busco en toda la estructura de directorios
         manifest, path = self.get_manifest_from_struct(path)
         if manifest:
             # si lo encuentro lo guardo en el archivo para la proxima
             OeConfig().save_client_path(self._name, path)
         # devuelvo el manifiesto o false si no esta
         return manifest
示例#5
0
    def __init__(self, odooenv, name):
        """ Busca el cliente en la estructura de directorios, pero si no lo
            encuentra pide un directorio donde esta el repo que lo contiene
        """
        # parent es siempre un objeto OdooEnv
        self._parent = odooenv
        self._name = name
        self._license = False
        self._images = []
        self._repos = []
        self._port = 0
        self._version = ''
        self.CPUs = 1
        self.limit_request = '0'
        self.limit_memory_soft = '0'
        self.limit_memory_hard = '0'
        self.limit_time_cpu = '0'
        self.limit_time_real = '0'

        # si estamos en test accedo a data
        if name[0:5] in ['test_', 'test2']:
            path = os.path.dirname(os.path.abspath(__file__))
            path = path.replace('odoo_env', 'odoo_env/data')
            manifest = self.get_manifest(path)
            OeConfig().save_client_path(name, path)
        else:
            manifest = self.get_manifest(BASE_DIR)
        if not manifest:
            msg.inf('Can not find client {} in this host installation.\n'
                    'We will try in current dir'.format(self._name))

            # mantener compatibilidad con python2
            import six
            six.moves.input('Hit Enter to continue or CTRL C to exit')
            manifest, _ = self.get_manifest_from_struct(os.getcwd())
            if not manifest:
                msg.err('Can not find client {} in current dir'.format(name))

            msg.inf('Client found!')
            msg.inf('Name {}\nversion {}\n'.format(manifest.get('name'),
                                                   manifest.get('version')))

        self.check_common(manifest)

        # verificar version del manifiesto
        ver = manifest.get('env-ver', '1')
        if ver == '1':
            self.check_v1(manifest)
        elif ver == '2':
            self.check_v2(manifest)
        else:
            msg.err('not supported syntax version in manifest')
示例#6
0
 def test_save_multiple_clients(self):
     OeConfig().save_client_path('test_client', 'multiple_path')
     OeConfig().save_client_path('test_client', 'multiple_path')
     config = OeConfig().get_config_data()
     self.assertEqual(len(config.get('clients')), 1)
示例#7
0
 def test_check_version(self):
     """ ##################################################### CHECK VERSION
     """
     self.assertTrue(OeConfig().check_version())
示例#8
0
    def setUp(self, *args, **kwargs):
        super().setUp(*args, **kwargs)

        conf = OeConfig()
        conf.unlink()
        conf._test = True
示例#9
0
def main():
    parser = argparse.ArgumentParser(description="""
Odoo Environment Manager v%s - by jeo Software <*****@*****.**>
""" % __version__)

    parser.add_argument(
        '-i',
        '--install',
        action='store_true',
        help="Install. Creates dir structure, and pull all the repositories "
        "declared in the client manifest. Use with --debug to copy Odoo "
        "image sources to host")

    parser.add_argument(
        '-p',
        '--pull-images',
        action='store_true',
        help="Pull Images. Download all images declared in client manifest.")

    parser.add_argument('-w',
                        '--write-config',
                        action='store_true',
                        help="Create / Overwrite config file.")

    parser.add_argument('-R',
                        '--run-env',
                        action='store_true',
                        help="Run postgres and aeroo images.")

    parser.add_argument('-r',
                        '--run-cli',
                        action='store_true',
                        help="Run odoo image")

    parser.add_argument('-S',
                        '--stop-env',
                        action='store_true',
                        help="Stop postgres and aeroo images.")

    parser.add_argument('-s',
                        '--stop-cli',
                        action='store_true',
                        help="Stop odoo image.")

    parser.add_argument(
        '-u',
        '--update',
        action='store_true',
        help="Update modules to database. Use --debug to force update with "
        "image sources. use -m modulename to update this only module "
        "default is all use -d databasename to update this database, "
        "default is clientname_default")

    parser.add_argument(
        '-c',
        action='append',
        dest='client',
        help="Set default client name. This option is persistent")

    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help="Go verbose mode. Prints every command")

    parser.add_argument('--deactivate',
                        action='store_true',
                        help="Deactivate database before restore")

    parser.add_argument(
        '--debug',
        action='store_true',
        help='Set default environment mode to debug'
        'This option has the following efects: '
        '1.- When doing an install it copies the image sources to host '
        'and clones repos with depth=100'
        '2.- When doing an update all, (option -u) it forces update with '
        'image sources.'
        'This option is persistent.')
    parser.add_argument(
        '--prod',
        action='store_true',
        help='Set default environment mode to production'
        'This option is intended to install a production environment.'
        'This option is persistent.')

    parser.add_argument(
        '--no-repos',
        action='store_true',
        help='Does not clone or pull repos when doing -i (install)')

    parser.add_argument('-d',
                        action='store',
                        nargs=1,
                        dest='database',
                        help="Set default Database name."
                        "This option is persistent")

    parser.add_argument(
        '-m',
        action='append',
        dest='module',
        help="Module to update. Used with -u (update) i.e. -m sale for "
        "updating sale module -m all for updating all modules. NOTE: if "
        "you perform -u without -m it asumes all modules")

    parser.add_argument(
        '--nginx',
        action='store_true',
        help='Add nginx to installation: Used with -i creates nginx dir '
        'with config file. '
        'Used with -r starts an nginx container linked to odoo.'
        'Used with -s stops nginx container. '
        'If you want to add certificates review nginx.conf file located '
        'in /odoo_ar/nginx/conf')

    parser.add_argument(
        '-Q',
        action='store',
        metavar='repo',
        nargs=1,
        dest='quality_assurance',
        help="Perform QA running tests, argument are repository to test. "
        "Need -d, -m and -c options Note: for the test to run the "
        "database must be created with demo data and must have "
        "admin user with password admin.")

    parser.add_argument('--backup-list',
                        action='store_true',
                        help="List all backup files available for restore")

    parser.add_argument(
        '--restore',
        action='store_true',
        help="Restores a backup. it uses last backup and restores to default "
        "database. You can change the backup file to restore with -f "
        "option and change database name -d option")

    parser.add_argument(
        '-f',
        action='append',
        dest='backup_file',
        help="Filename to restore. Used with --restore. To get the name of "
        "this file issue a --backup-list command."
        "If ommited the newest file will be restored")

    parser.add_argument(
        '-H',
        '--server-help',
        action='store_true',
        help="Show odoo server help, it shows the help from the odoo image"
        "declared in the cliente manifest")

    parser.add_argument('-V',
                        '--version',
                        action='store_true',
                        help="Show version number and exit.")

    args = parser.parse_args()
    if args.debug:
        OeConfig().save_environment('debug')

    if args.prod:
        OeConfig().save_environment('prod')

    debug_option = OeConfig().get_environment() == 'debug'
    options = {
        'verbose': args.verbose,
        'debug': debug_option,
        'no-repos': args.no_repos,
        'nginx': args.nginx,
        'backup_file': args.backup_file,
    }
    commands = []

    if args.server_help:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).server_help(client_name)

    if args.backup_list:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).backup_list(client_name)

    if args.restore:
        client_name = get_param(args, 'client')
        database = get_param(args, 'database')
        backup_file = get_param(args, 'backup_file')
        deactivate = get_param(args, 'deactivate')
        commands += OdooEnv(options).restore(client_name, database,
                                             backup_file, deactivate)

    if args.install:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).install(client_name)

    if args.write_config:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).write_config(client_name)

    if args.pull_images:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).pull_images(client_name)

    if args.stop_env:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).stop_environment(client_name)

    if args.run_env:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).run_environment(client_name)

    if args.stop_cli:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).stop_client(client_name)

    if args.run_cli:
        client_name = get_param(args, 'client')
        commands += OdooEnv(options).run_client(client_name)

    if args.update:
        client_name = get_param(args, 'client')
        database = get_param(args, 'database')
        modules = get_param(args, 'module')
        commands += OdooEnv(options).update(client_name, database, modules)

    if args.quality_assurance:
        client_name = get_param(args, 'client')
        database = get_param(args, 'database')
        commands += OdooEnv(options).qa(client_name, database,
                                        args.quality_assurance[0])
    if args.version:
        Msg().inf('oe version %s' % __version__)
        exit()

    # Verificar la version del script en pypi
    conf = OeConfig()
    conf.check_version()

    # #####################################################################
    # ejecutar comandos
    # ######################################################################
    for command in commands:
        if command and command.check():
            Msg().inf(command.usr_msg)
            command.execute()