From 08bf982a9d8ba072c2e433f0f4469e524660dc20 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sat, 01 Aug 2009 04:42:30 +0000 Subject: More pylint/pep8 fixes --- diff --git a/extensions/cpsection/updater/backends/__init__.py b/extensions/cpsection/updater/backends/__init__.py index c148fcc..0dd0174 100644 --- a/extensions/cpsection/updater/backends/__init__.py +++ b/extensions/cpsection/updater/backends/__init__.py @@ -14,5 +14,3 @@ # 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 - - diff --git a/extensions/cpsection/updater/backends/aslo.py b/extensions/cpsection/updater/backends/aslo.py index 7985e5c..69cd47c 100644 --- a/extensions/cpsection/updater/backends/aslo.py +++ b/extensions/cpsection/updater/backends/aslo.py @@ -14,15 +14,18 @@ # 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 + """Activity information microformat parser. Activity information is embedded in HTML/XHTML/XML pages using a Resource Description Framework (RDF) http://www.w3.org/RDF/ . - + An example:: - + + @@ -37,43 +40,51 @@ An example:: {3ca105e0-2280-4897-99a0-c277d1b733d2} 0.82 0.84 - http://activities.sugarlabs.org/downloads/file/25986/bounce-7.xo - - sha256:816a7c43b4f1ea4769c61c03fea24842ec5fa566b7d41626ffc52ec37b37b6c5 + http://foo.xo + 7 + sha256:816a7c43b4f1ea4769c61c03ea4.. """ +import logging import urllib2 -from urllib2 import HTTPError +from xml.etree.ElementTree import XML -import socket +from jarabe import config -from xml.etree.ElementTree import ElementTree, XML +_FIND_VERSION = './/{http://www.mozilla.org/2004/em-rdf#}version' +_FIND_LINK = './/{http://www.mozilla.org/2004/em-rdf#}updateLink' +_FIND_SIZE = './/{http://www.mozilla.org/2004/em-rdf#}updateSize' -from jarabe import config +_UPDATE_PATH = 'http://activities.sugarlabs.org/services/update.php' class ASLOParser(): """XML parser to pull out data expressed in our aslo format.""" - + def __init__(self, xml_data): self.elem = XML(xml_data) + self.version = 0 + self.link = None + self.size = 0 + def parse(self): try: - self.version = self.elem.find(".//{http://www.mozilla.org/2004/em-rdf#}version").text - self.link = self.elem.find(".//{http://www.mozilla.org/2004/em-rdf#}updateLink").text - self.size = self.elem.find(".//{http://www.mozilla.org/2004/em-rdf#}updateSize").text - self.size = long(self.size) * 1024 - except: + self.version = self.elem.find(_FIND_VERSION).text + self.link = self.elem.find(_FIND_LINK).text + self.size = long(self.elem.find(_FIND_SIZE).text) * 1024 + except Exception, e: + logging.warning("Can't parse update data: %s" % e) self.version = 0 self.link = None self.size = 0 def parse_aslo(xml_data): """Parse the activity information embedded in the given string - containing XML data. Returns a list containing the activity version and url. + containing XML data. Returns a list containing the activity version, + size and url. """ ap = ASLOParser(xml_data) ap.parse() @@ -95,7 +106,8 @@ def fetch_update_info(bundle): update can be found. """ - url = 'http://activities.sugarlabs.org/services/update.php?id=' + bundle.get_bundle_id() + '&appVersion=' + config.version + url = '%s?id=%s&appVersion=%s' % \ + (_UPDATE_PATH, bundle.get_bundle_id(), config.version) return parse_url(url) @@ -103,6 +115,7 @@ def fetch_update_info(bundle): # Self-test code. def _main(): """Self-test.""" - print parse_url('http://activities.sugarlabs.org/services/update.php?id=bounce') + print parse_url('%s?id=bounce' % _UPDATE_PATH) -if __name__ == '__main__': _main () +if __name__ == '__main__': + _main() diff --git a/extensions/cpsection/updater/view.py b/extensions/cpsection/updater/view.py index 41380c6..0e32d51 100644 --- a/extensions/cpsection/updater/view.py +++ b/extensions/cpsection/updater/view.py @@ -103,7 +103,7 @@ class ActivityUpdater(SectionView): self.top_label.set_markup('%s' % _e(header)) self.bundle_pane.refresh_update_size() - def __install_clicked_cb(self, widget, event, data=None): + def install_clicked_cb(self, widget, event, data=None): """Invoked when the 'ok' button is clicked.""" self.top_label.set_markup('%s' % _('Installing updates...')) @@ -164,7 +164,7 @@ class BundlePane(gtk.VBox): self.install_button = _make_button(_("Install selected"), name='emblem-downloads') self.install_button.connect('clicked', - update_activity.__install_clicked_cb, self) + update_activity.install_clicked_cb, self) button_box.pack_start(self.install_button, expand=False) def is_valid_cb(bundle_list, __): -- cgit v0.9.1