Example #1
0
def _so_builder(db_name, port_number=8069, *args):
    ODOO_BIN_PATH = f"{env.ODOO}/odoo-bin"
    ODOO_PY_PATH = f"{env.ODOO}/odoo.py"
    PATH_COMMUNITY = f"--addons-path={env.ODOO}/addons"
    PATH_ENTERPRISE = (
        f"--addons-path={env.ENTERPRISE},{env.ODOO}/addons,{env.SRC}/design-themes"
    )
    PARAMS_NORMAL = f"--db-filter=^{db_name}$ -d {db_name} --xmlrpc-port={port_number}"
    additional_params = " ".join(args)
    if _check_file_exists(ODOO_BIN_PATH):
        # version 10 or above
        cmd = f"{ODOO_BIN_PATH} {PATH_ENTERPRISE} {PARAMS_NORMAL} {additional_params}"
    else:
        # version 9 or below
        try:
            version = _get_version_from_db(db_name)
        except OperationalError as e:
            msg = f"""{e}
                Note:
                `so` does not work with DBs < 10.0, unless it already exists
                This will probably never be fixed."""
            raise Invalid_params(msg)
        if version == "8.0":
            cmd = f"{ODOO_PY_PATH} {PATH_COMMUNITY} {PARAMS_NORMAL} {additional_params}"
        else:
            cmd = (
                f"{ODOO_PY_PATH} {PATH_ENTERPRISE} {PARAMS_NORMAL} {additional_params}"
            )
    print(cmd)
    return cmd
Example #2
0
def godb(db_name):
    """switch repos branch to the version of the given DB"""
    try:
        version = _get_version_from_db(db_name)
    except OperationalError:
        print(f"DB {db_name} does not exist")
    else:
        params = {"checkout": True, "--dbname": db_name}
        _git_odoo_app(**params)
        differed_sh_run(f"go_venv {version}")
Example #3
0
def _so_checker(*args):
    # check that the params given to 'so' are correct,
    # check that I am not trying to start a protected DB,
    # check that I am sure to want to start a DB with the wrong branch checked out (only check $ODOO)

    if len(args) == 0:
        raise Invalid_params(
            _dd("""\
                At least give me a name :(
                so dbname [port] [other_parameters]
                note: port is mandatory if you want to add other parameters""")
        )
    db_name = args[0]
    if db_name.startswith("CLEAN_ODOO"):
        raise Invalid_params(
            _dd(f"""\
                Don't play with that one!
                {db_name} is a protected database."""))
    try:
        db_version = _get_version_from_db(db_name)
    except OperationalError:
        # db doesn't exist.
        pass
    else:
        checked_out_branch = _get_branch_name(env.ODOO)
        if db_version != checked_out_branch:
            print(
                _dd(f"""\
                    Version mismatch
                    DB version is: {db_version}
                    repo version is: {checked_out_branch}"""))
            ans = input("continue anyway? (y/N):").lower()
            if ans == "y":
                print("I hope you know what you're doing...")
            else:
                raise UserAbort("Yeah, that's probably safer :D")
    if len(args) >= 2:
        try:
            int(args[1])
        except ValueError as ve:
            bad_port = str(ve).split(":")[1][2:-1]
            raise Invalid_params(
                f"""The port number must be an integer. Provided value : {bad_port}"""
            )