~ubuntu-branches/ubuntu/quantal/software-center/quantal-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Anthony Lenton, Gary Lasker, Natalia Bidart
  • Date: 2012-03-09 08:55:46 UTC
  • Revision ID: package-import@ubuntu.com-20120309085546-p7p4ppu59ishighc
Tags: 5.1.12
[ Michael Vogt ]
* lp:~mvo/software-center/webcam-string-fix:
- small fix to support the debtagshw updated tags for hardware::camera
  (split into webcam,digicam now)
* lp:~mvo/software-center/trivial-nm-state-override:
  - support the SOFTWARE_CENTER_NET_CONNECTED environment value to
    force the connected state as a stopgap workaround for bug 911706
* lp:~mvo/software-center/lp941361:
  - adds a general make_string_from_list() helper to build (somewhat)
    i18n friendly human readable strings easily (LP: #941361)
* lp:~mvo/software-center/expunge-cache:
  - merge os.nice() addition
* lp:~mvo/software-center/lp789596:
  - better (less scary) string for updates from third-party
    venders (LP: #789596)
* lp:~mvo/software-center/fix-refresh-of-whats-new:
  - fix missing refresh of the what's new content on a database
    reopen so that new content from the agent appears as soon
    as it finishes the update
* lp:~mvo/software-center/review-fixes:
  - ensure ui is correctly updated after submitting/modifying review
* lp:~mvo/software-center/simulate-slow-network:
  - add a small helper to simulate a slow network connection to
    see if we have hidden latencies in the UI when the network
    is (really) slow
* lp:~mvo/software-center/top-rated-refresh:
  - ensure that the top-rated apps are refreshed when we have new data
* lp:~mvo/software-center/apptreeview-tweaks:
  - fix 'load_range" errors when navigating the installed view
    (LP: #913675), and do some nice needed refactoring/cleanup

[ Anthony Lenton ]
* lp:~elachuni/software-center/dont-store:
  - consolidate Ubunty SSO logins to use "Ubuntu Software Center", fixes
    inconsistent UI and storing of two keys in they keyring, as well as
    being prompted to log in twice the first time that you review an app
* lp:~elachuni/software-center/pep8-test,
  lp:~elachuni/software-center/pep8-test-part2,
  lp:~elachuni/software-center/pep8-test-part3,
  lp:~elachuni/software-center/pep8-test-part4:
  - add a unit test to check code statically for pep8 compliance and update
    more and more of the code to meet it

[ Gary Lasker ]
* lp:~gary-lasker/software-center/fix-crash-lp944875:
  - Fix an intermittent crash that can happen if the installed view pane
    has not been built yet when a call to show the spinner is made as a
    result of a refresh (LP: #944875)
* lp:~gary-lasker/software-center/list-view-icon-coordinates-lp947624:
  - This branch adds support for providing the correct icon size and 
    on-screen coordinates values in the Unity launcher integration dbus 
    call when an installation is initiated via the list view
    (LP: #947624)
* lp:~gary-lasker/software-center/enable-published-date-unit-test:
  - unit test change only, enable the published-date unit test that was
    disabled pending deployment of support on the staging server

[ Natalia Bidart ]
* lp:~nataliabidart/software-center/one-auth:
  - use consistently the same app name for every Ubuntu SSO call to
    ensure SSO tokens are handled properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
LOG = logging.getLogger('softwarecenter.db.packagekit')
29
29
 
 
30
 
30
31
class PkOrigin:
31
32
    def __init__(self, repo):
32
33
        if repo:
63
64
            self.component = 'main'
64
65
        self.site = ''
65
66
 
 
67
 
66
68
class PackagekitVersion(_Version):
67
69
    def __init__(self, package, pkginfo):
68
70
        self.package = package
75
77
 
76
78
    @property
77
79
    def downloadable(self):
78
 
        return True #FIXME: check for an equivalent
 
80
        return True  # FIXME: check for an equivalent
 
81
 
79
82
    @property
80
83
    def summary(self):
81
84
        return self.package.get_property('summary')
 
85
 
82
86
    @property
83
87
    def size(self):
84
88
        return self.pkginfo.get_size(self.package.get_name())
 
89
 
85
90
    @property
86
91
    def installed_size(self):
87
 
        """ In packagekit, installed_size can be fetched only for installed packages,
88
 
        and is stored in the same 'size' property as the package size """
 
92
        """In packagekit, installed_size can be fetched only for installed
 
93
        packages, and is stored in the same 'size' property as the package
 
94
        size"""
89
95
        return self.pkginfo.get_installed_size(self.package.get_name())
 
96
 
90
97
    @property
91
98
    def version(self):
92
99
        return self.package.get_version()
 
100
 
93
101
    @property
94
102
    def origins(self):
95
103
        return self.pkginfo.get_origins(self.package.get_name())
96
104
 
 
105
 
97
106
def make_locale_string():
98
107
    loc = locale.getlocale(locale.LC_MESSAGES)
99
108
    if loc[1]:
100
109
        return loc[0] + '.' + loc[1]
101
110
    return loc[0]
102
111
 
 
112
 
103
113
class PackagekitInfo(PackageInfo):
104
114
    USE_CACHE = True
105
115
 
107
117
        super(PackagekitInfo, self).__init__()
108
118
        self.client = packagekit.Client()
109
119
        self.client.set_locale(make_locale_string())
110
 
        self._cache = {} # temporary hack for decent testing
 
120
        self._cache = {}  # temporary hack for decent testing
111
121
        self._notfound_cache = []
112
122
        self._repocache = {}
113
123
        self.distro = get_distro()
136
146
            return PackagekitVersion(p, self) if p else None
137
147
 
138
148
    def get_candidate(self, pkgname):
139
 
        p = self._get_one_package(pkgname, pfilter=packagekit.FilterEnum.NEWEST)
 
149
        p = self._get_one_package(pkgname,
 
150
            pfilter=packagekit.FilterEnum.NEWEST)
140
151
        return PackagekitVersion(p, self) if p else None
141
152
 
142
153
    def get_versions(self, pkgname):
143
 
        return [PackagekitVersion(p, self) for p in self._get_packages(pkgname)]
 
154
        return [PackagekitVersion(p, self)
 
155
                for p in self._get_packages(pkgname)]
144
156
 
145
157
    def get_section(self, pkgname):
146
158
        # FIXME: things are fuzzy here - group-section association
167
179
        p = self._get_one_package(pkgname)
168
180
        if not p:
169
181
            return []
170
 
        res = self.client.get_files((p.get_id(),), None, self._on_progress_changed, None)
 
182
        res = self.client.get_files((p.get_id(),), None,
 
183
            self._on_progress_changed, None)
171
184
        files = res.get_files_array()
172
185
        if not files:
173
186
            return []
185
198
 
186
199
    def get_origins(self, pkgname):
187
200
        self._get_repolist()
188
 
        pkgs = self._get_packages(pkgname, pfilter=packagekit.FilterEnum.NOT_INSTALLED)
 
201
        pkgs = self._get_packages(pkgname,
 
202
            pfilter=packagekit.FilterEnum.NOT_INSTALLED)
189
203
        out = set()
190
204
 
191
205
        for p in pkgs:
223
237
        if not p:
224
238
            return []
225
239
        autoremove = False
226
 
        res = self.client.simulate_remove_packages((p.get_id(),), 
 
240
        res = self.client.simulate_remove_packages((p.get_id(),),
227
241
                                            autoremove, None,
228
242
                                            self._on_progress_changed, None,
229
243
        )
230
244
        if not res:
231
245
            return []
232
 
        return [p.get_name() for p in res.get_package_array() if p.get_name() != pkg.name]
 
246
        return [p.get_name()
 
247
                for p in res.get_package_array()
 
248
                if p.get_name() != pkg.name]
233
249
 
234
250
    def get_packages_removed_on_install(self, pkg):
235
251
        """ Returns a package names list of dependencies
237
253
        p = self._get_one_package(pkg.name)
238
254
        if not p:
239
255
            return []
240
 
        res = self.client.simulate_install_packages((p.get_id(),), 
 
256
        res = self.client.simulate_install_packages((p.get_id(),),
241
257
                                            None,
242
258
                                            self._on_progress_changed, None,
243
259
        )
244
260
        if not res:
245
261
            return []
246
 
        return [p.get_name() for p in res.get_package_array() if (p.get_name() != pkg.name) and p.get_info() == packagekit.InfoEnum.INSTALLED]
 
262
        return [p.get_name()
 
263
                for p in res.get_package_array()
 
264
                if (p.get_name() != pkg.name)
 
265
                and p.get_info() == packagekit.InfoEnum.INSTALLED]
247
266
 
248
 
    def get_total_size_on_install(self, pkgname, 
 
267
    def get_total_size_on_install(self, pkgname,
249
268
                                  addons_install=None, addons_remove=None,
250
269
                                  archive_suite=None):
251
270
        """ Returns a tuple (download_size, installed_size)
253
272
        plus addons change.
254
273
        """
255
274
        # FIXME: support archive_suite here too
256
 
        
 
275
 
257
276
        # FIXME: PackageKit reports only one size at a time
258
277
        if self.is_installed(pkgname):
259
278
            return (0, self.get_size(pkgname))
276
295
 
277
296
    """ private methods """
278
297
    def _get_package_details(self, packageid, cache=USE_CACHE):
279
 
        LOG.debug("package_details %s", packageid) #, self._cache.keys()
 
298
        LOG.debug("package_details %s", packageid)  # , self._cache.keys()
280
299
        if (packageid in self._cache.keys()) and cache:
281
300
            return self._cache[packageid]
282
301
 
283
 
        result = self.client.get_details((packageid,), None, self._on_progress_changed, None)
 
302
        result = self.client.get_details((packageid,), None,
 
303
            self._on_progress_changed, None)
284
304
        pkgs = result.get_details_array()
285
305
        if not pkgs:
286
306
            return None
287
307
        packageid = pkgs[0].get_property('package-id')
288
308
        self._cache[packageid] = pkgs[0]
289
309
        return pkgs[0]
290
 
 
291
 
    def _get_one_package(self, pkgname, pfilter=packagekit.FilterEnum.NONE, cache=USE_CACHE):
292
 
        LOG.debug("package_one %s", pkgname) #, self._cache.keys()
 
310
 
 
311
    def _get_one_package(self, pkgname, pfilter=packagekit.FilterEnum.NONE,
 
312
        cache=USE_CACHE):
 
313
        LOG.debug("package_one %s", pkgname)  # , self._cache.keys()
293
314
        if (pkgname in self._cache.keys()) and cache:
294
315
            return self._cache[pkgname]
295
316
        ps = self._get_packages(pkgname, pfilter)
313
334
        pkgs = result.get_package_array()
314
335
        return pkgs
315
336
 
316
 
    def _get_repolist(self, pfilter=packagekit.FilterEnum.NONE, cache=USE_CACHE):
 
337
    def _get_repolist(self, pfilter=packagekit.FilterEnum.NONE,
 
338
        cache=USE_CACHE):
317
339
        """ obtain and cache a dictionary of repositories """
318
340
        if self._repocache:
319
341
            return self._repocache
342
364
    def _on_progress_changed(self, progress, ptype, data=None):
343
365
        pass
344
366
 
345
 
if __name__=="__main__":
 
367
if __name__ == "__main__":
346
368
    pi = PackagekitInfo()
347
369
 
348
370
    print "Firefox, installed ", pi.is_installed('firefox')