Update GNOME proxy support for GNOME 3 and Python 3

GConf is replaced by dconf and the GSettings API in GNOME 3.
This commit is contained in:
Chris Mayo 2020-06-05 16:29:45 +01:00
parent e207ac54ce
commit b9c8e33878
7 changed files with 23 additions and 38 deletions

View file

@ -2,6 +2,7 @@
Changes:
- cmdline: Remove options replaced by plugins and made ineffective in 9.0
- configuration: Update proxy settings support for GNOME 3.
9.4 "just passing by" (released 12.4.2018)

View file

@ -1,4 +1,4 @@
.TH LINKCHECKER 1 2020-04-24 "LinkChecker" "LinkChecker User Manual"
.TH LINKCHECKER 1 2020-06-05 "LinkChecker" "LinkChecker User Manual"
.SH NAME
linkchecker \- command line client to check HTML documents and websites for broken links
.SH SYNOPSIS
@ -298,7 +298,7 @@ To use a proxy on Unix or Windows set the $http_proxy, $https_proxy or $ftp_prox
environment variables to the proxy URL. The URL should be of the form
\fBhttp://\fP[\fIuser\fP\fB:\fP\fIpass\fP\fB@\fP]\fIhost\fP[\fB:\fP\fIport\fP].
LinkChecker also detects manual proxy settings of Internet Explorer under
Windows systems, and gconf or KDE on Linux systems.
Windows systems, and GNOME or KDE on Linux systems.
On a Mac use the Internet Config to select a proxy.
.PP
You can also set a comma-separated domain list in the $no_proxy environment

View file

@ -54,7 +54,8 @@ First, install the required software.
ClamAv from https://www.clamav.net/
7. *Optional, for GNOME proxy setting parsing:*
Python Gtk from http://www.pygtk.org/downloads.html
PyGObject and GIO.
Best installed from your distribution e.g. ``python3-gi``
8. *Optional, to run the WSGI web interface:*
Apache from https://httpd.apache.org/

View file

@ -308,7 +308,7 @@ To use a proxy on Unix or Windows set the $http_proxy, $https_proxy or
form
<b>http://</b>[<i>user</i><b>:</b><i>pass</i><b>@</b>]<i>host</i>[<b>:</b><i>port</i>].
LinkChecker also detects manual proxy settings of Internet Explorer under
Windows systems, and gconf or KDE on Linux systems. On a Mac use the Internet
Windows systems, and GNOME or KDE on Linux systems. On a Mac use the Internet
Config to select a proxy.
<p class="Pp">You can also set a comma-separated domain list in the $no_proxy
environment variables to ignore any proxy settings for these domains.</p>
@ -518,7 +518,7 @@ Copyright &#x00A9; 2000-2014 Bastian Kleineidam
</div>
<table class="foot">
<tr>
<td class="foot-date">2020-04-24</td>
<td class="foot-date">2020-06-05</td>
<td class="foot-os">LinkChecker</td>
</tr>
</table>

View file

@ -70,7 +70,7 @@ Modules = (
("pygeoip", "GeoIP", 'lib_version'), # on Windows systems
("sqlite3", "Pysqlite", 'version'),
("sqlite3", "Sqlite", 'sqlite_version'),
("gconf", "Gconf", '__version__'),
("gi", "PyGObject", '__version__'),
("meliae", "Meliae", '__version__'),
)
@ -331,11 +331,11 @@ class Configuration(dict):
if os.name != 'posix':
return
if "http" not in self["proxy"]:
http_proxy = get_gconf_http_proxy() or get_kde_http_proxy()
http_proxy = get_gnome_proxy() or get_kde_http_proxy()
if http_proxy:
self["proxy"]["http"] = http_proxy
if "ftp" not in self["proxy"]:
ftp_proxy = get_gconf_ftp_proxy() or get_kde_ftp_proxy()
ftp_proxy = get_gnome_proxy(protocol="FTP") or get_kde_ftp_proxy()
if ftp_proxy:
self["proxy"]["ftp"] = ftp_proxy
@ -440,43 +440,26 @@ def get_user_config():
return userconf
def get_gconf_http_proxy():
"""Return host:port for GConf HTTP proxy if found, else None."""
def get_gnome_proxy(protocol="HTTP"):
"""Return host:port for a GNOME proxy if found, else None."""
try:
import gconf
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio
except ImportError:
return None
try:
client = gconf.client_get_default()
if client.get_bool("/system/http_proxy/use_http_proxy"):
host = client.get_string("/system/http_proxy/host")
port = client.get_int("/system/http_proxy/port")
if host:
if not port:
port = 8080
return "%s:%d" % (host, port)
except Exception as msg:
log.debug(LOG_CHECK, "error getting HTTP proxy from gconf: %s", msg)
pass
return None
def get_gconf_ftp_proxy():
"""Return host:port for GConf FTP proxy if found, else None."""
try:
import gconf
except ImportError:
return None
try:
client = gconf.client_get_default()
host = client.get_string("/system/proxy/ftp_host")
port = client.get_int("/system/proxy/ftp_port")
settings = Gio.Settings.new("org.gnome.system.proxy.%s" % protocol.lower())
if protocol == "HTTP" and not settings.get_boolean("enabled"):
return None
host = settings.get_string("host")
port = settings.get_int("port")
if host:
if not port:
port = 8080
return "%s:%d" % (host, port)
except Exception as msg:
log.debug(LOG_CHECK, "error getting FTP proxy from gconf: %s", msg)
log.debug(LOG_CHECK, "error getting %s proxy from GNOME: %s", (protocol, msg))
pass
return None

View file

@ -84,7 +84,7 @@ To use a proxy on Unix or Windows set $http_proxy, $https_proxy or $ftp_proxy
to the proxy URL. The URL should be of the form
"http://[<user>:<pass>@]<host>[:<port>]".
LinkChecker also detects manual proxy settings of Internet Explorer under
Windows systems, and gconf or KDE on Linux systems.
Windows systems, and GNOME or KDE on Linux systems.
On a Mac use the Internet Config to select a proxy.
LinkChecker honors the $no_proxy environment variable. It can be a list

View file

@ -386,7 +386,7 @@ setup(
# See also doc/install.txt for more detailed dependency documentation.
# extra_requires = {
# "IP country info": ['GeoIP'], # https://pypi.org/project/GeoIP/
# "GNOME proxies": ['pygtk'], # http://www.pygtk.org/downloads.html
# "GNOME proxies": ['PyGObject'], # https://pypi.org/project/PyGObject/
# "Bash completion": ['argcomplete'], # https://pypi.org/project/argcomplete/
# "Memory debugging": ['meliae'], # https://pypi.org/project/meliae/
# }