~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to softwarecenter/db/pkginfo_impl/aptcache.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from gi.repository import GObject
27
27
from gi.repository import Gio
28
28
 
 
29
# we need this to get the size calculation done asyncronously and reliable
 
30
from aptdaemon.client import AptClient
 
31
 
 
32
from softwarecenter.db.pkginfo import PackageInfo, _Version
29
33
from softwarecenter.enums import PkgStates
30
 
 
31
 
from softwarecenter.db.pkginfo import PackageInfo, _Version
 
34
from softwarecenter.utils import ExecutionTime
32
35
 
33
36
LOG = logging.getLogger(__name__)
34
37
 
135
138
            "changed", self._on_apt_finished_stamp_changed)
136
139
        # this is fast, so ok
137
140
        self._language_packages = self._read_language_pkgs()
 
141
        # query the totalize on install using aptdaemon
 
142
        try:
 
143
            self.aptd_client = AptClient()
 
144
        except Exception as e:
 
145
            self.aptd_client = None
 
146
            logging.error("Can not get aptdaemon client: '%s', no "
 
147
                          "size information will be available " % e)
 
148
        self._aptd_trans = None
138
149
 
139
150
    @staticmethod
140
151
    def version_compare(a, b):
231
242
    def get_license(self, name):
232
243
        return None
233
244
 
234
 
    def open(self):
 
245
    def open(self, blocking=False):
235
246
        """ (re)open the cache, this sends cache-invalid, cache-ready signals
236
247
        """
237
248
        LOG.info("aptcache.open()")
238
249
        self._ready = False
239
250
        self.emit("cache-invalid")
240
 
        from softwarecenter.utils import ExecutionTime
 
251
        if blocking:
 
252
            progress = None
 
253
        else:
 
254
            progress = GtkMainIterationProgress()
241
255
        with ExecutionTime("open the apt cache (in event loop)"):
242
 
            if self._cache == None:
243
 
                self._cache = apt.Cache(GtkMainIterationProgress())
 
256
            if self._cache is None:
 
257
                self._cache = apt.Cache(progress)
244
258
            else:
245
 
                self._cache.open(GtkMainIterationProgress())
 
259
                self._cache.open(progress)
246
260
        self._ready = True
247
261
        self.emit("cache-ready")
248
262
        if self._cache.broken_count > 0:
391
405
    @convert_package_argument
392
406
    def _get_depends_by_type(self, pkg, types):
393
407
        version = pkg.installed
394
 
        if version == None:
 
408
        if version is None:
395
409
            version = pkg.candidate
396
410
        return version.get_dependencies(*types)
397
411
 
512
526
    @convert_package_argument
513
527
    def _get_changes_without_applying(self, pkg):
514
528
        try:
515
 
            if pkg.installed == None:
 
529
            if pkg.installed is None:
516
530
                pkg.mark_install()
517
531
            else:
518
532
                pkg.mark_delete()
566
580
            pkg._pkg, version._cand, archive_suite)
567
581
        return res
568
582
 
569
 
    def get_total_size_on_install(self, pkgname,
570
 
                                  addons_install=None, addons_remove=None,
571
 
                                  archive_suite=None):
572
 
        pkgs_to_install = []
573
 
        pkgs_to_remove = []
574
 
        total_download_size = 0  # in kB
575
 
        total_install_size = 0  # in kB
576
 
 
 
583
    # space calulcation stuff
 
584
    def _on_total_size_calculation_done(self, trans, space):
 
585
        pkgname = trans.packages[0][0]
 
586
        self.emit(
 
587
            "query-total-size-on-install-done",
 
588
            pkgname, trans.download, trans.space)
 
589
 
 
590
    def _on_trans_simulate_error(self, error):
 
591
        LOG.exception("simulate failed")
 
592
 
 
593
    def _on_trans_commit_packages_ready(self, trans):
 
594
        trans.connect("space-changed", self._on_total_size_calculation_done)
 
595
        try:
 
596
            trans.simulate(reply_handler=lambda: True,
 
597
                           error_handler=self._on_trans_simulate_error)
 
598
        except:
 
599
            LOG.exception("simulate failed")
 
600
 
 
601
    def query_total_size_on_install(self, pkgname,
 
602
                                    addons_install=[], addons_remove=[],
 
603
                                    archive_suite=""):
577
604
        if not pkgname in self._cache:
578
 
            return (0, 0)
579
 
 
580
 
        pkg = self._cache[pkgname]
581
 
        version = pkg.installed
582
 
 
583
 
        all_install = []
584
 
        if addons_install is not None:
585
 
            all_install += addons_install
586
 
 
587
 
        if version == None:
588
 
            # its important that its the first pkg as the depcache will
589
 
            # get cleared for each pkg and that will means that the
590
 
            # set_candidate_release is lost again
591
 
            all_install.append(pkgname)
592
 
 
593
 
        for p in all_install:
594
 
            # ensure that the archive_suite is set if needed, this needs to
595
 
            # be in the loop as the cache is cleared in each loop iteration
596
 
            if archive_suite:
597
 
                self._set_candidate_release(pkg, archive_suite)
598
 
            # now get the right version
599
 
            version = self._cache[p].candidate
600
 
            # this can happen on e.g. deb packages that are not in the cache
601
 
            # testcase: software-center google-chrome-stable_current_amd64.deb
602
 
            if not version:
603
 
                continue
604
 
            pkgs_to_install.append(version)
605
 
            # now do it
606
 
            deps_inst = self._try_install_and_get_all_deps_installed(
607
 
                self._cache[p])
608
 
            for dep in deps_inst:
609
 
                if self._cache[dep].installed == None:
610
 
                    dep_version = self._cache[dep].candidate
611
 
                    pkgs_to_install.append(dep_version)
612
 
            deps_remove = self._try_install_and_get_all_deps_removed(
613
 
                self._cache[p])
614
 
            for dep in deps_remove:
615
 
                if self._cache[dep].is_installed:
616
 
                    dep_version = self._cache[dep].installed
617
 
                    pkgs_to_remove.append(dep_version)
618
 
 
619
 
        all_remove = [] if addons_remove is None else addons_remove
620
 
        for p in all_remove:
621
 
            version = self._cache[p].installed
622
 
            pkgs_to_remove.append(version)
623
 
            deps_inst = self._try_install_and_get_all_deps_installed(
624
 
                self._cache[p])
625
 
            for dep in deps_inst:
626
 
                if self._cache[dep].installed == None:
627
 
                    version = self._cache[dep].candidate
628
 
                    pkgs_to_install.append(version)
629
 
            deps_remove = self._try_install_and_get_all_deps_removed(
630
 
                self._cache[p])
631
 
            for dep in deps_remove:
632
 
                if self._cache[dep].installed != None:
633
 
                    version = self._cache[dep].installed
634
 
                    pkgs_to_remove.append(version)
635
 
 
636
 
        pkgs_to_install = list(set(pkgs_to_install))
637
 
        pkgs_to_remove = list(set(pkgs_to_remove))
638
 
 
639
 
        for pkg in pkgs_to_install:
640
 
            if not pkg_downloaded(pkg) and not pkg.package.installed:
641
 
                total_download_size += pkg.size
642
 
            total_install_size += pkg.installed_size
643
 
        for pkg in pkgs_to_remove:
644
 
            total_install_size -= pkg.installed_size
645
 
 
646
 
        return (total_download_size, total_install_size)
 
605
            self.emit("query-total-size-on-install-done", pkgname, 0, 0)
 
606
 
 
607
        # ensure the syntax is right
 
608
        if archive_suite:
 
609
            pkgname = pkgname + "/" + archive_suite
 
610
 
 
611
        # and simulate the install/remove via aptdaemon
 
612
        install = [pkgname] + addons_install
 
613
        remove = addons_remove
 
614
        reinstall = purge = upgrade = downgrade = []
 
615
 
 
616
        if self._aptd_trans:
 
617
            self._aptd_trans.cancel()
 
618
            self._aptd_trans = None
 
619
 
 
620
        # do this async
 
621
        try:
 
622
            self.aptd_client.commit_packages(
 
623
                install, reinstall, remove, purge, upgrade, downgrade,
 
624
                # wait
 
625
                False,
 
626
                # reply and error handlers
 
627
                self._on_trans_commit_packages_ready,
 
628
                self._on_trans_simulate_error)
 
629
        except:
 
630
            LOG.exception(
 
631
                "getting commit_packages trans failed for '%s'" % pkgname)
647
632
 
648
633
    def get_all_deps_upgrading(self, pkg):
649
634
        # note: this seems not to be used anywhere