Пример #1
0
def detect_profile():
    '''Automatically detect the profile based on the host platform'''
    profile = {
        'Darwin': 'macOS_cmdline',
        'Linux': 'linux',
        'Windows': 'windows'
    }.get(platform.system())
    if not profile:
        raise exceptions.PlatformError(
            "Host platform not supported for native build")
    return profile
Пример #2
0
def restore_snapshot(
    c,
    snapshot_name=None,
    destination_db="devel",
):
    """Restore database and filestore snapshot.

    Uses click-odoo-copydb behind the scenes to restore a DB snapshot.
    """
    with c.cd(str(PROJECT_ROOT)):
        cur_state = c.run("docker-compose stop odoo db", pty=True).stdout
        if not snapshot_name:
            # List DBs
            res = c.run(
                "docker-compose run --rm -e LOG_LEVEL=WARNING odoo psql -tc"
                " 'SELECT datname FROM pg_database;'",
                env=UID_ENV,
                hide="stdout",
            )
            db_list = []
            for db in res.stdout.splitlines():
                # Parse and filter DB List
                if not db.lstrip().startswith(destination_db):
                    continue
                db_name = db.lstrip()
                try:
                    db_date = datetime.strptime(
                        db_name.lstrip(destination_db + "-"), "%Y_%m_%d-%H_%M"
                    )
                    db_list.append((db_name, db_date))
                except ValueError:
                    continue
            snapshot_name = max(db_list, key=lambda x: x[1])[0]
            if not snapshot_name:
                raise exceptions.PlatformError(
                    "No snapshot found for destination_db %s" % destination_db
                )
        _logger.info("Restoring snapshot %s to %s" % (snapshot_name, destination_db))
        _run = "docker-compose run --rm -l traefik.enable=false odoo"
        c.run(
            f"{_run} click-odoo-dropdb {destination_db}",
            env=UID_ENV,
            warn=True,
            pty=True,
        )
        c.run(
            f"{_run} click-odoo-copydb {snapshot_name} {destination_db}",
            env=UID_ENV,
            pty=True,
        )
        if "Stopping" in cur_state:
            # Restart services if they were previously active
            c.run("docker-compose start odoo db", pty=True)
Пример #3
0
def preparedb(c):
    """Run the `preparedb` script inside the container

    Populates the DB with some helpful config
    """
    if ODOO_VERSION < 11:
        raise exceptions.PlatformError(
            "The preparedb script is not available for Doodba environments bellow v11."
        )
    with c.cd(str(PROJECT_ROOT)):
        c.run(
            "docker-compose run --rm -l traefik.enable=false odoo preparedb",
            env=UID_ENV,
            pty=True,
        )
Пример #4
0
def build(ctx,
          debug=False,
          coverage=False,
          sonarqube=False,
          sanitize=None,
          cmake_verbose=False,
          cmakegen=None):
    '''Build Golden Gate natively using the default auto-detected profile for the host platform'''
    build_dir = ctx.C.BUILD_DIR_NATIVE
    cmake.build(ctx,
                build_dir,
                detect_profile(),
                tests=True,
                debug=debug,
                coverage=coverage,
                sanitize=sanitize,
                cmake_verbose=cmake_verbose,
                generator=cmakegen)
    build_wrapper = ""
    if sonarqube:
        wrapper_bin = {
            'Darwin': 'build-wrapper-macosx-x86',
            'Linux': 'build-wrapper-linux-x86-64'
        }.get(platform.system())
        if not wrapper_bin:
            raise exceptions.PlatformError(
                "Host platform not supported for native build")
        build_wrapper = "{} --out-dir {}/sonarqube/build-wrapper ".format(
            wrapper_bin, build_dir)

        # Ensure the output directory exists
        ctx.run("mkdir -p {build_dir}/sonarqube/build-wrapper".format(
            build_dir=build_dir))

        # Check that the wrapper binary is installed
        try:
            ctx.run("{}true".format(build_wrapper),
                    pty=(sys.platform != 'win32'))
        except exceptions.UnexpectedExit as e:
            print(type(e))
            print(
                "!!! Sonarqube wrapper not installed ({}), will not run analysis. See https://docs.sonarqube.org/latest/analysis/languages/cfamily"
                .format(wrapper_bin))
            build_wrapper = ""

    # Run the build
    ctx.run("{}cmake --build {}".format(build_wrapper, build_dir),
            pty=(sys.platform != 'win32'))