Esempio n. 1
0
def upgrade(A=[], repo=None):
    """Re-installs packages from the repository, trying to perform
    a minimum or maximum number of upgrades according to options."""

    packagedb = pisi.db.packagedb.PackageDB()
    installdb = pisi.db.installdb.InstallDB()
    replaces = packagedb.get_replaces()
    if not A:
        # if A is empty, then upgrade all packages
        A = installdb.list_installed()

    if repo:
        repo_packages = set(packagedb.list_packages(repo))
        A = set(A).intersection(repo_packages)

    A_0 = A = set(A)
    Ap = find_upgrades(A, replaces)
    A = set(Ap)

    # Force upgrading of installed but replaced packages or else they will be removed (they are obsoleted also).
    # This is not wanted for a replaced driver package (eg. nvidia-X).
    A |= set(pisi.util.flatten_list(replaces.values()))

    A |= upgrade_base(A)

    A = pisi.blacklist.exclude_from(A, ctx.const.blacklist)

    if ctx.get_option('exclude_from'):
        A = pisi.blacklist.exclude_from(A, ctx.get_option('exclude_from'))

    if ctx.get_option('exclude'):
        A = pisi.blacklist.exclude(A, ctx.get_option('exclude'))

    ctx.ui.debug('A = %s' % str(A))

    if len(A) == 0:
        ctx.ui.info(_('No packages to upgrade.'))
        return True

    ctx.ui.debug('A = %s' % str(A))

    if not ctx.config.get_option('ignore_dependency'):
        G_f, order = plan_upgrade(A, replaces=replaces)
    else:
        G_f = None
        order = list(A)

    componentdb = pisi.db.componentdb.ComponentDB()

    # Bug 4211
    if componentdb.has_component('system.base'):
        order = operations.helper.reorder_base_packages(order)

    ctx.ui.status(_('The following packages will be upgraded:'))
    ctx.ui.info(util.format_by_columns(sorted(order)))

    total_size, cached_size = operations.helper.calculate_download_sizes(order)
    total_size, symbol = util.human_readable_size(total_size)
    ctx.ui.info(
        util.colorize(
            _('Total size of package(s): %.2f %s') % (total_size, symbol),
            "yellow"))

    needs_confirm = check_update_actions(order)

    # NOTE: replaces.values() was already flattened above, it can be reused
    if set(order) - A_0 - set(pisi.util.flatten_list(replaces.values())):
        ctx.ui.warning(_("There are extra packages due to dependencies."))
        needs_confirm = True

    if ctx.get_option('dry_run'):
        return

    if needs_confirm and \
            not ctx.ui.confirm(_("Do you want to continue?")):
        return False

    ctx.ui.notify(ui.packagestogo, order=order)

    conflicts = []
    if not ctx.get_option('ignore_package_conflicts'):
        conflicts = operations.helper.check_conflicts(order, packagedb)

    paths = []
    for x in order:
        ctx.ui.info(
            util.colorize(
                _("Downloading %d / %d") % (order.index(x) + 1, len(order)),
                "yellow"))
        install_op = atomicoperations.Install.from_name(x)
        paths.append(install_op.package_fname)

    # fetch to be upgraded packages but do not install them.
    if ctx.get_option('fetch_only'):
        return

    if conflicts:
        operations.remove.remove_conflicting_packages(conflicts)

    operations.remove.remove_obsoleted_packages()

    for path in paths:
        ctx.ui.info(
            util.colorize(
                _("Installing %d / %d") % (paths.index(path) + 1, len(paths)),
                "yellow"))
        install_op = atomicoperations.Install(path, ignore_file_conflicts=True)
        install_op.install(not ctx.get_option('compare_sha1sum'))
Esempio n. 2
0
def install_pkg_names(A, reinstall = False, extra = False):
    """This is the real thing. It installs packages from
    the repository, trying to perform a minimum number of
    installs"""

    installdb = pisi.db.installdb.InstallDB()
    packagedb = pisi.db.packagedb.PackageDB()

    A = [str(x) for x in A] #FIXME: why do we still get unicode input here? :/ -- exa
    # A was a list, remove duplicates
    A_0 = A = set(A)

    # filter packages that are already installed
    if not reinstall:
        Ap = set(filter(lambda x: not installdb.has_package(x), A))
        d = A - Ap
        if len(d) > 0:
            ctx.ui.warning(_("The following package(s) are already installed "
                             "and are not going to be installed again:"))
            ctx.ui.info(util.format_by_columns(sorted(d)))
            A = Ap

    if len(A)==0:
        ctx.ui.info(_('No packages to install.'))
        return True

    A |= operations.upgrade.upgrade_base(A)

    if not ctx.config.get_option('ignore_dependency'):
        G_f, order = plan_install_pkg_names(A)
    else:
        G_f = None
        order = list(A)

    componentdb = pisi.db.componentdb.ComponentDB()

    # Bug 4211
    if componentdb.has_component('system.base'):
        order = operations.helper.reorder_base_packages(order)

    if len(order) > 1:
        ctx.ui.info(util.colorize(_("Following packages will be installed:"), "brightblue"))
        ctx.ui.info(util.format_by_columns(sorted(order)))

    total_size, cached_size = operations.helper.calculate_download_sizes(order)
    total_size, symbol = util.human_readable_size(total_size)
    ctx.ui.info(util.colorize(_('Total size of package(s): %.2f %s') % (total_size, symbol), "yellow"))

    if ctx.get_option('dry_run'):
        return True

    extra_packages = set(order) - A_0
    if extra_packages:
        if not ctx.ui.confirm(_('There are extra packages due to dependencies. Do you want to continue?')):
            return False

    ctx.ui.notify(ui.packagestogo, order = order)

    ignore_dep = ctx.config.get_option('ignore_dependency')

    conflicts = []
    if not ctx.get_option('ignore_package_conflicts'):
        conflicts = operations.helper.check_conflicts(order, packagedb)

    paths = []
    extra_paths = {}
    for x in order:
        ctx.ui.info(util.colorize(_("Downloading %d / %d") % (order.index(x)+1, len(order)), "yellow"))
        install_op = atomicoperations.Install.from_name(x)
        paths.append(install_op.package_fname)
        if x in extra_packages or (extra and x in A):
            extra_paths[install_op.package_fname] = x
        elif reinstall and  x in installdb.installed_extra:
            installdb.installed_extra.remove(x)
            with open(os.path.join(ctx.config.info_dir(), ctx.const.installed_extra), "w") as ie_file:
                ie_file.write("\n".join(installdb.installed_extra) + ("\n" if installdb.installed_extra else ""))


    # fetch to be installed packages but do not install them.
    if ctx.get_option('fetch_only'):
        return

    if conflicts:
        operations.remove.remove_conflicting_packages(conflicts)

    for path in paths:
        ctx.ui.info(util.colorize(_("Installing %d / %d") % (paths.index(path)+1, len(paths)), "yellow"))
        install_op = atomicoperations.Install(path)
        install_op.install(False)
        try:
            with open(os.path.join(ctx.config.info_dir(), ctx.const.installed_extra), "a") as ie_file:
                ie_file.write("%s\n" % extra_paths[path])
            installdb.installed_extra.append(extra_paths[path])
        except KeyError:
            pass

    return True
Esempio n. 3
0
def upgrade_pkg_names(A=[]):
    """Re-installs packages from the repository, trying to perform
    a minimum or maximum number of upgrades according to options."""

    ignore_build = ctx.get_option('ignore_build_no')
    security = ctx.get_option('security')

    if not A:
        # if A is empty, then upgrade all packages
        A = ctx.installdb.list_installed()

    A_0 = A = expand_components(set(A))

    Ap = []
    for x in A:
        if x.endswith(ctx.const.package_suffix):
            ctx.ui.debug(_("Warning: package *name* ends with '.pisi'"))

        if not ctx.installdb.is_installed(x):
            ctx.ui.info(_('Package %s is not installed.') % x, True)
            continue
        (version, release, build) = ctx.installdb.get_version(x)
        if ctx.packagedb.has_package(x):
            pkg = ctx.packagedb.get_package(x)
        else:
            ctx.ui.info(
                _('Package %s is not available in repositories.') % x, True)
            continue

        if security:  # below is a readable functional code, don't overflow lines!
            updates = [
                x for x in pkg.history if Version(x.release) > Version(release)
            ]
            if not pisi.util.any(lambda x: x.type == 'security', updates):
                continue

        if ignore_build or (not build) or (not pkg.build):
            if Version(release) < Version(pkg.release):
                Ap.append(x)
            else:
                ctx.ui.info(
                    _('Package %s is already at the latest release %s.') %
                    (pkg.name, pkg.release), True)
        else:
            if build < pkg.build:
                Ap.append(x)
            else:
                ctx.ui.info(
                    _('Package %s is already at the latest build %s.') %
                    (pkg.name, pkg.build), True)

    A = set(Ap)

    if len(A) == 0:
        ctx.ui.info(_('No packages to upgrade.'))
        return True

    A |= upgrade_base(A)

    ctx.ui.debug('A = %s' % str(A))

    if not ctx.config.get_option('ignore_dependency'):
        G_f, order = plan_upgrade(A, ignore_build)
    else:
        G_f = None
        order = A

    ctx.ui.info(
        _('The following packages will be upgraded: ') + util.strlist(order))

    total_size = sum([ctx.packagedb.get_package(p).packageSize for p in order])
    total_size, symbol = util.human_readable_size(total_size)
    ctx.ui.info(_('Total size of packages: %.2f %s') % (total_size, symbol))

    if ctx.get_option('dry_run'):
        return

    if len(order) > len(A_0):
        if not ctx.ui.confirm(
                _('There are extra packages due to dependencies. Do you want to continue?'
                  )):
            return False

    ctx.ui.notify(ui.packagestogo, order=order)

    paths = []
    for x in order:
        install_op = atomicoperations.Install.from_name(x)
        paths.append(install_op.package_fname)

    for path in paths:
        install_op = atomicoperations.Install(path, ignore_file_conflicts=True)
        install_op.install(True)

    if 'pisi' in order:
        upgrade_pisi()
Esempio n. 4
0
def install_pkg_names(A, reinstall=False):
    """This is the real thing. It installs packages from
    the repository, trying to perform a minimum number of
    installs"""

    installdb = pisi.db.installdb.InstallDB()
    packagedb = pisi.db.packagedb.PackageDB()

    A = [str(x)
         for x in A]  #FIXME: why do we still get unicode input here? :/ -- exa
    # A was a list, remove duplicates
    A_0 = A = set(A)

    # filter packages that are already installed
    if not reinstall:
        Ap = set(filter(lambda x: not installdb.has_package(x), A))
        d = A - Ap
        if len(d) > 0:
            ctx.ui.warning(
                _("The following package(s) are already installed and are not going to be installed again:\n"
                  ) + util.strlist(d))
            A = Ap

    if len(A) == 0:
        ctx.ui.info(_('No packages to install.'))
        return True

    A |= operations.upgrade.upgrade_base(A)

    if not ctx.config.get_option('ignore_dependency'):
        G_f, order = plan_install_pkg_names(A)
    else:
        G_f = None
        order = list(A)

    componentdb = pisi.db.componentdb.ComponentDB()

    # Bug 4211
    if componentdb.has_component('system.base'):
        order = operations.helper.reorder_base_packages(order)

    if len(order) > 1:
        ctx.ui.info(
            _("Following packages will be installed in the respective "
              "order to satisfy dependencies:\n") + util.strlist(order))

    total_size, cached_size = operations.helper.calculate_download_sizes(order)
    total_size, symbol = util.human_readable_size(total_size)
    ctx.ui.info(_('Total size of package(s): %.2f %s') % (total_size, symbol))

    if ctx.get_option('dry_run'):
        return True

    if set(order) - A_0:
        if not ctx.ui.confirm(
                _('There are extra packages due to dependencies. Do you want to continue?'
                  )):
            return False

    ctx.ui.notify(ui.packagestogo, order=order)

    ignore_dep = ctx.config.get_option('ignore_dependency')

    conflicts = []
    if not ctx.get_option('ignore_package_conflicts'):
        conflicts = operations.helper.check_conflicts(order, packagedb)

    paths = []
    for x in order:
        ctx.ui.info(
            util.colorize(
                _("Downloading %d / %d") % (order.index(x) + 1, len(order)),
                "yellow"))
        install_op = atomicoperations.Install.from_name(x)
        paths.append(install_op.package_fname)

    # fetch to be installed packages but do not install them.
    if ctx.get_option('fetch_only'):
        return

    if conflicts:
        operations.remove.remove_conflicting_packages(conflicts)

    for path in paths:
        ctx.ui.info(
            util.colorize(
                _("Installing %d / %d") % (paths.index(path) + 1, len(paths)),
                "yellow"))
        install_op = atomicoperations.Install(path)
        install_op.install(False)

    return True
Esempio n. 5
0
def upgrade_pkg_names(A=[]):
    """Re-installs packages from the repository, trying to perform
    a minimum or maximum number of upgrades according to options."""

    ignore_build = ctx.get_option('ignore_build_no')
    security_only = ctx.get_option('security_only')

    packagedb = pisi.db.packagedb.PackageDB()
    replaces = packagedb.get_replaces()

    installdb = pisi.db.installdb.InstallDB()

    if not A:
        # if A is empty, then upgrade all packages
        A = installdb.list_installed()

    A_0 = A = set(A)

    Ap = []
    for x in A:
        if x.endswith(ctx.const.package_suffix):
            ctx.ui.debug(_("Warning: package *name* ends with '.pisi'"))

        # Handling of replacement packages
        if x in replaces.values():
            Ap.append(x)
            continue

        if x in replaces.keys():
            Ap.append(replaces[x])
            continue

        if not installdb.has_package(x):
            ctx.ui.info(_('Package %s is not installed.') % x, True)
            continue
        (version, release, build) = installdb.get_version(x)
        if packagedb.has_package(x):
            pkg = packagedb.get_package(x)
        else:
            ctx.ui.info(
                _('Package %s is not available in repositories.') % x, True)
            continue

        if security_only:
            updates = [
                i for i in pkg.history if
                pisi.version.Version(i.release) > pisi.version.Version(release)
            ]
            if not pisi.util.any(lambda i: i.type == 'security', updates):
                continue

        if ignore_build or (not build) or (not pkg.build):
            if pisi.version.Version(release) < pisi.version.Version(
                    pkg.release):
                Ap.append(x)
            else:
                ctx.ui.info(
                    _('Package %s is already at the latest release %s.') %
                    (pkg.name, pkg.release), True)
        else:
            if build < pkg.build:
                Ap.append(x)
            else:
                ctx.ui.info(
                    _('Package %s is already at the latest build %s.') %
                    (pkg.name, pkg.build), True)

    A = set(Ap)

    if len(A) == 0:
        ctx.ui.info(_('No packages to upgrade.'))
        return True

    A |= upgrade_base(A)

    ctx.ui.debug('A = %s' % str(A))

    if not ctx.config.get_option('ignore_dependency'):
        G_f, order = plan_upgrade(A)
    else:
        G_f = None
        order = list(A)

    componentdb = pisi.db.componentdb.ComponentDB()

    # Bug 4211
    if componentdb.has_component('system.base'):
        order = operations.helper.reorder_base_packages(order)

    if not ctx.get_option('ignore_package_conflicts'):
        conflicts = operations.helper.check_conflicts(order, packagedb)

    ctx.ui.info(
        _('The following packages will be upgraded: ') + util.strlist(order))

    total_size, cached_size = operations.helper.calculate_download_sizes(order)
    total_size, symbol = util.human_readable_size(total_size)
    ctx.ui.info(_('Total size of package(s): %.2f %s') % (total_size, symbol))

    if ctx.get_option('dry_run'):
        return

    if set(order) - A_0 - set(replaces.values()):
        if not ctx.ui.confirm(
                _('There are extra packages due to dependencies. Do you want to continue?'
                  )):
            return False

    ctx.ui.notify(ui.packagestogo, order=order)

    paths = []
    for x in order:
        ctx.ui.info(
            util.colorize(
                _("Downloading %d / %d") % (order.index(x) + 1, len(order)),
                "yellow"))
        install_op = atomicoperations.Install.from_name(x)
        paths.append(install_op.package_fname)

    # fetch to be upgraded packages but do not install them.
    if ctx.get_option('fetch_only'):
        return

    if not ctx.get_option('ignore_package_conflicts'):
        if conflicts:
            operations.remove.remove_conflicting_packages(conflicts)

    if replaces:
        operations.remove.remove_replaced_packages(order, replaces)

    operations.remove.remove_obsoleted_packages()

    for path in paths:
        ctx.ui.info(
            util.colorize(
                _("Installing %d / %d") % (paths.index(path) + 1, len(paths)),
                "yellow"))
        install_op = atomicoperations.Install(path, ignore_file_conflicts=True)
        install_op.install(True)