Merge lp:~elachuni/software-center/pep8-test into lp:software-center

Proposed by Anthony Lenton
Status: Merged
Merged at revision: 2821
Proposed branch: lp:~elachuni/software-center/pep8-test
Merge into: lp:software-center
Diff against target: 1054 lines (+226/-92)
7 files modified
softwarecenter/db/pkginfo_impl/aptcache.py (+97/-41)
softwarecenter/db/pkginfo_impl/packagekit.py (+43/-21)
softwarecenter/ui/qml/app.py (+3/-2)
softwarecenter/ui/qml/categoriesmodel.py (+5/-5)
softwarecenter/ui/qml/pkglist.py (+22/-16)
softwarecenter/ui/qml/reviewslist.py (+7/-7)
test/test_pep8.py (+49/-0)
To merge this branch: bzr merge lp:~elachuni/software-center/pep8-test
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+96449@code.launchpad.net

Description of the change

This branch adds a test that checks the code statically using pep8 (http://pypi.python.org/pypi/pep8).

Only a couple of packages are being tested currently (namely softwarecenter.db.pkginfo_impl and softwarecenter.ui.qml) to keep the diff close to reasonable, just above 1K lines.

The plan would be to add packages to the list of checked code in subsequent branches. The kind of changes it proposes are only stylistic, long lines, trailing whitespace, whitespace around operators and declarations, etc. These changes shouldn't change any actual feature, and reviews (although long) should be relatively straight forwards.

The test itself is in the last 50 lines of the diff (starting around line 1000), and is probably the only non-trivial bit of the branch. Only once was there a whitespace issue that wasn't easy to fix, and that's around 499 of the diff: A combination of a bit too much indentation and long variable names meant that I wasn't sure how to fix that without
using a backslash. Let me know if you'd prefer some other solution.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

This is great! Thanks a lot, Anthony!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/db/pkginfo_impl/aptcache.py'
2--- softwarecenter/db/pkginfo_impl/aptcache.py 2012-02-14 10:08:18 +0000
3+++ softwarecenter/db/pkginfo_impl/aptcache.py 2012-03-07 20:23:18 +0000
4@@ -32,6 +32,7 @@
5
6 LOG = logging.getLogger(__name__)
7
8+
9 class GtkMainIterationProgress(apt.progress.base.OpProgress):
10 """Progress that just runs the main loop"""
11 def update(self, percent=0):
12@@ -39,6 +40,7 @@
13 while context.pending():
14 context.iteration()
15
16+
17 def convert_package_argument(f):
18 """ decorator converting _Package argument to Package object from cache """
19 def _converted(self, pkg, *args):
20@@ -47,18 +49,20 @@
21 if type(pkg) is str:
22 pkg = self._cache[pkg]
23 else:
24- pkg = self._cache[pkg.name]
25+ pkg = self._cache[pkg.name]
26 except Exception as e:
27 logging.exception(e)
28 pkg = None
29 return f(self, pkg, *args)
30 return _converted
31
32+
33 def pkg_downloaded(pkg_version):
34 filename = os.path.basename(pkg_version.filename)
35 # FIXME: use relative path here
36 return os.path.exists("/var/cache/apt/archives/" + filename)
37
38+
39 class AptCacheVersion(_Version):
40 def __init__(self, version):
41 self.ver = version
42@@ -66,24 +70,31 @@
43 @property
44 def description(self):
45 return self.ver.description
46+
47 @property
48 def summary(self):
49 return self.ver.summary
50+
51 @property
52 def size(self):
53 return self.ver.size
54+
55 @property
56 def installed_size(self):
57 return self.ver.installed_size
58+
59 @property
60 def version(self):
61 return self.ver.version
62+
63 @property
64 def origins(self):
65 return self.ver.origins
66+
67 @property
68 def downloadable(self):
69 return self.ver.downloadable
70+
71 @property
72 def not_automatic(self):
73 priority = self.ver.policy_priority
74@@ -91,8 +102,9 @@
75 return True
76 return False
77
78+
79 class AptCache(PackageInfo):
80- """
81+ """
82 A apt cache that opens in the background and keeps the UI alive
83 """
84
85@@ -115,8 +127,10 @@
86 self._ready = False
87 self._timeout_id = None
88 # setup monitor watch for install/remove changes
89- self.apt_finished_stamp=Gio.File.new_for_path(self.APT_FINISHED_STAMP)
90- self.apt_finished_monitor = self.apt_finished_stamp.monitor_file(0, None)
91+ self.apt_finished_stamp = Gio.File.new_for_path(
92+ self.APT_FINISHED_STAMP)
93+ self.apt_finished_monitor = self.apt_finished_stamp.monitor_file(0,
94+ None)
95 self.apt_finished_monitor.connect(
96 "changed", self._on_apt_finished_stamp_changed)
97 # this is fast, so ok
98@@ -125,10 +139,12 @@
99 @staticmethod
100 def version_compare(a, b):
101 return apt_pkg.version_compare(a, b)
102+
103 @staticmethod
104 def upstream_version_compare(a, b):
105 return apt_pkg.version_compare(apt_pkg.upstream_version(a),
106 apt_pkg.upstream_version(b))
107+
108 @staticmethod
109 def upstream_version(v):
110 return apt_pkg.upstream_version(v)
111@@ -138,11 +154,13 @@
112 lowlevel_cache = self._cache._cache
113 return (pkgname in lowlevel_cache and
114 lowlevel_cache[pkgname].current_ver is not None)
115+
116 def is_upgradable(self, pkgname):
117 # use the lowlevel cache here, twice as fast
118 if not pkgname in self._cache:
119 return False
120 return self._cache[pkgname].is_upgradable
121+
122 def is_available(self, pkgname):
123 return (pkgname in self._cache and
124 self._cache[pkgname].candidate)
125@@ -166,7 +184,7 @@
126 return [AptCacheVersion(v) for v in self._cache[pkgname].versions]
127
128 def get_section(self, pkgname):
129- if (pkgname not in self._cache or
130+ if (pkgname not in self._cache or
131 not self._cache[pkgname].candidate):
132 return ''
133 return self._cache[pkgname].candidate.section
134@@ -209,8 +227,10 @@
135 @property
136 def ready(self):
137 return self._ready
138+
139 def get_license(self, name):
140 return None
141+
142 def open(self):
143 """ (re)open the cache, this sends cache-invalid, cache-ready signals
144 """
145@@ -231,21 +251,25 @@
146
147 # temporarely return a full apt.Package so that the tests and the
148 # code keeps working for now, this needs to go away eventually
149- # and get replaced with the abstract _Package class
150+ # and get replaced with the abstract _Package class
151 #def __getitem__(self, key):
152 # return self._cache[key]
153
154 def __iter__(self):
155 return self._cache.__iter__()
156+
157 def __contains__(self, k):
158 return self._cache.__contains__(k)
159- def _on_apt_finished_stamp_changed(self, monitor, afile, other_file, event):
160+
161+ def _on_apt_finished_stamp_changed(self, monitor, afile, other_file,
162+ event):
163 if not event == Gio.FileMonitorEvent.CHANGES_DONE_HINT:
164- return
165+ return
166 if self._timeout_id:
167 GObject.source_remove(self._timeout_id)
168 self._timeout_id = None
169 self._timeout_id = GObject.timeout_add_seconds(10, self.open)
170+
171 def _get_rdepends_by_type(self, pkg, type, onlyInstalled):
172 rdeps = set()
173 # make sure this is a apt.Package object
174@@ -262,6 +286,7 @@
175 (onlyInstalled and self._cache[rdep_name].is_installed)):
176 rdeps.add(rdep.parent_pkg.name)
177 return rdeps
178+
179 def _installed_dependencies(self, pkg_name, all_deps=None):
180 """ recursively return all installed dependencies of a given pkg """
181 #print "_installed_dependencies", pkg_name, all_deps
182@@ -272,16 +297,18 @@
183 cur = self._cache[pkg_name]._pkg.current_ver
184 if not cur:
185 return all_deps
186- for t in self.DEPENDENCY_TYPES+self.RECOMMENDS_TYPES:
187+ for t in self.DEPENDENCY_TYPES + self.RECOMMENDS_TYPES:
188 try:
189 for dep in cur.depends_list[t]:
190 dep_name = dep[0].target_pkg.name
191 if not dep_name in all_deps:
192 all_deps.add(dep_name)
193- all_deps |= self._installed_dependencies(dep_name, all_deps)
194+ all_deps |= self._installed_dependencies(dep_name,
195+ all_deps)
196 except KeyError:
197 pass
198 return all_deps
199+
200 def get_installed_automatic_depends_for_pkg(self, pkg):
201 """ Get the installed automatic dependencies for this given package
202 only.
203@@ -298,7 +325,7 @@
204 except KeyError:
205 continue
206 else:
207- if (pkg.is_installed and
208+ if (pkg.is_installed and
209 pkg.is_auto_removable):
210 installed_auto_deps.add(dep_name)
211 return installed_auto_deps
212@@ -334,7 +361,7 @@
213 def get_origin(self, pkgname):
214 """
215 return a uniqe origin for the given package name. currently
216- this will use
217+ this will use
218 """
219 if not pkgname in self._cache or not self._cache[pkgname].candidate:
220 return
221@@ -352,9 +379,9 @@
222 """ check if the given component is enabled """
223 # FIXME: test for more properties here?
224 for it in self._cache._cache.file_list:
225- if (it.component != "" and
226+ if (it.component != "" and
227 it.component == component and
228- it.archive != "" and
229+ it.archive != "" and
230 it.archive == distro_codename):
231 return True
232 return False
233@@ -365,6 +392,7 @@
234 if version == None:
235 version = pkg.candidate
236 return version.get_dependencies(*types)
237+
238 def _get_depends_by_type_str(self, pkg, *types):
239 def not_in_list(list, item):
240 for i in list:
241@@ -384,33 +412,41 @@
242 # pkg relations
243 def _get_depends(self, pkg):
244 return self._get_depends_by_type_str(pkg, self.DEPENDENCY_TYPES)
245+
246 def _get_recommends(self, pkg):
247 return self._get_depends_by_type_str(pkg, self.RECOMMENDS_TYPES)
248+
249 def _get_suggests(self, pkg):
250 return self._get_depends_by_type_str(pkg, self.SUGGESTS_TYPES)
251+
252 def _get_enhances(self, pkg):
253 return self._get_depends_by_type_str(pkg, self.ENHANCES_TYPES)
254+
255 @convert_package_argument
256 def _get_provides(self, pkg):
257 # note: can use ._cand, because pkg has been converted to apt.Package
258 provides_list = pkg.candidate._cand.provides_list
259 provides = []
260 for provided in provides_list:
261- provides.append(provided[0]) # the package name
262+ provides.append(provided[0]) # the package name
263 return provides
264
265 # reverse pkg relations
266 def _get_rdepends(self, pkg):
267 return self._get_rdepends_by_type(pkg, self.DEPENDENCY_TYPES, False)
268+
269 def _get_rrecommends(self, pkg):
270 return self._get_rdepends_by_type(pkg, self.RECOMMENDS_TYPES, False)
271+
272 def _get_rsuggests(self, pkg):
273 return self._get_rdepends_by_type(pkg, self.SUGGESTS_TYPES, False)
274+
275 def _get_renhances(self, pkg):
276 return self._get_rdepends_by_type(pkg, self.ENHANCES_TYPES, False)
277+
278 @convert_package_argument
279 def _get_renhances_lowlevel_apt_pkg(self, pkg):
280- """ takes a apt_pkg.Package and returns a list of pkgnames that
281+ """ takes a apt_pkg.Package and returns a list of pkgnames that
282 enhance this package - this is needed to support enhances
283 for virtual packages
284 """
285@@ -419,6 +455,7 @@
286 if dep.dep_type_untranslated == "Enhances":
287 renhances.append(dep.parent_pkg.name)
288 return renhances
289+
290 def _get_rprovides(self, pkg):
291 return self._get_rdepends_by_type(pkg, self.PROVIDES_TYPES, False)
292
293@@ -436,10 +473,13 @@
294
295 def _get_installed_rrecommends(self, pkg):
296 return self._get_rdepends_by_type(pkg, self.RECOMMENDS_TYPES, True)
297+
298 def _get_installed_rsuggests(self, pkg):
299 return self._get_rdepends_by_type(pkg, self.SUGGESTS_TYPES, True)
300+
301 def _get_installed_renhances(self, pkg):
302 return self._get_rdepends_by_type(pkg, self.ENHANCES_TYPES, True)
303+
304 def _get_installed_rprovides(self, pkg):
305 return self._get_rdepends_by_type(pkg, self.PROVIDES_TYPES, True)
306
307@@ -450,6 +490,7 @@
308 if addon.startswith(template):
309 return True
310 return False
311+
312 def _read_language_pkgs(self):
313 language_packages = set()
314 if not os.path.exists(self.LANGPACK_PKGDEPENDS):
315@@ -464,7 +505,7 @@
316 continue
317 language_packages.add(language_pkg)
318 return language_packages
319-
320+
321 # these are used for calculating the total size
322 @convert_package_argument
323 def _get_changes_without_applying(self, pkg):
324@@ -492,6 +533,7 @@
325 changes[change.name] = PkgStates.UNKNOWN
326 self._cache.clear()
327 return changes
328+
329 def _try_install_and_get_all_deps_installed(self, pkg):
330 """ Return all dependencies of pkg that will be marked for install """
331 changes = self._get_changes_without_applying(pkg)
332@@ -500,6 +542,7 @@
333 if change != pkg.name and changes[change] == PkgStates.INSTALLING:
334 installing_deps.append(change)
335 return installing_deps
336+
337 def _try_install_and_get_all_deps_removed(self, pkg):
338 """ Return all dependencies of pkg that will be marked for remove"""
339 changes = self._get_changes_without_applying(pkg)
340@@ -508,6 +551,7 @@
341 if change != pkg.name and changes[change] == PkgStates.REMOVING:
342 removing_deps.append(change)
343 return removing_deps
344+
345 def _set_candidate_release(self, pkg, archive_suite):
346 # Check if the package is provided in the release
347 for version in pkg.versions:
348@@ -519,13 +563,14 @@
349 res = pkg._pcache._depcache.set_candidate_release(
350 pkg._pkg, version._cand, archive_suite)
351 return res
352- def get_total_size_on_install(self, pkgname,
353+
354+ def get_total_size_on_install(self, pkgname,
355 addons_install=None, addons_remove=None,
356 archive_suite=None):
357 pkgs_to_install = []
358 pkgs_to_remove = []
359- total_download_size = 0 # in kB
360- total_install_size = 0 # in kB
361+ total_download_size = 0 # in kB
362+ total_install_size = 0 # in kB
363
364 if not pkgname in self._cache:
365 return (0, 0)
366@@ -536,7 +581,7 @@
367 all_install = []
368 if addons_install is not None:
369 all_install += addons_install
370-
371+
372 if version == None:
373 # its important that its the first pkg as the depcache will
374 # get cleared for each pkg and that will means that the
375@@ -552,12 +597,14 @@
376 version = self._cache[p].candidate
377 pkgs_to_install.append(version)
378 # now do it
379- deps_inst = self._try_install_and_get_all_deps_installed(self._cache[p])
380+ deps_inst = self._try_install_and_get_all_deps_installed(
381+ self._cache[p])
382 for dep in deps_inst:
383 if self._cache[dep].installed == None:
384 dep_version = self._cache[dep].candidate
385 pkgs_to_install.append(dep_version)
386- deps_remove = self._try_install_and_get_all_deps_removed(self._cache[p])
387+ deps_remove = self._try_install_and_get_all_deps_removed(
388+ self._cache[p])
389 for dep in deps_remove:
390 if self._cache[dep].is_installed:
391 dep_version = self._cache[dep].installed
392@@ -567,12 +614,14 @@
393 for p in all_remove:
394 version = self._cache[p].installed
395 pkgs_to_remove.append(version)
396- deps_inst = self._try_install_and_get_all_deps_installed(self._cache[p])
397+ deps_inst = self._try_install_and_get_all_deps_installed(
398+ self._cache[p])
399 for dep in deps_inst:
400 if self._cache[dep].installed == None:
401 version = self._cache[dep].candidate
402 pkgs_to_install.append(version)
403- deps_remove = self._try_install_and_get_all_deps_removed(self._cache[p])
404+ deps_remove = self._try_install_and_get_all_deps_removed(
405+ self._cache[p])
406 for dep in deps_remove:
407 if self._cache[dep].installed != None:
408 version = self._cache[dep].installed
409@@ -580,7 +629,7 @@
410
411 pkgs_to_install = list(set(pkgs_to_install))
412 pkgs_to_remove = list(set(pkgs_to_remove))
413-
414+
415 for pkg in pkgs_to_install:
416 if not pkg_downloaded(pkg) and not pkg.package.installed:
417 total_download_size += pkg.size
418@@ -610,6 +659,7 @@
419 :return: a tuple of pkgnames (recommends, suggests)
420 """
421 logging.debug("get_addons for '%s'" % pkgname)
422+
423 def _addons_filter(addon):
424 """ helper for get_addons that filters out unneeded ones """
425 # we don't know about this one (prefectly legal for suggests)
426@@ -648,6 +698,7 @@
427 # looks good
428 return True
429 #----------------------------------------------------------------
430+
431 def _addons_filter_slow(addon):
432 """ helper for get_addons that filters out unneeded ones """
433 # this addon would get installed anyway (e.g. via indirect
434@@ -660,7 +711,7 @@
435 # deb file, or pkg needing source, etc
436 if (not pkgname in self._cache or
437 not self._cache[pkgname].candidate):
438- return ([],[])
439+ return ([], [])
440
441 # initial setup
442 pkg = self._cache[pkgname]
443@@ -678,7 +729,8 @@
444 LOG.debug("provides: %s" % provides)
445 for provide in provides:
446 virtual_aptpkg_pkg = self._cache._cache[provide]
447- renhances = self._get_renhances_lowlevel_apt_pkg(virtual_aptpkg_pkg)
448+ renhances = self._get_renhances_lowlevel_apt_pkg(
449+ virtual_aptpkg_pkg)
450 LOG.debug("renhances of %s: %s" % (provide, renhances))
451 addons_sug += renhances
452 context = GObject.main_context_default()
453@@ -688,9 +740,9 @@
454 # get more addons, the idea is that if a package foo-data
455 # just depends on foo we want to get the info about
456 # "recommends, suggests, enhances" for foo-data as well
457- #
458+ #
459 # FIXME: find a good package where this is actually the case and
460- # replace the existing test
461+ # replace the existing test
462 # (arduino-core -> avrdude -> avrdude-doc) with that
463 # FIXME2: if it turns out we don't have good/better examples,
464 # kill it
465@@ -700,11 +752,11 @@
466 pkgdep = self._cache[dep]
467 if len(self._get_rdepends(pkgdep)) == 1:
468 # pkg is the only known package that depends on pkgdep
469- pkgdep_rec = self._get_recommends(pkgdep)
470+ pkgdep_rec = self._get_recommends(pkgdep)
471 LOG.debug("recommends from lonley dependency %s: %s" % (
472 pkgdep, pkgdep_rec))
473 addons_rec += pkgdep_rec
474- pkgdep_sug = self._get_suggests(pkgdep)
475+ pkgdep_sug = self._get_suggests(pkgdep)
476 LOG.debug("suggests from lonley dependency %s: %s" % (
477 pkgdep, pkgdep_sug))
478 addons_sug += pkgdep_sug
479@@ -718,26 +770,30 @@
480 context.iteration()
481
482 # remove duplicates from suggests (sets are great!)
483- addons_sug = list(set(addons_sug)-set(addons_rec))
484+ addons_sug = list(set(addons_sug) - set(addons_rec))
485
486 # filter out stuff we don't want
487 addons_rec = filter(_addons_filter, addons_rec)
488 addons_sug = filter(_addons_filter, addons_sug)
489
490- # this is not integrated into the filter above, as it is quite expensive
491- # to run this call, so we only run it if we actually have addons
492+ # this is not integrated into the filter above, as it is quite
493+ # expensive to run this call, so we only run it if we actually have
494+ # addons
495 if addons_rec or addons_sug:
496 # now get all_deps if the package would be installed
497 try:
498- all_deps_if_installed = self._try_install_and_get_all_deps_installed(pkg)
499+ all_deps_if_installed = \
500+ self._try_install_and_get_all_deps_installed(pkg)
501 except:
502 # if we have broken packages, then we return no addons
503- LOG.warn("broken packages encountered while getting deps for %s" % pkgname)
504- return ([],[])
505+ LOG.warn(
506+ "broken packages encountered while getting deps for %s" %
507+ pkgname)
508+ return ([], [])
509 # filter out stuff we don't want
510 addons_rec = filter(_addons_filter_slow, addons_rec)
511 addons_sug = filter(_addons_filter_slow, addons_sug)
512-
513+
514 return (addons_rec, addons_sug)
515
516 if __name__ == "__main__":
517@@ -756,7 +812,7 @@
518 print(c.get_packages_removed_on_remove(pkg))
519 print(c._get_installed_rrecommends(pkg))
520 print(c._get_installed_rsuggests(pkg))
521-
522+
523 print("deps of gimp")
524 pkg = c["gimp"]
525 print(c._get_depends(pkg))
526@@ -764,7 +820,7 @@
527 print(c._get_suggests(pkg))
528 print(c._get_enhances(pkg))
529 print(c._get_provides(pkg))
530-
531+
532 print("rdeps of gimp")
533 print(c._get_rdepends(pkg))
534 print(c._get_rrecommends(pkg))
535
536=== modified file 'softwarecenter/db/pkginfo_impl/packagekit.py'
537--- softwarecenter/db/pkginfo_impl/packagekit.py 2012-02-14 09:51:45 +0000
538+++ softwarecenter/db/pkginfo_impl/packagekit.py 2012-03-07 20:23:18 +0000
539@@ -27,6 +27,7 @@
540
541 LOG = logging.getLogger('softwarecenter.db.packagekit')
542
543+
544 class PkOrigin:
545 def __init__(self, repo):
546 if repo:
547@@ -63,6 +64,7 @@
548 self.component = 'main'
549 self.site = ''
550
551+
552 class PackagekitVersion(_Version):
553 def __init__(self, package, pkginfo):
554 self.package = package
555@@ -75,31 +77,39 @@
556
557 @property
558 def downloadable(self):
559- return True #FIXME: check for an equivalent
560+ return True # FIXME: check for an equivalent
561+
562 @property
563 def summary(self):
564 return self.package.get_property('summary')
565+
566 @property
567 def size(self):
568 return self.pkginfo.get_size(self.package.get_name())
569+
570 @property
571 def installed_size(self):
572- """ In packagekit, installed_size can be fetched only for installed packages,
573- and is stored in the same 'size' property as the package size """
574+ """In packagekit, installed_size can be fetched only for installed
575+ packages, and is stored in the same 'size' property as the package
576+ size"""
577 return self.pkginfo.get_installed_size(self.package.get_name())
578+
579 @property
580 def version(self):
581 return self.package.get_version()
582+
583 @property
584 def origins(self):
585 return self.pkginfo.get_origins(self.package.get_name())
586
587+
588 def make_locale_string():
589 loc = locale.getlocale(locale.LC_MESSAGES)
590 if loc[1]:
591 return loc[0] + '.' + loc[1]
592 return loc[0]
593
594+
595 class PackagekitInfo(PackageInfo):
596 USE_CACHE = True
597
598@@ -107,7 +117,7 @@
599 super(PackagekitInfo, self).__init__()
600 self.client = packagekit.Client()
601 self.client.set_locale(make_locale_string())
602- self._cache = {} # temporary hack for decent testing
603+ self._cache = {} # temporary hack for decent testing
604 self._notfound_cache = []
605 self._repocache = {}
606 self.distro = get_distro()
607@@ -136,11 +146,13 @@
608 return PackagekitVersion(p, self) if p else None
609
610 def get_candidate(self, pkgname):
611- p = self._get_one_package(pkgname, pfilter=packagekit.FilterEnum.NEWEST)
612+ p = self._get_one_package(pkgname,
613+ pfilter=packagekit.FilterEnum.NEWEST)
614 return PackagekitVersion(p, self) if p else None
615
616 def get_versions(self, pkgname):
617- return [PackagekitVersion(p, self) for p in self._get_packages(pkgname)]
618+ return [PackagekitVersion(p, self)
619+ for p in self._get_packages(pkgname)]
620
621 def get_section(self, pkgname):
622 # FIXME: things are fuzzy here - group-section association
623@@ -167,7 +179,8 @@
624 p = self._get_one_package(pkgname)
625 if not p:
626 return []
627- res = self.client.get_files((p.get_id(),), None, self._on_progress_changed, None)
628+ res = self.client.get_files((p.get_id(),), None,
629+ self._on_progress_changed, None)
630 files = res.get_files_array()
631 if not files:
632 return []
633@@ -185,7 +198,8 @@
634
635 def get_origins(self, pkgname):
636 self._get_repolist()
637- pkgs = self._get_packages(pkgname, pfilter=packagekit.FilterEnum.NOT_INSTALLED)
638+ pkgs = self._get_packages(pkgname,
639+ pfilter=packagekit.FilterEnum.NOT_INSTALLED)
640 out = set()
641
642 for p in pkgs:
643@@ -223,13 +237,15 @@
644 if not p:
645 return []
646 autoremove = False
647- res = self.client.simulate_remove_packages((p.get_id(),),
648+ res = self.client.simulate_remove_packages((p.get_id(),),
649 autoremove, None,
650 self._on_progress_changed, None,
651 )
652 if not res:
653 return []
654- return [p.get_name() for p in res.get_package_array() if p.get_name() != pkg.name]
655+ return [p.get_name()
656+ for p in res.get_package_array()
657+ if p.get_name() != pkg.name]
658
659 def get_packages_removed_on_install(self, pkg):
660 """ Returns a package names list of dependencies
661@@ -237,15 +253,18 @@
662 p = self._get_one_package(pkg.name)
663 if not p:
664 return []
665- res = self.client.simulate_install_packages((p.get_id(),),
666+ res = self.client.simulate_install_packages((p.get_id(),),
667 None,
668 self._on_progress_changed, None,
669 )
670 if not res:
671 return []
672- return [p.get_name() for p in res.get_package_array() if (p.get_name() != pkg.name) and p.get_info() == packagekit.InfoEnum.INSTALLED]
673+ return [p.get_name()
674+ for p in res.get_package_array()
675+ if (p.get_name() != pkg.name)
676+ and p.get_info() == packagekit.InfoEnum.INSTALLED]
677
678- def get_total_size_on_install(self, pkgname,
679+ def get_total_size_on_install(self, pkgname,
680 addons_install=None, addons_remove=None,
681 archive_suite=None):
682 """ Returns a tuple (download_size, installed_size)
683@@ -253,7 +272,7 @@
684 plus addons change.
685 """
686 # FIXME: support archive_suite here too
687-
688+
689 # FIXME: PackageKit reports only one size at a time
690 if self.is_installed(pkgname):
691 return (0, self.get_size(pkgname))
692@@ -276,20 +295,22 @@
693
694 """ private methods """
695 def _get_package_details(self, packageid, cache=USE_CACHE):
696- LOG.debug("package_details %s", packageid) #, self._cache.keys()
697+ LOG.debug("package_details %s", packageid) # , self._cache.keys()
698 if (packageid in self._cache.keys()) and cache:
699 return self._cache[packageid]
700
701- result = self.client.get_details((packageid,), None, self._on_progress_changed, None)
702+ result = self.client.get_details((packageid,), None,
703+ self._on_progress_changed, None)
704 pkgs = result.get_details_array()
705 if not pkgs:
706 return None
707 packageid = pkgs[0].get_property('package-id')
708 self._cache[packageid] = pkgs[0]
709 return pkgs[0]
710-
711- def _get_one_package(self, pkgname, pfilter=packagekit.FilterEnum.NONE, cache=USE_CACHE):
712- LOG.debug("package_one %s", pkgname) #, self._cache.keys()
713+
714+ def _get_one_package(self, pkgname, pfilter=packagekit.FilterEnum.NONE,
715+ cache=USE_CACHE):
716+ LOG.debug("package_one %s", pkgname) # , self._cache.keys()
717 if (pkgname in self._cache.keys()) and cache:
718 return self._cache[pkgname]
719 ps = self._get_packages(pkgname, pfilter)
720@@ -313,7 +334,8 @@
721 pkgs = result.get_package_array()
722 return pkgs
723
724- def _get_repolist(self, pfilter=packagekit.FilterEnum.NONE, cache=USE_CACHE):
725+ def _get_repolist(self, pfilter=packagekit.FilterEnum.NONE,
726+ cache=USE_CACHE):
727 """ obtain and cache a dictionary of repositories """
728 if self._repocache:
729 return self._repocache
730@@ -342,7 +364,7 @@
731 def _on_progress_changed(self, progress, ptype, data=None):
732 pass
733
734-if __name__=="__main__":
735+if __name__ == "__main__":
736 pi = PackagekitInfo()
737
738 print "Firefox, installed ", pi.is_installed('firefox')
739
740=== modified file 'softwarecenter/ui/qml/app.py'
741--- softwarecenter/ui/qml/app.py 2011-11-03 14:27:59 +0000
742+++ softwarecenter/ui/qml/app.py 2012-03-07 20:23:18 +0000
743@@ -27,7 +27,7 @@
744 from PyQt4 import QtDeclarative
745 from PyQt4.QtCore import QUrl
746 from PyQt4.QtGui import QApplication, QIcon
747-from PyQt4.QtDeclarative import QDeclarativeView
748+from PyQt4.QtDeclarative import QDeclarativeView
749
750 from softwarecenter.db.pkginfo import get_pkg_info
751
752@@ -46,7 +46,8 @@
753
754 view = QDeclarativeView()
755 view.setWindowTitle(view.tr("Ubuntu Software Center"))
756- view.setWindowIcon(QIcon(os.path.join(os.path.dirname(__file__), "../../../data/icons/scalable/apps/softwarecenter.svg")))
757+ view.setWindowIcon(QIcon(os.path.join(os.path.dirname(__file__),
758+ "../../../data/icons/scalable/apps/softwarecenter.svg")))
759 view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
760
761 # if running locally, fixup softwarecenter.paths
762
763=== modified file 'softwarecenter/ui/qml/categoriesmodel.py'
764--- softwarecenter/ui/qml/categoriesmodel.py 2011-11-02 22:07:14 +0000
765+++ softwarecenter/ui/qml/categoriesmodel.py 2012-03-07 20:23:18 +0000
766@@ -19,7 +19,7 @@
767
768 import os
769
770-# this is a bit silly, but *something* imports gtk2 symbols, so if we
771+# this is a bit silly, but *something* imports gtk2 symbols, so if we
772 # force gtk3 here it crashes - the only reason we need this at all is to
773 # get the icon path
774 import gi
775@@ -35,13 +35,14 @@
776 from softwarecenter.paths import XAPIAN_BASE_PATH
777 import softwarecenter.paths
778
779+
780 class CategoriesModel(QAbstractListModel):
781
782 # should match the softwarecenter.backend.reviews.Review attributes
783 COLUMNS = ('_name',
784 '_iconname',
785 )
786-
787+
788 def __init__(self, parent=None):
789 super(CategoriesModel, self).__init__()
790 self._categories = []
791@@ -76,10 +77,10 @@
792 if info:
793 return info.get_filename()
794 return ""
795-
796+
797 if __name__ == "__main__":
798 from PyQt4.QtGui import QApplication
799- from PyQt4.QtDeclarative import QDeclarativeView
800+ from PyQt4.QtDeclarative import QDeclarativeView
801 import sys
802
803 app = QApplication(sys.argv)
804@@ -97,4 +98,3 @@
805 # show it
806 view.show()
807 sys.exit(app.exec_())
808-
809
810=== modified file 'softwarecenter/ui/qml/pkglist.py'
811--- softwarecenter/ui/qml/pkglist.py 2011-11-02 22:07:14 +0000
812+++ softwarecenter/ui/qml/pkglist.py 2012-03-07 20:23:18 +0000
813@@ -29,6 +29,7 @@
814 from softwarecenter.backend import get_install_backend
815 from softwarecenter.backend.reviews import get_review_loader
816
817+
818 class PkgListModel(QAbstractListModel):
819
820 COLUMNS = ('_appname',
821@@ -40,7 +41,7 @@
822 '_ratings_total',
823 '_ratings_average',
824 '_installremoveprogress')
825-
826+
827 def __init__(self, parent=None):
828 super(PkgListModel, self).__init__()
829 self._docs = []
830@@ -53,7 +54,7 @@
831 self.db = StoreDatabase(pathname, self.cache)
832 self.db.open(use_axi=False)
833 self.backend = get_install_backend()
834- self.backend.connect("transaction-progress-changed",
835+ self.backend.connect("transaction-progress-changed",
836 self._on_backend_transaction_progress_changed)
837 self.reviews = get_review_loader(self.cache)
838 # FIXME: get this from a parent
839@@ -71,9 +72,9 @@
840 doc = self._docs[index.row()]
841 role = self.COLUMNS[role]
842 pkgname = unicode(self.db.get_pkgname(doc), "utf8", "ignore")
843- appname = unicode(self.db.get_appname(doc), "utf8", "ignore")
844+ appname = unicode(self.db.get_appname(doc), "utf8", "ignore")
845 if role == "_pkgname":
846- return pkgname
847+ return pkgname
848 elif role == "_appname":
849 return appname
850 elif role == "_summary":
851@@ -90,12 +91,14 @@
852 iconname = self.db.get_iconname(doc)
853 return self._findIcon(iconname)
854 elif role == "_ratings_average":
855- stats = self.reviews.get_review_stats(Application(appname, pkgname))
856+ stats = self.reviews.get_review_stats(Application(appname,
857+ pkgname))
858 if stats:
859 return stats.ratings_average
860 return 0
861 elif role == "_ratings_total":
862- stats = self.reviews.get_review_stats(Application(appname, pkgname))
863+ stats = self.reviews.get_review_stats(Application(appname,
864+ pkgname))
865 if stats:
866 return stats.ratings_total
867 return 0
868@@ -106,26 +109,27 @@
869 return None
870
871 # helper
872- def _on_backend_transaction_progress_changed(self, backend, pkgname, progress):
873+ def _on_backend_transaction_progress_changed(self, backend, pkgname,
874+ progress):
875 column = self.COLUMNS.index("_installremoveprogress")
876 # FIXME: instead of the entire model, just find the row that changed
877 top = self.createIndex(0, column)
878- bottom = self.createIndex(self.rowCount()-1, column)
879+ bottom = self.createIndex(self.rowCount() - 1, column)
880 self.dataChanged.emit(top, bottom)
881
882 def _findIcon(self, iconname):
883 path = "/usr/share/icons/Humanity/categories/32/applications-other.svg"
884 for ext in ["svg", "png", ".xpm"]:
885 p = "/usr/share/app-install/icons/%s" % iconname
886- if os.path.exists(p+ext):
887- path = "file://%s" % p+ext
888+ if os.path.exists(p + ext):
889+ path = "file://%s" % p + ext
890 break
891 return path
892-
893+
894 def clear(self):
895 if self._docs == []:
896 return
897- self.beginRemoveRows(QModelIndex(), 0, self.rowCount()-1)
898+ self.beginRemoveRows(QModelIndex(), 0, self.rowCount() - 1)
899 self._docs = []
900 self.endRemoveRows()
901
902@@ -133,7 +137,7 @@
903 self.clear()
904 docs = self.db.get_docs_from_query(
905 str(querystr), start=0, end=500, category=self._category)
906- self.beginInsertRows(QModelIndex(), 0, len(docs)-1)
907+ self.beginInsertRows(QModelIndex(), 0, len(docs) - 1)
908 self._docs = docs
909 self.endInsertRows()
910
911@@ -143,6 +147,7 @@
912 appname = ""
913 iconname = ""
914 self.backend.install(pkgname, appname, iconname)
915+
916 @pyqtSlot(str)
917 def removePackage(self, pkgname):
918 appname = ""
919@@ -152,11 +157,13 @@
920 # searchQuery property (for qml )
921 def getSearchQuery(self):
922 return self._query
923+
924 def setSearchQuery(self, query):
925 self._query = query
926 self._runQuery(query)
927 searchQueryChanged = QtCore.pyqtSignal()
928- searchQuery = QtCore.pyqtProperty(unicode, getSearchQuery, setSearchQuery, notify=searchQueryChanged)
929+ searchQuery = QtCore.pyqtProperty(unicode, getSearchQuery, setSearchQuery,
930+ notify=searchQueryChanged)
931
932 # allow to refine searches for specific categories
933 @pyqtSlot(str)
934@@ -177,7 +184,7 @@
935
936 if __name__ == "__main__":
937 from PyQt4.QtGui import QApplication
938- from PyQt4.QtDeclarative import QDeclarativeView
939+ from PyQt4.QtDeclarative import QDeclarativeView
940 import sys
941
942 app = QApplication(sys.argv)
943@@ -195,4 +202,3 @@
944 # show it
945 view.show()
946 sys.exit(app.exec_())
947-
948
949=== modified file 'softwarecenter/ui/qml/reviewslist.py'
950--- softwarecenter/ui/qml/reviewslist.py 2011-11-02 22:58:38 +0000
951+++ softwarecenter/ui/qml/reviewslist.py 2012-03-07 20:23:18 +0000
952@@ -26,6 +26,7 @@
953 from softwarecenter.db.pkginfo import get_pkg_info
954 from softwarecenter.backend.reviews import get_review_loader
955
956+
957 class ReviewsListModel(QAbstractListModel):
958
959 # should match the softwarecenter.backend.reviews.Review attributes
960@@ -35,7 +36,7 @@
961 '_date_created',
962 '_reviewer_displayname',
963 )
964-
965+
966 def __init__(self, parent=None):
967 super(ReviewsListModel, self).__init__()
968 self._reviews = []
969@@ -56,20 +57,21 @@
970 review = self._reviews[index.row()]
971 role = self.COLUMNS[role]
972 if role == '_date_created':
973- when = datetime.strptime(getattr(review, role[1:]), '%Y-%m-%d %H:%M:%S')
974+ when = datetime.strptime(getattr(review, role[1:]),
975+ '%Y-%m-%d %H:%M:%S')
976 return when.strftime('%Y-%m-%d')
977 return unicode(getattr(review, role[1:]))
978
979 # helper
980 def clear(self):
981- self.beginRemoveRows(QModelIndex(), 0, self.rowCount()-1)
982+ self.beginRemoveRows(QModelIndex(), 0, self.rowCount() - 1)
983 self._reviews = []
984 self.endRemoveRows()
985
986 def _on_reviews_ready_callback(self, loader, reviews):
987 self.beginInsertRows(QModelIndex(),
988- self.rowCount(), # first
989- self.rowCount() + len(reviews)-1) # last
990+ self.rowCount(), # first
991+ self.rowCount() + len(reviews) - 1) # last
992 self._reviews += reviews
993 self.endInsertRows()
994
995@@ -99,5 +101,3 @@
996 # FIXME: how is this signal actually used in the qml JS?
997 # signals
998 reviewStatsChanged = pyqtSignal()
999-
1000-
1001
1002=== added file 'test/test_pep8.py'
1003--- test/test_pep8.py 1970-01-01 00:00:00 +0000
1004+++ test/test_pep8.py 2012-03-07 20:23:18 +0000
1005@@ -0,0 +1,49 @@
1006+import os
1007+import pep8
1008+import unittest
1009+from collections import defaultdict
1010+
1011+from testutils import setup_test_env
1012+setup_test_env()
1013+
1014+# Only test these two packages for now:
1015+import softwarecenter.db.pkginfo_impl
1016+import softwarecenter.ui.qml
1017+
1018+class PackagePep8TestCase(unittest.TestCase):
1019+ maxDiff = None
1020+ packages = [softwarecenter.ui.qml, softwarecenter.db.pkginfo_impl]
1021+ exclude = []
1022+
1023+ def message(self, text):
1024+ self.errors.append(text)
1025+
1026+ def setUp(self):
1027+ self.errors = []
1028+
1029+ class Options(object):
1030+ exclude = self.exclude
1031+ filename = ['*.py']
1032+ testsuite = ''
1033+ doctest = ''
1034+ counters = defaultdict(int)
1035+ messages = {}
1036+ verbose = 0
1037+ quiet = 0
1038+ repeat = True
1039+ show_source = False
1040+ show_pep8 = False
1041+ select = []
1042+ ignore = []
1043+ pep8.options = Options()
1044+ pep8.message = self.message
1045+ Options.physical_checks = pep8.find_checks('physical_line')
1046+ Options.logical_checks = pep8.find_checks('logical_line')
1047+
1048+ def test_all_code(self):
1049+ for package in self.packages:
1050+ pep8.input_dir(os.path.dirname(package.__file__))
1051+ self.assertEqual([], self.errors)
1052+
1053+if __name__ == "__main__":
1054+ unittest.main()