11

How can I show my own personalized banner exhibits on Ubuntu Software Center?

I've seen some URL definitions on /usr/share/software-center/softwarecenter/enums.py and /usr/share/software-center/softwarecenter/distro/Ubuntu.py so far.

I also tried to track the code from the views to the core. But I got lost. _append_banner_adds calls SoftwareCenterAgent. It calls SpawnHelper. Then I get lost. There are also some calls at SimpleFileDownloader but I'm not able to track them.

Also, I've noticed this entry on the debug log.

2013-02-08 15:07:43,731 - softwarecenter.simplefiledownloader - DEBUG - download_file: http://software-center.ubuntu.com/site_media/exhibits/2012/12/SC_banner_Mixxx_2.png None True

Is there documentation on how this is implemented? Some simple recipe to change the default banners and put my own banners on a clean way would be very helpful.

I suppose I can simply rewrite the _append_banner_adds function, but I'm not very prolific on python and I'd like to understand and use the same methods Ubuntu is using, if possible.

1 Answer 1

6
+200

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.

10
  • Thanks! Can't I reuse the standard banner rotator? I tried declaring multiple classes and it worked pretty well. I'm having some styling issues with the iframe, but I should be able to sort that out. Now I want to gather the banner exhibits from a web server, so I should probably use JSON. Please notice that the bounty includes this, gathering the banners from my own server. If you include this information, I'll be able to award you the bounty :) Feb 13, 2013 at 9:47
  • @JorgeSuárezdeLis: done Feb 15, 2013 at 12:50
  • Ok, this isn't working. On the application I see an error like this: Unable to load page - Problem occurred while loading the URL http:localhost:8800cgi-binbanner.py (the same for the local version on /tmp). The old version worked, but now it seems to strip the URLs slashes somewhere. The exhibits are gathered OK, and I can print the HTML contents into the console and the slashes are there, but on the application they're missing! What could be happening? Feb 18, 2013 at 12:42
  • Well, are you sure the URL is accessible? Try loading it using curl in the console. I think it only strips the slashes in the error message. Feb 18, 2013 at 18:03
  • I don't think so. I've taken an screenshot. The two first petitions are from Firefox. Only the bannerlist seems to be gathered from the software center. Feb 18, 2013 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .