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

« back to all changes in this revision

Viewing changes to softwarecenter/utils.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-12-06 17:30:50 UTC
  • Revision ID: package-import@ubuntu.com-20121206173050-n7mxi5fzlsvtdh9l
Tags: 5.5.2
* lp:~mvo/software-center/fix-pygobject-deprecation-warnings:
  - fix deprecation warninings with the latest python-gi
* lp:~mvo/software-center/minor-logging-fixes:
  - drop some LOG.info() messages to LOG.debug() to spam the user
    less
* lp:~mvo/software-center/trivial-close-ui-tweak:
  - hide the main window immediately when closing down
* lp:~mvo/software-center/5.4-fix-save-person-to-config:
  - This branch ensures that the "username" is saved everytime
    that the ubuntu sso whoami call is done
* lp:~mvo/software-center/use-dpkg-builddeps:
  - use dpkg-checkbuilddeps to find test-dependencies
* lp:~mvo/software-center/update-sc-cmdline-flexibility:
  - update-software-center-agent: 
    + add --target-db-path commandline
  - update-software-center: 
    + add --app-install-desktop-dir and --target-db-path commandline
* lp:~mvo/software-center/raring-pep8:
  - fixes for new pep8

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import gc
21
21
import gettext
22
22
from gi.repository import GObject
 
23
from gi.repository import GLib
23
24
from gi.repository import Gio
24
25
import logging
25
26
import math
42
43
from paths import (
43
44
    SOFTWARE_CENTER_CACHE_DIR,
44
45
    OEM_CHANNEL_DESCRIPTOR,
45
 
    )
 
46
)
46
47
 
47
48
from config import get_config
48
49
 
146
147
            size, resident, share, text, lib, data, dt = f.readline().split()
147
148
        return {'resident': int(resident),
148
149
                'data': int(data),
149
 
               }
 
150
                }
150
151
 
151
152
 
152
153
def utf8(s):
183
184
        if not self.cache.ready:
184
185
            if window:
185
186
                window.set_cursor(self.busy_cursor)
186
 
            GObject.timeout_add(500, lambda: wrapper(*args, **kwargs))
 
187
            GLib.timeout_add(500, lambda: wrapper(*args, **kwargs))
187
188
            return False
188
189
        # cache ready now
189
190
        if window:
465
466
    try:
466
467
        icon = icons.load_icon(iconname, iconsize, 0)
467
468
    except Exception as e:
468
 
        LOG.warning(utf8("could not load icon '%s', displaying missing "
469
 
                         "icon instead: %s ") % (
470
 
                utf8(iconname), utf8(e.message)))
 
469
        LOG.warning(
 
470
            utf8("could not load icon '%s', displaying missing "
 
471
                 "icon instead: %s ") % (utf8(iconname), utf8(e.message)))
471
472
        icon = icons.load_icon(missingicon, iconsize, 0)
472
473
    return icon
473
474
 
478
479
    return the file path of the icon in the theme that corresponds to the
479
480
    given iconname, or None if it cannot be determined
480
481
    """
481
 
    if (not iconname or
482
 
        not icons.has_icon(iconname)):
 
482
    if not iconname or not icons.has_icon(iconname):
483
483
        iconname = Icons.MISSING_APP
484
484
    try:
485
485
        icon_info = icons.lookup_icon(iconname, iconsize, 0)
518
518
            return installed_desktop_file_path
519
519
        # files in the extras archive have their desktop filenames prepended
520
520
        # by "extras-", so we check for that also (LP: #1012877)
521
 
        extras_desktop_file_path = ("/usr/share/applications/"
522
 
            "extras-%s.desktop" % pkgname)
 
521
        extras_desktop_file_path = \
 
522
            "/usr/share/applications/extras-%s.desktop" % pkgname
523
523
        if os.path.exists(extras_desktop_file_path):
524
524
            return extras_desktop_file_path
525
525
    LOG.warn("Could not determine the installed desktop file path for "
536
536
        DBUS_BUS_NAME,
537
537
        DBUS_CREDENTIALS_IFACE,
538
538
        DBUS_CREDENTIALS_PATH,
539
 
        )
 
539
    )
540
540
    # clean
541
 
    loop = GObject.MainLoop()
 
541
    loop = GLib.MainLoop()
542
542
    bus = dbus.SessionBus()
543
543
    obj = bus.get_object(bus_name=DBUS_BUS_NAME,
544
544
                         object_path=DBUS_CREDENTIALS_PATH,
550
550
    proxy.connect_to_signal("CredentialsError", loop.quit)
551
551
    proxy.clear_credentials(appname, {})
552
552
    # ensure we don't hang forever here
553
 
    GObject.timeout_add_seconds(2, loop.quit)
 
553
    GLib.timeout_add_seconds(2, loop.quit)
554
554
    # run the mainloop until the credentials are clear
555
555
    loop.run()
556
556
 
609
609
 
610
610
 
611
611
def get_nice_size(n_bytes):
612
 
    nice_size = lambda s: [(s % 1024 ** i and "%.1f" % (s / 1024.0 ** i) or
613
 
        str(s / 1024 ** i)) + x.strip() for i, x in enumerate(' KMGTPEZY')
 
612
    nice_size = lambda s: [
 
613
        (s % 1024 ** i and "%.1f" % (s / 1024.0 ** i) or
 
614
         str(s / 1024 ** i)) + x.strip() for i, x in enumerate(' KMGTPEZY')
614
615
        if s < 1024 ** (i + 1) or i == 8][0]
615
616
    return nice_size(n_bytes)
616
617
 
623
624
    curr_name = get_person_from_config()
624
625
    if curr_name != username:
625
626
        config = get_config()
626
 
        if not config.has_section("reviews"):
627
 
            config.add_section("reviews")
628
 
        config.set("reviews", "username", username)
629
 
        config.write()
 
627
        config.reviews_username = username
630
628
        # refresh usefulness cache in the background once we know
631
629
        # the person
632
630
        from backend.reviews import UsefulnessCache
638
636
    """ get the username value for Ubuntu SSO from the config file
639
637
    """
640
638
    cfg = get_config()
641
 
    if cfg.has_option("reviews", "username"):
642
 
        return cfg.get("reviews", "username")
643
 
    return None
 
639
    return cfg.reviews_username
644
640
 
645
641
 
646
642
def pnormaldist(qn):
735
731
        if os.path.exists(path):
736
732
            softwarecenter.paths.APP_INSTALL_PATH = './build/share/app-install'
737
733
            logging.warn("using local APP_INSTALL_PATH: %s" %
738
 
                             softwarecenter.paths.APP_INSTALL_PATH)
 
734
                         softwarecenter.paths.APP_INSTALL_PATH)
739
735
    else:
740
736
        datadir = softwarecenter.paths.datadir
741
737
        xapian_base_path = softwarecenter.paths.XAPIAN_BASE_PATH
854
850
                  GObject.TYPE_NONE,
855
851
                  (GObject.TYPE_PYOBJECT,
856
852
                   GObject.TYPE_PYOBJECT,),),
857
 
        }
 
853
    }
858
854
 
859
855
    def __init__(self):
860
856
        GObject.GObject.__init__(self)
872
868
            instead a permanent cache dir - no etag or timestamp
873
869
            checks are performed.
874
870
        """
875
 
        self.LOG.debug("download_file: %s %s %s" % (
876
 
                url, dest_file_path, use_cache))
 
871
        self.LOG.debug(
 
872
            "download_file: %s %s %s" % (url, dest_file_path, use_cache))
877
873
 
878
874
        # cancel anything pending to avoid race conditions
879
875
        # like bug #839462
933
929
        # self._cancel but self.url/self.dest_file_path will still point to
934
930
        # the wrong file
935
931
        if self.url != want_url:
936
 
            self.LOG.warn("url changed from '%s' to '%s'" % (
937
 
                    want_url, self.url))
 
932
            self.LOG.warn(
 
933
                "url changed from '%s' to '%s'" % (want_url, self.url))
938
934
            return False
939
935
        return True
940
936