{"id":967,"date":"2009-02-10T14:56:51","date_gmt":"2009-02-10T22:56:51","guid":{"rendered":"http:\/\/mozillalabs.com\/?p=967"},"modified":"2009-02-10T14:56:51","modified_gmt":"2009-02-10T22:56:51","slug":"ubiquitys_python_feed_plugin","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/labs\/2009\/02\/ubiquitys_python_feed_plugin\/","title":{"rendered":"Ubiquity\u2019s Python Feed Plugin"},"content":{"rendered":"<p>A few weeks ago I wrote about Ubiquity <a href=\"http:\/\/www.toolness.com\/wp\/?p=426\">Feed Plugins<\/a>, which are basically just a way of separating the user interface of subscribing to a new feature from the implementation of the feature itself.<\/p>\n<p>As I&#8217;ve <a href=\"http:\/\/www.toolness.com\/wp\/?p=48\">written about before<\/a>, one of the things I&#8217;ve missed about the Mozilla development environment is its support for the Python programming language.  Aside from being humane and having a great community, it has functionality that could complement the Mozilla platform quite nicely.  So we&#8217;ve whipped up a quick proof-of-concept Python Feed Plugin for Ubiquity to explore this possibility.<\/p>\n<p>Here&#8217;s a really simple command feed written in Python:<\/p>\n<pre>\ndef cmd_sample_python_command(ubiquity):\n    ubiquity.displayMessage('Hello from Python %s.' % sys.version)\n\ncmd_sample_python_command.preview = 'a sample python command!'\n<\/pre>\n<p>For anyone who knows Python and has read the <a href=\"https:\/\/wiki.mozilla.org\/Labs\/Ubiquity\/Ubiquity_0.1_Author_Tutorial\">Ubiquity Author Tutorial<\/a>, this should be fairly self-explanatory.  The <tt>ubiquity<\/tt> argument is just passed in to the command execution function to make unit testing as easy as possible.<\/p>\n<p>As with any Ubiquity feed, the file containing the above code needs to be referenced in the <tt>&lt;HEAD&gt;<\/tt> element of a web page:<\/p>\n<p><tt>&lt;LINK REL=\"python-commands\" HREF=\"sample_command.py\"&gt;<\/tt><\/p>\n<p>In this case the <tt>python-commands<\/tt> value of the <tt>REL<\/tt> attribute is what tells Ubiquity to process this feed using the Python feed plugin.<\/p>\n<p>Visiting the web page containing this tag results in the same <a href=\"https:\/\/wiki.mozilla.org\/Image:Subscribe.png\">subscripton panel<\/a> that shows up with any page that has a Ubiquity command feed.  Because Python code executes at the same privilege level as default Ubiquity feeds, the Python feed plugin really ought to display the same <a href=\"https:\/\/wiki.mozilla.org\/Image:Warning.PNG\">warning page<\/a> that default Ubiquity feeds show when the user clicks &#8220;Subscribe&#8221;; but because this is just a proof of concept, we skipped that implementation and currently only allow Python feeds to be used when they already exist on the user&#8217;s local filesystem&mdash;in other words, when the feed is at a <tt>file:<\/tt> URL.<\/p>\n<p>The first time an end-user subscribes to a Python command feed, they&#8217;re presented with this non-intrusive message:<\/p>\n<p><img><\/p>\n<p>What happens behind-the-scenes is a bit more complex: Ubiquity uses <a href=\"http:\/\/pypi.python.org\/pypi\/virtualenv\">virtualenv<\/a> to bootstrap a sandboxed Python virtual environment inside the user&#8217;s profile directory.  It then uses <tt>easy_install<\/tt> to install <a href=\"http:\/\/ajaxian.com\/archives\/jsbridge-powering-mozilla-with-python\">jsbridge<\/a>, and then sets up a &#8220;feed server&#8221; process on the user&#8217;s system, which Ubiquity communicates with over jsbridge to execute Python code:<\/p>\n<p><img><\/p>\n<p>Pretty Frankenstein, but it works on OS X and Linux.  Because Windows doesn&#8217;t come with Python built-in like the other two operating systems do, we&#8217;ll have to <a href=\"http:\/\/www.toolness.com\/wp\/?p=23\">bootstrap it<\/a> first, which we haven&#8217;t gotten around to yet.<\/p>\n<p>So, if you&#8217;ve got OS X or Linux and like Python, feel free to play around with this; a sample Python command feed is included with the <a href=\"https:\/\/ubiquity.mozilla.com\/xpi\/ubiquity-latest-beta.xpi\">latest Ubiquity beta<\/a>.  If this is something that seems interesting to you, we&#8217;d love to know&mdash;you&#8217;re welcome to leave a comment on this post, drop us a line on the <a href=\"http:\/\/groups.google.com\/group\/ubiquity-firefox\">ubiquity-firefox<\/a> Google Group, or say hello on #ubiquity on irc.mozilla.org.<\/p>\n<p><i>This post was originally posted on Atul&#8217;s blog at toolness.com.  If you have any comments on it, please leave them on the <a href=\"http:\/\/www.toolness.com\/wp\/?p=463\">original post<\/a>.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I wrote about Ubiquity Feed Plugins, which are basically just a way of separating the user interface of subscribing to a new feature from the implementation of the feature itself. As I&#8217;ve written about before, one &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/labs\/2009\/02\/ubiquitys_python_feed_plugin\/\">Continue reading<\/a><\/p>\n","protected":false},"author":51,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[529],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts\/967"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/comments?post=967"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts\/967\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/categories?post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/tags?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}