Skip to content

Instantly share code, notes, and snippets.

@lloc
Last active April 26, 2019 10:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloc/5868367 to your computer and use it in GitHub Desktop.
Save lloc/5868367 to your computer and use it in GitHub Desktop.
Configure GitHub for a connection trough a proxy with a pacfile
#!/usr/bin/env python
"""
The config.ini contains something like:
[Proxy]
proxy = http://YOURPROXY/proxy.pac
user = YOURUSER
pass = YOURPASS
local = proxy.pac
url = http://github.com
short = github.com
"""
import urllib2, re, os
from ConfigParser import SafeConfigParser
import pacparser # http://code.google.com/p/pacparser/
config = SafeConfigParser()
config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
localpac = config.get('Proxy', 'local')
remotepac = urllib2.urlopen(config.get('Proxy', 'proxy'))
output = open(localpac, 'w')
output.write(remotepac.read())
output.close()
pacstring = pacparser.just_find_proxy(
localpac,
config.get('Proxy', 'url'),
config.get('Proxy', 'short')
)
m = re.match(r'PROXY ([0-9:.]+);', pacstring)
proxystr = 'http://%s:%s@%s' % (
config.get('Proxy', 'user'),
config.get('Proxy', 'pass'),
m.group(1)
)
#os.system('set http_proxy=%s' % proxystr)
#os.system('set https_proxy=%s' % proxystr)
os.system('setx http_proxy "%s"' % proxystr)
os.system('setx https_proxy "%s"' % proxystr)
os.system('git config --global http.proxy %s' % proxystr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment