From d3a1c85bcc7e97982399cf7e69e5e374c8180bfe Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sat, 01 Aug 2009 03:48:16 +0000 Subject: Fix pylint warnings --- (limited to 'extensions') diff --git a/extensions/cpsection/updater/NEWS b/extensions/cpsection/updater/NEWS deleted file mode 100644 index 8b13789..0000000 --- a/extensions/cpsection/updater/NEWS +++ /dev/null @@ -1 +0,0 @@ - diff --git a/extensions/cpsection/updater/README b/extensions/cpsection/updater/README deleted file mode 100644 index 8b13789..0000000 --- a/extensions/cpsection/updater/README +++ /dev/null @@ -1 +0,0 @@ - diff --git a/extensions/cpsection/updater/SOURCES b/extensions/cpsection/updater/SOURCES deleted file mode 100644 index 8b13789..0000000 --- a/extensions/cpsection/updater/SOURCES +++ /dev/null @@ -1 +0,0 @@ - diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py index bf0249e..939b330 100755 --- a/extensions/cpsection/updater/model.py +++ b/extensions/cpsection/updater/model.py @@ -46,8 +46,6 @@ from backends import aslo ########################################################################## # Fundamental data object. -_column_name_map = dict(globals()) - """List of columns in the `UpdateList`.""" BUNDLE_ID, \ BUNDLE, \ @@ -62,12 +60,6 @@ BUNDLE_ID, \ UPDATE_AVAILABLE, \ IS_HEADER = xrange(12) - -"""Map column names to indices.""" -_column_name_map = dict((k,v) for k,v in globals().items() - if k not in _column_name_map and k!='_column_name_map') - - class UpdateList(gtk.ListStore): """Model which provides backing storage for the BUNDLE list treeview.""" @@ -75,16 +67,6 @@ class UpdateList(gtk.ListStore): 'is_valid': (gobject.TYPE_BOOLEAN, 'is valid', 'true iff the UpdateList has been properly refreshed', False, gobject.PARAM_READABLE), - 'saw_network_failure': (gobject.TYPE_BOOLEAN, 'saw network failure', - 'true iff at least one network IO error '+ - 'occurred when the UpdateList was last '+ - 'refreshed', - False, gobject.PARAM_READABLE), - 'saw_network_success': (gobject.TYPE_BOOLEAN, 'saw network success', - 'true iff at least one network operation '+ - 'completed successfully when the UpdateList '+ - 'was last refreshed', - False, gobject.PARAM_READABLE), } def __init__(self): @@ -97,7 +79,10 @@ class UpdateList(gtk.ListStore): self._cancel = False self._is_valid = True - self.registry =bundleregistry.get_registry() + self.registry = bundleregistry.get_registry() + self.steps_count = 0 + self.steps_total = 0 + self._progress_cb = None def refresh_list(self, progress_callback=lambda n, extra: None, clear_cache=True): @@ -106,12 +91,12 @@ class UpdateList(gtk.ListStore): self._progress_cb(None, _('Looking for local actvities...')) self.clear() - self.steps_total = len(self.registry._bundles) + self.steps_total = len([i for i in self.registry]) self.steps_count = 0 row_map = {} - for bundle in self.registry._bundles: + for bundle in self.registry: self._make_progress(_('Checking %s...') % bundle.get_name()) if self._cancel: @@ -187,7 +172,8 @@ class UpdateList(gtk.ListStore): try: urllib.urlretrieve(row[UPDATE_URL], xofile) except Exception, e: - logging.warning("Can't download %s" % row[UPDATE_URL]) + logging.warning("Can't download %s: %s" % \ + (row[UPDATE_URL], e)) continue if self._cancel: @@ -249,27 +235,27 @@ class UpdateList(gtk.ListStore): ############################################################################### # Utility Funtions -def _humanize_size(bytes): +def _humanize_size(bytes_): """ Convert a given size in bytes to a nicer better readable unit """ - if bytes == 0: + if bytes_ == 0: # TRANSLATORS: download size is 0 return _("None") - elif bytes < 1024: + elif bytes_ < 1024: # TRANSLATORS: download size of very small updates return _("1 KB") - elif bytes < 1024 * 1024: + elif bytes_ < 1024 * 1024: # TRANSLATORS: download size of small updates, e.g. "250 KB" - return locale.format(_("%.0f KB"), bytes/1024) + return locale.format(_("%.0f KB"), bytes_ / 1024) else: # TRANSLATORS: download size of updates, e.g. "2.3 MB" - return locale.format(_("%.1f MB"), bytes / 1024 / 1024) + return locale.format(_("%.1f MB"), bytes_ / 1024 / 1024) def print_available(ul):#FIXME this should onlu return available updates - print def opt(x): - if x is None or x == '': return '' + if x is None or x == '': + return '' return ': %s' % x for row in ul: if row[IS_HEADER]: @@ -290,4 +276,5 @@ def _main(): print_available(update_list) update_list.install_updates() -if __name__ == '__main__': _main () +if __name__ == '__main__': + _main () diff --git a/extensions/cpsection/updater/view.py b/extensions/cpsection/updater/view.py index ee773fb..d02c972 100644 --- a/extensions/cpsection/updater/view.py +++ b/extensions/cpsection/updater/view.py @@ -1,14 +1,24 @@ -from gettext import gettext as _ -import gettext -import logging -from threading import Thread +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import pygtk -pygtk.require('2.0') +import logging import gtk import gobject +from threading import Thread +from gettext import gettext as _ +from gettext import ngettext -from sugar.activity import activity from sugar.graphics import style from jarabe.controlpanel.sectionview import SectionView @@ -33,14 +43,16 @@ class ActivityUpdater(SectionView): self.top_label = gtk.Label() self.top_label.set_line_wrap(True) self.top_label.set_justify(gtk.JUSTIFY_LEFT) - self.top_label.set_property('xalign',0) + self.top_label.set_property('xalign', 0) # bottom label # bottom_label = gtk.Label() bottom_label.set_line_wrap(True) bottom_label.set_justify(gtk.JUSTIFY_LEFT) bottom_label.set_property('xalign', 0) - bottom_label.set_markup(_('Software updates correct errors, eliminate security vulnerabilities, and provide new features.')) + bottom_label.set_markup( + _('Software updates correct errors, eliminate security' \ + 'vulnerabilities, and provide new features.')) # main canvas # self.pack_start(self.top_label, expand=False) @@ -62,7 +74,8 @@ class ActivityUpdater(SectionView): # refresh # def refresh_cb(self, widget, event): - self.top_label.set_markup('%s' % _('Checking for updates...')) + self.top_label.set_markup('%s' % \ + _('Checking for updates...')) self.progress_pane.switch_to_check_progress() self.bundle_list.freeze_notify() Thread(target=self._do_refresh).start() @@ -83,12 +96,12 @@ class ActivityUpdater(SectionView): header = _("Your software is up-to-date") self.progress_pane.switch_to_complete_message() else: - header = gettext.ngettext("You can install %s update", - "You can install %s updates", avail) \ - % avail + header = ngettext("You can install %s update", + "You can install %s updates", avail) \ + % avail self.bundle_pane.switch() self.top_label.set_markup('%s' % _e(header)) - self.bundle_pane._refresh_update_size() + self.bundle_pane.refresh_update_size() def install_cb(self, widget, event, data=None): """Invoked when the 'ok' button is clicked.""" @@ -104,16 +117,13 @@ class ActivityUpdater(SectionView): def _install_done_cb(self, installed): self.bundle_list.thaw_notify() - header = gettext.ngettext("%s update was installed", - "%s updates were installed", installed) \ - % installed + header = ngettext("%s update was installed", + "%s updates were installed", installed) \ + % installed self.top_label.set_markup('%s' % _e(header)) self.progress_pane.update(0) self.progress_pane.switch_to_complete_message() - def _install_progress_cb(n, extra=None, icon=None): - gobject.idle_add(self._progress_cb, n, extra, icon) - def _progress_cb(self, n, extra=None, icon=None): """Invoked in main thread during a refresh operation.""" self.progress_pane.update(n, extra, icon) @@ -158,7 +168,7 @@ class BundlePane(gtk.VBox): self.install_button.set_sensitive(bundle_list.is_valid()) update_activity.bundle_list.connect('notify::is-valid', is_valid_cb) - def _refresh_update_size(self): + def refresh_update_size(self): """Update the 'download size' label.""" bundle_list = self.updater_activity.bundle_list size = bundle_list.updates_size() @@ -209,7 +219,8 @@ class BundleListView(gtk.ScrolledWindow): hide_func = view_func_maker('visible') insens_func = view_func_maker('sensitive') self.column_install = gtk.TreeViewColumn('Install', crbool) - self.column_install.add_attribute(crbool, 'active', model.UPDATE_SELECTED) + self.column_install.add_attribute(crbool, 'active', + model.UPDATE_SELECTED) self.column_install.set_cell_data_func(crbool, hide_func) self.column = gtk.TreeViewColumn('Name') self.column.pack_start(cricon, expand=False) @@ -239,7 +250,8 @@ class BundleListView(gtk.ScrolledWindow): self.treeview.connect('button-press-event', self.show_context_menu) def is_valid_cb(activity_list, __): - self.treeview.set_sensitive(self.update_activity.bundle_list.is_valid()) + self.treeview.set_sensitive( + self.update_activity.bundle_list.is_valid()) self.update_activity.bundle_list.connect('notify::is-valid', is_valid_cb) is_valid_cb(self.update_activity.bundle_list, None) @@ -250,31 +262,36 @@ class BundleListView(gtk.ScrolledWindow): def toggled_cb(self, crbool, path): row = self.treeview.props.model[path] row[model.UPDATE_SELECTED] = not row[model.UPDATE_SELECTED] - self.bundle_pane._refresh_update_size() + self.bundle_pane.refresh_update_size() def show_context_menu(self, widget, event): """ Show a context menu if a right click was performed on an update entry """ - if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: - def cb(__, f): - f() - self.bundle_pane._refresh_update_size() - menu = gtk.Menu() - item_select_none = gtk.MenuItem(_("_Uncheck All")) - item_select_none.connect("activate", cb, - bundle_list.unselect_all) - menu.add(item_select_none) - if self.updater_activity.activity_list.updates_available() == 0: - item_select_none.set_property("sensitive", False) - item_select_all = gtk.MenuItem(_("_Check All")) - item_select_all.connect("activate", cb, - bundle_list.select_all) - menu.add(item_select_all) - menu.popup(None, None, None, 0, event.time) - menu.show_all() - return True - return False + if not (event.type == gtk.gdk.BUTTON_PRESS and event.button == 3): + return + + menu = gtk.Menu() + + item = gtk.MenuItem(_("_Uncheck All")) + item.connect("activate", self.__check_activate_cb, False) + if self.update_activity.bundle_list.updates_available() == 0: + item.set_property("sensitive", False) + menu.add(item) + + item = gtk.MenuItem(_("_Check All")) + item.connect("activate", self.__check_activate_cb, True) + if self.update_activity.bundle_list.updates_available() == 0: + item.set_property("sensitive", False) + menu.add(item) + + menu.popup(None, None, None, 0, event.time) + menu.show_all() + + def __check_activate_cb(self, sender, state): + for i in self.update_activity.bundle_list: + i[model.UPDATE_SELECTED] = state + self.bundle_pane.refresh_update_size() class ProgressPane(gtk.VBox): """Container which replaces the `ActivityPane` during refresh or @@ -286,7 +303,7 @@ class ProgressPane(gtk.VBox): self.set_spacing(style.DEFAULT_PADDING) self.set_border_width(style.DEFAULT_SPACING * 2) - self.bar = gtk.ProgressBar() + self.progress = gtk.ProgressBar() self.label = gtk.Label() self.label.set_line_wrap(True) self.label.set_property('xalign', 0.5) @@ -300,14 +317,14 @@ class ProgressPane(gtk.VBox): self.refresh_button = gtk.Button(stock=gtk.STOCK_REFRESH) self.try_again_button = _make_button(_('Try again'), stock=gtk.STOCK_REFRESH) - for widget,cb in [(self.cancel_button, update_activity.cancel_cb), + for widget, cb in [(self.cancel_button, update_activity.cancel_cb), (self.refresh_button, update_activity.refresh_cb), (self.try_again_button, update_activity.refresh_cb)]: widget.connect('clicked', cb, update_activity) hbox.pack_start(widget, expand=True, fill=False) self.pack_start(self.icon) - self.pack_start(self.bar) + self.pack_start(self.progress) self.pack_start(self.label) self.pack_start(hbox) @@ -317,9 +334,9 @@ class ProgressPane(gtk.VBox): in `extra` or an icon in `icon`.""" if n is None: - self.bar.pulse() + self.progress.pulse() else: - self.bar.set_fraction(n) + self.progress.set_fraction(n) extra = _e(extra) if extra is not None else '' self.label.set_markup(extra) self.icon.set_property('visible', icon is not None) @@ -346,7 +363,7 @@ class ProgressPane(gtk.VBox): """Make the progress pane visible and the activity pane invisible.""" self.update_activity.bundle_pane.set_property('visible', False) self.set_property('visible', True) - for widget, v in [ (self.bar, show_bar), + for widget, v in [ (self.progress, show_bar), (self.cancel_button, show_cancel), (self.refresh_button, not show_cancel and not show_try_again), @@ -372,8 +389,3 @@ def _make_button(label_text, stock=None, name=None): hbox.pack_start(l, expand=False) b.add(hbox) return b - -if __name__ == "__main__": - window = gtk.Window(gtk.WINDOW_TOPLEVEL) - t = UpdateActivity(window) - gtk.main() -- cgit v0.9.1