Exemplo n.º 1
0
    def run(self, args):
        view = output.View()
        if args.distro_def_create:
            if not (args.distro_def_name and args.distro_def_version and
                    args.distro_def_arch and args.distro_def_type and
                    args.distro_def_path):
                error_msg = ('Required arguments: name, version, arch, type '
                             'and path')
                view.notify(event="error", msg=error_msg)
                sys.exit(exit_codes.AVOCADO_FAIL)

            output_file_name = self.get_output_file_name(args)
            if os.path.exists(output_file_name):
                error_msg = ('Output file "%s" already exists, will not '
                             'overwrite it' % output_file_name)
                view.notify(event="error", msg=error_msg)
            else:
                view.notify(event="message",
                            msg=("Loading distro information from tree... "
                                 "Please wait..."))
                distro = load_from_tree(args.distro_def_name,
                                        args.distro_def_version,
                                        args.distro_def_release,
                                        args.distro_def_arch,
                                        args.distro_def_type,
                                        args.distro_def_path)
                save_distro(distro, output_file_name)
                view.notify(event="message",
                            msg=('Distro information saved '
                                 'to "%s"' % output_file_name))
        else:
            detected = distro_utils.detect()
            msg = 'Detected distribution: %s (%s) version %s release %s' % (
                detected.name,
                detected.arch,
                detected.version,
                detected.release)
            view.notify(event="message", msg=msg)
Exemplo n.º 2
0
    def run(self, args):
        view = output.View()
        if args.distro_def_create:
            if not (args.distro_def_name and args.distro_def_version and
                    args.distro_def_arch and args.distro_def_type and
                    args.distro_def_path):
                error_msg = ('Required arguments: name, version, arch, type '
                             'and path')
                view.notify(event="error", msg=error_msg)
                sys.exit(exit_codes.AVOCADO_FAIL)

            output_file_name = self.get_output_file_name(args)
            if os.path.exists(output_file_name):
                error_msg = ('Output file "%s" already exists, will not '
                             'overwrite it' % output_file_name)
                view.notify(event="error", msg=error_msg)
            else:
                view.notify(event="message",
                            msg=("Loading distro information from tree... "
                                 "Please wait..."))
                distro = load_from_tree(args.distro_def_name,
                                        args.distro_def_version,
                                        args.distro_def_release,
                                        args.distro_def_arch,
                                        args.distro_def_type,
                                        args.distro_def_path)
                save_distro(distro, output_file_name)
                view.notify(event="message",
                            msg=('Distro information saved '
                                 'to "%s"' % output_file_name))
        else:
            detected = distro_utils.detect()
            msg = 'Detected distribution: %s (%s) version %s release %s' % (
                detected.name,
                detected.arch,
                detected.version,
                detected.release)
            view.notify(event="message", msg=msg)
Exemplo n.º 3
0
def install_distro_packages(distro_pkg_map, interactive=False):
    """
    Installs packages for the currently running distribution

    This utility function checks if the currently running distro is a
    key in the distro_pkg_map dictionary, and if there is a list of packages
    set as its value.

    If these conditions match, the packages will be installed using the
    software manager interface, thus the native packaging system if the
    currenlty running distro.

    :type distro_pkg_map: dict
    :param distro_pkg_map: mapping of distro name, as returned by
        utils.get_os_vendor(), to a list of package names
    :return: True if any packages were actually installed, False otherwise
    """
    if not interactive:
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'

    result = False
    pkgs = []
    detected_distro = distro.detect()

    distro_specs = [spec for spec in distro_pkg_map if
                    isinstance(spec, distro.Spec)]

    for distro_spec in distro_specs:
        if distro_spec.name != detected_distro.name:
            continue

        if (distro_spec.arch is not None and
                distro_spec.arch != detected_distro.arch):
            continue

        if int(detected_distro.version) < distro_spec.min_version:
            continue

        if (distro_spec.min_release is not None and
                int(detected_distro.release) < distro_spec.min_release):
            continue

        pkgs = distro_pkg_map[distro_spec]
        break

    if not pkgs:
        log.info("No specific distro release package list")

        # when comparing distro names only, fallback to a lowercase version
        # of the distro name is it's more common than the case as detected
        pkgs = distro_pkg_map.get(detected_distro.name, None)
        if not pkgs:
            pkgs = distro_pkg_map.get(detected_distro.name.lower(), None)

        if not pkgs:
            log.error("No generic distro package list")

    if pkgs:
        needed_pkgs = []
        software_manager = SoftwareManager()
        for pkg in pkgs:
            if not software_manager.check_installed(pkg):
                needed_pkgs.append(pkg)
        if needed_pkgs:
            text = ' '.join(needed_pkgs)
            log.info('Installing packages "%s"', text)
            result = software_manager.install(text)
    else:
        log.error("No packages found for %s %s %s %s",
                  detected_distro.name, detected_distro.arch,
                  detected_distro.version, detected_distro.release)
    return result
Exemplo n.º 4
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = distro.detect().name