Exemplo n.º 1
0
    def display_progress(self, **ka):
        """ display progress of any operation """
        if ka['operation'] in ["removing", "rebuilding-db"]:
            return

        elif ka['operation'] == "fetching":
            if not ctx.get_option("no_color"):
                complated_background = (ka['foregroundcolor']
                                        or 'backgroundgreen')
                queried_background = (ka['backgroundcolor']
                                      or 'backgroundyellow')
            else:
                complated_background = queried_background = "default"

            hr_size, hr_symbol = util.human_readable_size(ka["total_size"])
            phr_size, phr_symbol = util.human_readable_size(
                ka["downloaded_size"])
            totalsize = '{:.1f} {}'.format(hr_size, hr_symbol)
            nowsize = '{:.1f} {}'.format(phr_size, phr_symbol)

            file_and_totalsize = '[{:.40} {}/{}]'.format(
                ka['basename'], nowsize, totalsize)
            percentage_and_time = '{:.2f} {}'.format(ka['rate'], ka['symbol'])

            term_rows, term_columns = util.get_terminal_size()
            spacenum = (term_columns -
                        (len(file_and_totalsize) + len(percentage_and_time)))
            spacenum = spacenum - 10
            if spacenum < 1:
                spacenum = 0

            msg = file_and_totalsize + ' ' * spacenum + percentage_and_time

            lmsg = int((len(msg) * ka["percent"]) / 100) + 1
            # \r\x1b[2K erase current line
            if ka["percent"] < 100:
                self.output("\r\x1b[2K" +
                            ctx.const.colors[complated_background] +
                            "{:6.2f}% ".format(ka['percent']) + msg[:lmsg] +
                            ctx.const.colors[queried_background] + msg[lmsg:] +
                            ctx.const.colors['default'])
            else:
                self.output("\r\x1b[2K\x1b[A")  # @@@
            util.xterm_title("{} ( {:.2f} % )".format(ka['filename'],
                                                      ka['percent']))

        else:
            self.output("\r{} ( {:.2f} % )".format(ka['info'], ka['percent']))

            util.xterm_title("{} ( {:.2f} % )".format(ka['info'],
                                                      ka['percent']))
Exemplo n.º 2
0
    def __str__(self):
        s = specfile.Package.__str__(self)
        i_size = util.human_readable_size(self.installedSize)
        size = "%.2f %s" % (i_size[0], i_size[1])

        s += _('Distribution: {0}, Dist. Release: {1}\n').format(
            self.distribution, self.distributionRelease)
        s += _('Architecture: {0}, Installed Size: {1}').format(
            self.architecture, size)

        if self.packageSize:
            p_size = util.human_readable_size(self.packageSize)
            size = "%.2f %s" % (p_size[0], p_size[1])
            s += _(', Package Size: {}').format(size)

        s += _(', install.tar.xz sha1sum: {}').format(self.installTarHash)

        return s
Exemplo n.º 3
0
 def check_requirements(self):
     """check system requirements"""
     # Check free space
     total_size, symbol = util.human_readable_size(util.free_space())
     if util.free_space() < self.installedSize:
         raise Error(_("Is there enought free space in your disk?"))
     ctx.ui.info(_(
         "Free space in \'destinationdirectory\': {:.2f} {} ".format(
             total_size, symbol)),
                 verbose=True)
Exemplo n.º 4
0
def calculate_free_space_needed(order):
    total_needed = 0
    installdb = inary.db.installdb.InstallDB()
    packagedb = inary.db.packagedb.PackageDB()

    for pkg in [packagedb.get_package(name) for name in order]:
        delta = None
        if installdb.has_package(pkg.name):
            release = installdb.get_release(pkg.name)
            (distro, distro_release) = installdb.get_distro_release(pkg.name)

            # inary distro upgrade should not use delta support
            if distro == pkg.distribution and distro_release == pkg.distributionRelease:
                delta = pkg.get_delta(release)

            ignore_delta = ctx.config.values.general.ignore_delta

            installed_release_size = installdb.get_package(
                pkg.name).installedSize

            if delta and not ignore_delta:
                pkg_size = delta.installedSize
            else:
                pkg_size = pkg.installedSize - installed_release_size

            total_needed += pkg_size

        else:
            total_needed += int(packagedb.get_package(pkg.name).installedSize)

    needed, symbol = util.human_readable_size(total_needed)

    if total_needed < 0:
        ctx.ui.info(_("After this operation, {:.2f} {} space will be freed.").format(
            abs(int(needed)), symbol), color='cyan')
    else:
        ctx.ui.info(_("After this operation, {:.2f} {} space will be used.").format(
            abs(int(needed)), symbol), color='cyan')

    return total_needed
Exemplo n.º 5
0
    def notify(self, event, logging=True, **keywords):
        is_debug = False
        notify = True
        if event == inary.ui.installed:
            msg = _('Installed \"{}\"').format(keywords['package'].name)
            color = 'brightgreen'
        elif event == inary.ui.installing:
            msg = _(
                'Installing \"{0.name}\", version {0.version}, release {0.release}'
            ).format(keywords['package'])
            color = 'faintblue'
        elif event == inary.ui.removed:
            msg = _('Removed \"{}\"').format(keywords['package'].name)
            color = 'brightgreen'
        elif event == inary.ui.removing:
            msg = _('Removing \"{}\"').format(keywords['package'].name)
            color = 'brightpurple'
        elif event == inary.ui.upgraded:
            msg = _('Upgraded \"{}\"').format(keywords['package'].name)
            color = 'brightgreen'
        elif event == inary.ui.configured:
            msg = _('Configured \"{}\"').format(keywords['package'].name)
            color = 'brightgreen'
        elif event == inary.ui.configuring:
            msg = _('Configuring \"{}\"').format(keywords['package'].name)
            color = 'faintyellow'
        elif event == inary.ui.extracting:
            msg = _('Extracting the files of \"{}\"').format(
                keywords['package'].name)
            color = 'faintgreen'
        elif event == inary.ui.updatingrepo:
            msg = _('Updating package repository: \"{}\"').format(
                keywords['name'])
            color = 'green'
        elif event == inary.ui.cached:
            total_size, total_symbol = util.human_readable_size(
                keywords['total'])
            cached_size, cached_symbol = util.human_readable_size(
                keywords['cached'])
            msg = _('Total size of package(s): {:.2f} {} / {:.2f} {}').format(
                cached_size, cached_symbol, total_size, total_symbol)
            color = 'cyan'
            notify = False
        elif event == inary.ui.packagestogo:
            if ctx.log:
                ctx.log.info(
                    _("Following packages ordered for process: {}").format(
                        keywords['order']))
            msg = None
            notify = False
        elif event == inary.ui.desktopfile:
            if ctx.log:
                ctx.log.info(
                    _("Extracted desktop file \"{}\"").format(
                        keywords['desktopfile']))
            msg = None

        elif event == inary.ui.fetched:
            if self.show_verbose:
                msg = ""
            else:
                msg = "\x1b[K"
            msg += _("Downloaded \"{}\"".format(keywords['name']))
            color = "green"
            is_debug = True

        else:
            msg = None

        if msg:
            if ((not is_debug) or ctx.get_option('debug')):
                self.output(util.colorize(msg + '\n', color))
                if ctx.log and logging:
                    ctx.log.info(msg)
                if notify:
                    self.notify(msg, push_screen=False)
Exemplo n.º 6
0
def remove(A, ignore_dep=False, ignore_safety=False):
    """
    Removes the given packages from the system
    @param A: list of package names -> list_of_strings
    @param ignore_dep: removes packages without looking into theirs reverse deps if True
    @param ignore_safety: system.base packages can also be removed if True
    """
    inary.db.historydb.HistoryDB().create_history("remove")
    componentdb = inary.db.componentdb.ComponentDB()
    installdb = inary.db.installdb.InstallDB()

    A = [str(x) for x in A]

    # filter packages that are not installed
    A_0 = A = set(A)

    if not ctx.get_option(
            'ignore_safety'
    ) and not ctx.config.values.general.ignore_safety and not ignore_safety:
        if componentdb.has_component('system.base'):
            systembase = set(
                componentdb.get_union_component('system.base').packages)
            refused = A.intersection(systembase)
            if refused:
                raise inary.errors.Error(
                    _("Safety switch prevents the removal of "
                      "following packages:\n") +
                    util.format_by_columns(sorted(refused)))
                A = A - systembase
        else:
            ctx.ui.warning(
                _("Safety switch: The component system.base cannot be found."))

    Ap = []
    for x in A:
        if installdb.has_package(x):
            Ap.append(x)
        else:
            ctx.ui.info(
                _('Package \"{}\" does not exist. Cannot remove.').format(x))
    A = set(Ap)

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

    if not ctx.config.get_option('ignore_dependency') and not ignore_dep:
        G_f, order = plan_remove(A)
    else:
        G_f = None
        order = A

    ctx.ui.info(_("""The following list of packages will be removed
in the respective order to satisfy dependencies:"""),
                color='green')
    ctx.ui.info(util.strlist(order))
    if len(order) > len(A_0):
        if not ctx.ui.confirm(_('Would you like to continue?')):
            ctx.ui.warning(_('Package removal declined.'))
            return False

    removal_size = 0
    for pkg in [installdb.get_package(name) for name in order]:
        removal_size += pkg.installedSize

    removal_size, symbol = util.human_readable_size(removal_size)
    ctx.ui.info(_('{:.2f} {} space will be freed.').format(
        removal_size, symbol),
                color='cyan')
    del removal_size, symbol

    if not ctx.ui.confirm(_("Would you like to continue?")):
        ctx.ui.warning(_('Package removal declined.'))
        return False

    if ctx.get_option('dry_run'):
        return

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

    for x in order:
        if installdb.has_package(x):
            atomicoperations.remove_single(x)
            if 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 ""))

        else:
            ctx.ui.info(
                _('Package \"{}\" is not installed. Cannot remove.').format(x))