示例#1
0
def clean_directories(builddir, in_dir=True, out_dir=True):
    """Remove the in and out of the container if confirmed by the user."""
    with local.cwd(builddir):
        if in_dir and os.path.exists("container-in") and ask(
                "Should I delete '{0}'?".format(
                    os.path.abspath("container-in"))):
            rm("-rf", "container-in")
        if out_dir and os.path.exists("container-out") and ask(
                "Should I delete '{0}'?".format(
                    os.path.abspath("container-out"))):
            rm("-rf", "container-out")
示例#2
0
def clean_directories(builddir, in_dir=True, out_dir=True):
    """Remove the in and out of the container if confirmed by the user."""
    container_in = local.path(builddir) / "container-in"
    container_out = local.path(builddir) / "container-out"

    if in_dir and container_in.exists():
        if ui.ask("Should I delete '{0}'?".format(container_in)):
            container_in.delete()
    if out_dir and container_out.exists():
        if ui.ask("Should I delete '{0}'?".format(container_out)):
            container_out.delete()
示例#3
0
def clean_directories(builddir, in_dir=True, out_dir=True):
    """Remove the in and out of the container if confirmed by the user."""
    container_in = local.path(builddir) / "container-in"
    container_out = local.path(builddir) / "container-out"

    if in_dir and container_in.exists():
        if ui.ask("Should I delete '{0}'?".format(container_in)):
            container_in.delete()
    if out_dir and container_out.exists():
        if ui.ask("Should I delete '{0}'?".format(container_out)):
            container_out.delete()
示例#4
0
def install_package(pkg_name):
    if not bool(CFG['bootstrap']['install']):
        return False

    if pkg_name not in PACKAGES:
        print("No bootstrap support for package '{0}'".format(pkg_name))
    linux, _, _ = linux_distribution_major()
    linux = str(linux.lower())
    package_manager = PACKAGE_MANAGER[linux]
    packages = PACKAGES[pkg_name][linux]
    for pkg_name_on_host in packages:
        print("You are missing the package: '{0}'".format(pkg_name_on_host))
        cmd = local["sudo"]
        cmd = cmd[package_manager["cmd"], package_manager["args"],
                  pkg_name_on_host]
        cmd_str = str(cmd)

        ret = False
        if ui.ask("Run '{cmd}' to install it?".format(cmd=cmd_str)):
            print("Running: '{cmd}'".format(cmd=cmd_str))

        try:
            (cmd & FG(retcode=0))
        except ProcessExecutionError:
            print("NOT INSTALLED")
        else:
            print("OK")
    return ret
示例#5
0
 def output_file(self, container):
     """Find and writes the output path of a chroot container."""
     p = os.path.abspath(container)
     if os.path.exists(p):
         if not ask("Path '{0}' already exists." " Overwrite?".format(p)):
             sys.exit(0)
     CFG["container"]["output"] = p
示例#6
0
 def output_file(self, _container):
     """Find and writes the output path of a chroot container."""
     p = local.path(_container)
     if p.exists():
         if not ui.ask("Path '{0}' already exists."
                       " Overwrite?".format(p)):
             sys.exit(0)
     CFG["container"]["output"] = str(p)
示例#7
0
 def output_file(self, _container):
     """Find and writes the output path of a chroot container."""
     p = local.path(_container)
     if p.exists():
         if not ui.ask("Path '{0}' already exists."
                       " Overwrite?".format(p)):
             sys.exit(0)
     CFG["container"]["output"] = str(p)
示例#8
0
def enforce_versioning(force=False):
    """Install versioning on the db."""
    connect_str, repo_url = get_version_data()
    LOG.warning("Your database uses an unversioned benchbuild schema.")
    if not force and not ui.ask(
            "Should I enforce version control on your schema?"):
        LOG.error("User declined schema versioning.")
        return None
    repo_version = migrate.version(repo_url, url=connect_str)
    migrate.version_control(connect_str, repo_url, version=repo_version)
    return repo_version
示例#9
0
def enforce_versioning(force=False):
    """Install versioning on the db."""
    connect_str, repo_url = get_version_data()
    LOG.warning("Your database uses an unversioned benchbuild schema.")
    if not force and not ui.ask(
            "Should I enforce version control on your schema?"):
        LOG.error("User declined schema versioning.")
        return None
    repo_version = migrate.version(repo_url, url=connect_str)
    migrate.version_control(connect_str, repo_url, version=repo_version)
    return repo_version
示例#10
0
    def main(self, *args):
        log.configure()
        builddir = local.path(str(CFG["build_dir"]))
        if not builddir.exists():
            response = ui.ask(
                "The build directory {dirname} does not exist yet. "
                "Should I create it?".format(dirname=builddir))

            if response:
                mkdir("-p", builddir)
                print("Created directory {0}.".format(builddir))

        setup_directories(builddir)
示例#11
0
    def main(self, *args):
        log.configure()
        builddir = local.path(str(CFG["build_dir"]))
        if not builddir.exists():
            response = ui.ask(
                "The build directory {dirname} does not exist yet. "
                "Should I create it?".format(dirname=builddir))

            if response:
                mkdir("-p", builddir)
                print("Created directory {0}.".format(builddir))

        setup_directories(builddir)
示例#12
0
    def validate(self):
        """Make sure this configuration path exists."""
        path = local.path(ConfigPath.path_to_str(self.components))

        if not path.exists():
            print("The path '%s' is required by your configuration." % path)
            yes = ui.ask(
                "Should I create '%s' for you?" % path,
                default_answer=True,
                default_answer_str="yes")
            if yes:
                path.mkdir()
            else:
                LOG.error("User denied path creation of '%s'.", path)
        if not path.exists():
            LOG.error("The path '%s' needs to exist.", path)
示例#13
0
    def validate(self):
        """Make sure this configuration path exists."""
        path = local.path(ConfigPath.path_to_str(self.components))

        if not path.exists():
            print("The path '%s' is required by your configuration." % path)
            yes = ui.ask(
                "Should I create '%s' for you?" % path,
                default_answer=True,
                default_answer_str="yes")
            if yes:
                path.mkdir()
            else:
                LOG.error("User denied path creation of '%s'.", path)
        if not path.exists():
            LOG.error("The path '%s' needs to exist.", path)
示例#14
0
 def exc_wrapper(*args, **kwargs):
     nonlocal error_messages
     try:
         result = func(*args, **kwargs)
     except sa.exc.SQLAlchemyError as err:
         result = None
         details = None
         err_type = err.__class__
         if error_messages and err_type in error_messages:
             details = error_messages[err_type]
         if details:
             LOG.error(details)
         LOG.error("For developers: (%s) %s", err.__class__, str(err))
         if error_is_fatal:
             sys.exit("Abort, SQL operation failed.")
         if not ui.ask(
                 "I can continue at your own risk, do you want that?"):
             raise err
     return result
示例#15
0
 def exc_wrapper(*args, **kwargs):
     nonlocal error_messages
     try:
         result = func(*args, **kwargs)
     except sa.exc.SQLAlchemyError as err:
         result = None
         details = None
         err_type = err.__class__
         if error_messages and err_type in error_messages:
             details = error_messages[err_type]
         if details:
             LOG.error(details)
         LOG.error("For developers: (%s) %s", err.__class__, str(err))
         if error_is_fatal:
             sys.exit("Abort, SQL operation failed.")
         if not ui.ask(
                 "I can continue at your own risk, do you want that?"):
             raise err
     return result
示例#16
0
    def main(self, *args):
        log.configure()
        _log = logging.getLogger()
        _log.setLevel({
            3: logging.DEBUG,
            2: logging.INFO,
            1: logging.WARNING,
            0: logging.ERROR
        }[self.verbosity])

        builddir = os.path.abspath(str(CFG["build_dir"]))
        if not os.path.exists(builddir):
            response = ask("The build directory {dirname} does not exist yet. "
                           "Should I create it?".format(dirname=builddir))

            if response:
                mkdir("-p", builddir)
                print("Created directory {0}.".format(builddir))

        setup_directories(builddir)
示例#17
0
def maybe_update_db(repo_version, db_version):
    if db_version is None:
        return
    if db_version == repo_version:
        return

    LOG.warning("Your database contains version '%s' of benchbuild's schema.",
                db_version)
    LOG.warning(
        "Benchbuild currently requires version '%s' to work correctly.",
        repo_version)
    if not ui.ask("Should I attempt to update your schema to version '{0}'?".
                  format(repo_version)):
        LOG.error("User declined schema upgrade.")
        return

    connect_str = str(settings.CFG["db"]["connect_string"])
    repo_url = path.template_path("../db/")
    LOG.info("Upgrading to newest version...")
    migrate.upgrade(connect_str, repo_url)
    LOG.info("Complete.")
示例#18
0
def mkdir_interactive(dirpath):
    """
    Create a directory if required.

    This will query the user for a confirmation.

    Args:
        dirname: The path to create.
    """
    from benchbuild.utils.cmd import mkdir
    if os.path.exists(dirpath):
        return

    response = ui.ask("The directory {dirname} does not exist yet. "
                      "Should I create it?".format(dirname=dirpath),
                      default_answer=True,
                      default_answer_str="yes")

    if response:
        mkdir("-p", dirpath)
        print("Created directory {0}.".format(dirpath))
示例#19
0
def maybe_update_db(repo_version, db_version):
    if db_version is None:
        return
    if db_version == repo_version:
        return

    LOG.warning("Your database contains version '%s' of benchbuild's schema.",
                db_version)
    LOG.warning(
        "Benchbuild currently requires version '%s' to work correctly.",
        repo_version)
    if not ui.ask("Should I attempt to update your schema to version '{0}'?".
                  format(repo_version)):
        LOG.error("User declined schema upgrade.")
        return

    connect_str = settings.CFG["db"]["connect_string"].value()
    repo_url = bbpath.template_path("../db/")
    LOG.info("Upgrading to newest version...")
    migrate.upgrade(connect_str, repo_url)
    LOG.info("Complete.")
示例#20
0
def mkdir_interactive(dirpath):
    """
    Create a directory if required.

    This will query the user for a confirmation.

    Args:
        dirname: The path to create.
    """
    from benchbuild.utils.cmd import mkdir
    if os.path.exists(dirpath):
        return

    response = ui.ask(
        "The directory {dirname} does not exist yet. "
        "Should I create it?".format(dirname=dirpath),
        default_answer=True,
        default_answer_str="yes")

    if response:
        mkdir("-p", dirpath)
        print("Created directory {0}.".format(dirpath))
示例#21
0
def test_ask(env):
    assert ask("Test?", default_answer=True) == True
    assert ask("Test?", default_answer=False) == False