Merge lp:~turl/specto/better-web-launching into lp:specto

Proposed by Emilio
Status: Needs review
Proposed branch: lp:~turl/specto/better-web-launching
Merge into: lp:specto
Diff against target: 30 lines (+13/-7)
1 file modified
spectlib/util.py (+13/-7)
To merge this branch: bzr merge lp:~turl/specto/better-web-launching
Reviewer Review Type Date Requested Status
Jeff Fortin Tam Needs Fixing
Review via email: mp+16665@code.launchpad.net
To post a comment you must log in.
lp:~turl/specto/better-web-launching updated
147. By Emilio

Cosmetic fix.

148. By Emilio

Remove GConf fallback from return_webpage.

Revision history for this message
Jeff Fortin Tam (kiddo) wrote :

Two things:
- The Pythonic/PEP-8 way is to write "if path:", not "if path is not False:"
- It doesn't work here. My gnome settings for preferred applications were set by chromium to be:

/usr/lib/chromium-browser/chromium-browser %s

review: Needs Fixing

Unmerged revisions

148. By Emilio

Remove GConf fallback from return_webpage.

147. By Emilio

Cosmetic fix.

146. By Emilio

Improve return_webpage to use xdg-open when available.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'spectlib/util.py'
2--- spectlib/util.py 2009-12-29 21:45:20 +0000
3+++ spectlib/util.py 2010-01-06 19:50:23 +0000
4@@ -28,13 +28,19 @@
5
6 def return_webpage(webpage):
7 """ Open the webpage in the default browser. """
8- specto_gconf = Specto_gconf("/desktop/gnome/url-handlers/http")
9- default_browser = specto_gconf.get_entry("command")
10- # Return the browser executable with the URL
11- if "%s" in default_browser: # Most browsers
12- return (default_browser % webpage)
13- else: # TODO: This is a hack for Google Chrome. We should use xdg-open instead, ideally. See bug #284.
14- return ("%s %s" % (default_browser, webpage))
15+ # Scan the system path looking for a supported launcher
16+ path = os.environ.get('PATH',False)
17+ if path is not False:
18+ path = path.split(':')
19+ possible_launchers = ('xdg-open','gnome-open','kde-open','x-www-browser')
20+ for launcher in possible_launchers:
21+ for directory in path:
22+ test_file = os.path.join(directory,launcher)
23+ if os.path.isfile(test_file):
24+ return ("%s %s" % (test_file, webpage))
25+
26+ # There is no way for us to know the user's preferred browser :(
27+ return False
28
29
30 def show_webpage(webpage):

Subscribers

People subscribed via source and target branches