summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-10-13 16:28:16 +0200
committerinfirit <[email protected]>2014-10-13 16:28:16 +0200
commita267e864a373d7a3f251d63416e74c9e1d581a8b (patch)
tree6a13863f7eb320467acbca6b130f850b06d28092 /tools
parentea5e0b9e518aabe58890dc14a0cdc1751068b4f0 (diff)
downloadmate-desktop-a267e864a373d7a3f251d63416e74c9e1d581a8b.tar.bz2
mate-desktop-a267e864a373d7a3f251d63416e74c9e1d581a8b.tar.xz
mpaste: add proxy support
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mpaste35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/mpaste b/tools/mpaste
index c48000a..866826d 100755
--- a/tools/mpaste
+++ b/tools/mpaste
@@ -25,6 +25,7 @@
# TODO: If api is updated for registered users add back --author
from __future__ import unicode_literals, print_function
+from gi.repository import Gio
import json
import requests
import argparse
@@ -84,10 +85,44 @@ def get_params(session):
return params
+def get_proxies():
+ '''Read proxy from gsettings'''
+
+ proxies = {}
+ schemas = ('org.gnome.system.proxy.ftp',
+ 'org.gnome.system.proxy.http',
+ 'org.gnome.system.proxy.https',
+ 'org.gnome.system.proxy.socks')
+
+ settings = Gio.Settings.new('org.gnome.system.proxy')
+ mode = settings['mode']
+
+ if mode == 'none':
+ return {}
+
+ for schema in schemas:
+ settings = Gio.Settings.new(schema)
+ host = settings['host']
+ port = str(settings['port'])
+ proxy_type = schema.split('.')[-1]
+
+ if not host:
+ continue
+
+ proxies[proxy_type] = ':'.join((host, port))
+
+ return proxies
+
if __name__ == '__main__':
api_url = 'http://paste.mate-desktop.org/api/json/'
+ # Get proxies from gsettings
+ proxies = get_proxies()
+
+ # create session and add proxies
session = requests.session()
+ session.proxies = proxies
+
params = get_params(session)
# Create argument parser and read arguments