Browse code

2007-07-05 Michal Ludvig <michal@logix.cz>

* s3cmd: --configure support for Proxy



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@129 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2007/07/05 12:52:57
Showing 3 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 2007-07-05  Michal Ludvig  <michal@logix.cz>
2 2
 
3
+	* s3cmd: --configure support for Proxy
3 4
 	* S3/S3.py: HTTP proxy support from
4 5
 	  John D. Rowell <jdrowell@exerciseyourbrain.com>
5 6
 
... ...
@@ -20,7 +20,7 @@ class Config(object):
20 20
 	force = False
21 21
 	acl_public = False
22 22
 	proxy_host = ""
23
-	proxy_port = 0
23
+	proxy_port = 8080
24 24
 	encrypt = False
25 25
 	gpg_passphrase = ""
26 26
 	gpg_command = ""
... ...
@@ -8,6 +8,8 @@
8 8
 import sys
9 9
 import logging
10 10
 import time
11
+import os
12
+import re
11 13
 
12 14
 from copy import copy
13 15
 from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
... ...
@@ -276,10 +278,19 @@ def run_configure(config_file):
276 276
 		("secret_key", "Secret Key"),
277 277
 		("gpg_passphrase", "Encryption password", "Encryption password is used to protect your files from reading\nby unauthorized persons while in transfer to S3"),
278 278
 		("gpg_command", "Path to GPG program"),
279
+		("proxy_host", "HTTP Proxy server name", "On some networks all internet access must go through a HTTP proxy.\nTry setting it here if you can't conect to S3 directly"),
280
+		("proxy_port", "HTTP Proxy server port"),
279 281
 		]
282
+	## Option-specfic defaults
280 283
 	if getattr(cfg, "gpg_command") == "":
281 284
 		setattr(cfg, "gpg_command", find_executable("gpg"))
282 285
 
286
+	if getattr(cfg, "proxy_host") == "" and os.getenv("http_proxy"):
287
+		re_match=re.match("(http://)?([^:]+):(\d+)", os.getenv("http_proxy"))
288
+		if re_match:
289
+			setattr(cfg, "proxy_host", re_match.groups()[1])
290
+			setattr(cfg, "proxy_port", re_match.groups()[2])
291
+
283 292
 	try:
284 293
 		while 1:
285 294
 			output("\nEnter new values or accept defaults in brackets with Enter.")