Show personalized banner exhibits on Ubuntu Software Center

Open up /usr/share/software-center/softwarecenter/backend/scagent.py and edit the beginning of this function, so that it says:

def query_exhibits(self):
    import urllib, json
    class Obj:
      def __init__(self, obj):
        self.obj = obj
      def __getattr__(self, name):
        if name[:2] == "__": return object.__getattr__(self, name)
        return self.obj[name]

    self.emit("exhibits", [Obj(x) for x in json.loads(urllib.urlopen("http://localhost:8800/cgi-bin/bannerlist.py").read())])
    return

You can leave the rest as it is, it will never be reached.

If you want scripting support in your <iframe>, edit

/usr/share/software-center/softwarecenter/ui/gtk3/widgets/exhibits.py

and find settings.set_property("enable-scripts", False). Change False to True.

Now make /var/www/cgi-bin/bannerlist.py and make it executable:

#!/usr/bin/env python
import json

print("Content-type: application/json\n")

print(json.dumps([
{
  "html": "<iframe src='file:/tmp/test.html'></iframe>",
  "title_translated": "Hey dawg",
  "click_url": "http://4chan.org",
  "package_names": ("gimp"),
  "banner_urls": ["file:/"],
  "published": True
},
{
  "html": "<iframe src='http://localhost:8800/cgi-bin/banner.py'></iframe>",
  "title_translated": "Hey dawg",
  "click_url": "http://4chan.org",
  "package_names": ("gimp"),
  "banner_urls": ["file:/"],
  "published": True
}
]))

This demonstrates a generated banner list.

Now make /var/www/cgi-bin/banner.py and make it executable:

#!/usr/bin/env python3
import time
print("Content-type: image/svg+xml\n")
print("""
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect width="300" height="100"
  style="fill:rgba(0,0,255,0.5);stroke-width:1;stroke:rgba(0,0,0,0.5)"/>
  <text x="0" y="25" fill="black">Time is """ + str(time.time()) + """</text>
</svg> 
""")

This demonstrates a generated banner.

You might need to clear the software-center cache. You can do that using rm -rf ~/.cache/software-center.

Obviously you need to put something in /tmp/test.html for the first banner to work.

You also need a webserver running at 8800 with a cgi-bin for this to work. If you don't have this, run this in Bash:

cd /var/www
python -c "import BaseHTTPServer as h, CGIHTTPServer as c;
i = c.CGIHTTPRequestHandler;
i.cgi_directories = ['/cgi-bin'];
h.HTTPServer(('', 8800),i).serve_forever()"

You need to style the iframe to make it fill the space, but you figured that out.