diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-08-01 04:42:30 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-08-01 04:42:30 (GMT) |
commit | 08bf982a9d8ba072c2e433f0f4469e524660dc20 (patch) | |
tree | 8321f32bd7eef93df343532b24ba37f7a8792e57 /extensions/cpsection | |
parent | dc921a23879e2f42dbef688e45c4878670c72369 (diff) |
More pylint/pep8 fixes
Diffstat (limited to 'extensions/cpsection')
-rw-r--r-- | extensions/cpsection/updater/backends/__init__.py | 2 | ||||
-rw-r--r-- | extensions/cpsection/updater/backends/aslo.py | 51 | ||||
-rw-r--r-- | extensions/cpsection/updater/view.py | 4 |
3 files changed, 34 insertions, 23 deletions
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:: <?xml version="1.0" encoding="UTF-8"?> -<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"><RDF:Description about="urn:mozilla:extension:bounce"> +<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> +<RDF:Description about="urn:mozilla:extension:bounce"> <em:updates> <RDF:Seq> <RDF:li resource="urn:mozilla:extension:bounce:7"/> @@ -37,43 +40,51 @@ An example:: <em:id>{3ca105e0-2280-4897-99a0-c277d1b733d2}</em:id> <em:minVersion>0.82</em:minVersion> <em:maxVersion>0.84</em:maxVersion> - <em:updateLink>http://activities.sugarlabs.org/downloads/file/25986/bounce-7.xo</em:updateLink> - - <em:updateHash>sha256:816a7c43b4f1ea4769c61c03fea24842ec5fa566b7d41626ffc52ec37b37b6c5</em:updateHash> + <em:updateLink>http://foo.xo</em:updateLink> + <em:updateSize>7</em:updateSize> + <em:updateHash>sha256:816a7c43b4f1ea4769c61c03ea4..</em:updateHash> </RDF:Description> </em:targetApplication> </RDF:Description></RDF:RDF> """ +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('<big>%s</big>' % _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('<big>%s</big>' % _('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, __): |