Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Settings for HTTP and HTTPS proxies in the canvas #2906

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
pyqtgraph.setConfigOption("exitCleanup", False)


default_proxies = None


def fix_osx_10_9_private_font():
# Fix fonts on Os X (QTBUG 47206, 40833, 32789)
if sys.platform == "darwin":
Expand Down Expand Up @@ -88,10 +91,26 @@ def fix_win_pythonw_std_stream():
def fix_set_proxy_env():
"""
Set http_proxy/https_proxy environment variables (for requests, pip, ...)
from system settings on OS X and from registry on Windos. On unix, no-op.
from user-specified settings or, if none, from system settings on OS X
and from registry on Windos.
"""
for scheme, proxy in getproxies().items():
os.environ[scheme + '_proxy'] = proxy
# save default proxies so that setting can be reset
global default_proxies
if default_proxies is None:
default_proxies = getproxies() # can also read windows and macos settings

settings = QSettings()
proxies = getproxies()
for scheme in set(["http", "https"]) | set(proxies):
from_settings = settings.value("network/" + scheme + "-proxy", "", type=str)
from_default = default_proxies.get(scheme, "")
env_scheme = scheme + '_proxy'
if from_settings:
os.environ[env_scheme] = from_settings
elif from_default:
os.environ[env_scheme] = from_default # crucial for windows/macos support
else:
os.environ.pop(env_scheme, "")


def make_sql_logger(level=logging.INFO):
Expand Down Expand Up @@ -247,9 +266,6 @@ def main(argv=None):
# Try to fix fonts on OSX Mavericks
fix_osx_10_9_private_font()

# Set http_proxy environment variable(s) for some clients
fix_set_proxy_env()

# File handler should always be at least INFO level so we need
# the application root level to be at least at INFO.
root_level = min(levels[options.log_level], logging.INFO)
Expand Down Expand Up @@ -313,6 +329,9 @@ def main(argv=None):
config.widget_settings_dir(),
ignore_errors=True)

# Set http_proxy environment variables, after (potentially) clearing settings
fix_set_proxy_env()

file_handler = logging.FileHandler(
filename=os.path.join(config.log_dir(), "canvas.log"),
mode="w"
Expand Down
20 changes: 20 additions & 0 deletions Orange/canvas/application/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
log = logging.getLogger(__name__)


def refresh_proxies():
from Orange.canvas.__main__ import fix_set_proxy_env
fix_set_proxy_env()


class UserDefaultsPropertyBinding(AbstractBoundProperty):
"""
A Property binding for a setting in a
Expand Down Expand Up @@ -399,6 +404,20 @@ def __setupUi(self):

tab.setLayout(form)

# Network Tab
tab = QWidget()
self.addTab(tab, self.tr("Network"),
toolTip="Settings related to networking")

form = QFormLayout()
line_edit_http_proxy = QLineEdit()
self.bind(line_edit_http_proxy, "text", "network/http-proxy")
form.addRow("HTTP proxy:", line_edit_http_proxy)
line_edit_https_proxy = QLineEdit()
self.bind(line_edit_https_proxy, "text", "network/https-proxy")
form.addRow("HTTPS proxy:", line_edit_https_proxy)
tab.setLayout(form)

if self.__macUnified:
# Need some sensible size otherwise mac unified toolbar 'takes'
# the space that should be used for layout of the contents
Expand Down Expand Up @@ -461,6 +480,7 @@ def exec_(self):
self.show()
status = self.__loop.exec_()
self.__loop = None
refresh_proxies()
return status

def hideEvent(self, event):
Expand Down
4 changes: 4 additions & 0 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def init():

("add-ons/pip-install-arguments", str, '',
'Arguments to pass to "pip install" when installing add-ons.'),

("network/http-proxy", str, '', 'HTTP proxy.'),

("network/https-proxy", str, '', 'HTTPS proxy.'),
]

spec = [config_slot(*t) for t in spec]
Expand Down