76
80
raise NotImplementedError, \
77
81
"this function must be overridden by subclasses"
79
def show_exchange(self, authentication, reports=[], message=None,
83
def show_exchange(self, authentication, reports=[], message=None):
81
84
raise NotImplementedError, \
82
85
"this function must be overridden by subclasses"
84
87
def show_final(self, message):
85
88
raise NotImplementedError, \
86
89
"this function must be overridden by subclasses"
91
def show_url(self, url):
92
"""Open the given URL in a new browser window.
94
Display an error dialog if everything fails."""
99
(pid, status) = os.wait()
101
title = _("Unable to start web browser")
102
error = _("Unable to start web browser to open %s." % url)
103
message = os.fdopen(r).readline()
105
error += "\n" + message
106
self.show_error(title, error)
116
# If we are called through sudo, determine the real user id and run the
117
# browser with it to get the user's web browser settings.
119
uid = int(get_variable("SUDO_UID"))
120
gid = int(get_variable("SUDO_GID"))
121
sudo_prefix = ["sudo", "-H", "-u", "#%s" % uid]
127
# figure out appropriate web browser
129
# if ksmserver is running, try kfmclient
131
if os.getenv("DISPLAY") and \
132
subprocess.call(["pgrep", "-x", "-u", str(uid), "ksmserver"],
133
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
134
subprocess.call(sudo_prefix + ["kfmclient", "openURL", url])
139
# if gnome-session is running, try gnome-open; special-case firefox
140
# (and more generally, mozilla browsers) and epiphany to open a new window
141
# with respectively -new-window and --new-window
143
if os.getenv("DISPLAY") and \
144
subprocess.call(["pgrep", "-x", "-u", str(uid), "gnome-panel"],
145
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
146
gct = subprocess.Popen(sudo_prefix + ["gconftool", "--get",
147
"/desktop/gnome/url-handlers/http/command"],
148
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
149
if gct.returncode == 0:
150
preferred_browser = gct.communicate()[0]
151
browser = re.match("((firefox|seamonkey|flock)[^\s]*)", preferred_browser)
153
subprocess.call(sudo_prefix + [browser.group(0), "-new-window", url])
155
browser = re.match("(epiphany[^\s]*)", preferred_browser)
157
subprocess.call(sudo_prefix + [browser.group(0), "--new-window", url])
159
if subprocess.call(sudo_prefix + ["gnome-open", url]) == 0:
164
# fall back to webbrowser
169
remove_variable("SUDO_USER")
170
add_variable("HOME", pwd.getpwuid(uid).pw_dir)
172
webbrowser.open(url, new=True, autoraise=True)