[Inteproxy-commits] r64 - in trunk: . inteproxy
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 24 17:33:23 CEST 2007
Author: bh
Date: 2007-04-24 17:33:23 +0200 (Tue, 24 Apr 2007)
New Revision: 64
Added:
trunk/inteproxy/main.py
Modified:
trunk/ChangeLog
trunk/InteProxy.py
Log:
* InteProxy.py, inteproxy/main.py: Move practically everything
from InteProxy.py to the new file inteproxy/main.py. InteProxy.py
now only imports a function from inteproxy.main and calls it.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-04-24 14:16:15 UTC (rev 63)
+++ trunk/ChangeLog 2007-04-24 15:33:23 UTC (rev 64)
@@ -1,5 +1,11 @@
2007-04-24 Bernhard Herzog <bh at intevation.de>
+ * InteProxy.py, inteproxy/main.py: Move practically everything
+ from InteProxy.py to the new file inteproxy/main.py. InteProxy.py
+ now only imports a function from inteproxy.main and calls it.
+
+2007-04-24 Bernhard Herzog <bh at intevation.de>
+
* inteproxy/proxycore.py: New. Core classes and functions of
InteProxy.
Modified: trunk/InteProxy.py
===================================================================
--- trunk/InteProxy.py 2007-04-24 14:16:15 UTC (rev 63)
+++ trunk/InteProxy.py 2007-04-24 15:33:23 UTC (rev 64)
@@ -13,100 +13,7 @@
python InteProxy.py
"""
-import os
-import sys
-import optparse
-import urlparse
-import urllib2
-import inteproxy.proxyconnection as proxyconnection
-from inteproxy.transcoder import transcoder_map
-from inteproxy.getpassword import getpassword
-from inteproxy.proxycore import (InteProxyHTTPRequestHandler,
- MasterWorkerServer,
- log_date_time_string)
+from inteproxy.main import run_server
-inteproxy_version = "0.1.2"
-
-
-class IntePasswordManager(urllib2.HTTPPasswordMgr):
-
- def find_user_password(self, realm, authuri):
- user, password \
- = urllib2.HTTPPasswordMgr.find_user_password(self, realm, authuri)
- if user is None:
- # no password known yet. Ask the user
- authuri = "https://" + "".join(self.reduce_uri(authuri))
- title = "Username for %r realm %r: " % (authuri, realm)
- user, password = getpassword(title)
- return user, password
-
-def setup_urllib2(debuglevel):
- auth_handler = urllib2.HTTPBasicAuthHandler(IntePasswordManager())
- if os.environ.has_key('https_proxy'):
- https_proxy = urlparse.urlsplit(os.getenv('https_proxy'))[1]
- del os.environ['https_proxy']
- sys.stderr.write("[%s] Using HTTPS proxy: %s\n"
- % (log_date_time_string(), https_proxy))
- opener = urllib2.build_opener(
- auth_handler,
- proxyconnection.ConnectHTTPHandler(proxy=https_proxy,
- debuglevel=debuglevel),
- proxyconnection.ConnectHTTPSHandler(proxy=https_proxy,
- debuglevel=debuglevel))
- else:
- httphandler = urllib2.HTTPHandler(debuglevel=debuglevel)
- httpshandler = urllib2.HTTPSHandler(debuglevel=debuglevel)
- opener = urllib2.build_opener(auth_handler, httphandler,
- httpshandler)
- urllib2.install_opener(opener)
-
-
-def run_server(HandlerClass = InteProxyHTTPRequestHandler,
- ServerClass = MasterWorkerServer):
- """Run the InteProxy server"""
- parser = optparse.OptionParser()
- # The default config file name. It's an absolute filename for the
- # default config file, so that it must be in a specific directory
- # (for now the same directory as InteProxy.py) and we don't
- # accidentally pick up other config files if InteProxy is started
- # with a different working directory.
- default_config_file = os.path.join(os.path.dirname(__file__),
- "inteproxy.cfg")
- parser.set_defaults(port=64609, workers=5, debug_level=0,
- config_file=default_config_file)
- parser.add_option("--logfile")
- parser.add_option("--allow-shutdown", action="store_true")
- parser.add_option("--port", type="int")
- parser.add_option("--workers", type="int")
- parser.add_option("--debug-level", type="int")
- parser.add_option("--config-file")
- opts, rest = parser.parse_args()
-
- HandlerClass.allow_shutdown = opts.allow_shutdown
- HandlerClass.debug_level = opts.debug_level
-
- transcoder_map.read_config(opts.config_file)
-
- setup_urllib2(opts.debug_level)
-
- server_address = ('localhost', opts.port)
-
- if opts.logfile:
- sys.stderr = open(opts.logfile, "a", 0)
-
- sys.stderr.write("InteProxy Version %s\n" % inteproxy_version)
- sys.stderr.write("[%s] server starting up\n" % log_date_time_string())
-
- httpd = ServerClass(server_address, HandlerClass, opts.workers)
-
- print "Serving HTTP on port", opts.port, "..."
- sys.stderr.write("[%s] serving HTTP on port %d\n"
- % (log_date_time_string(), opts.port))
- httpd.serve_forever()
- logmessage = "[%s] server stopped" % (log_date_time_string(),)
- print logmessage
- sys.stderr.write(logmessage + "\n")
-
-
if __name__ == '__main__':
run_server()
Added: trunk/inteproxy/main.py
===================================================================
--- trunk/inteproxy/main.py 2007-04-24 14:16:15 UTC (rev 63)
+++ trunk/inteproxy/main.py 2007-04-24 15:33:23 UTC (rev 64)
@@ -0,0 +1,103 @@
+#! /usr/bin/python
+# Copyright (C) 2006, 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Main entry point for the InteProxy"""
+
+import os
+import sys
+import optparse
+import urlparse
+import urllib2
+import inteproxy.proxyconnection as proxyconnection
+from inteproxy.transcoder import transcoder_map
+from inteproxy.getpassword import getpassword
+from inteproxy.proxycore import (InteProxyHTTPRequestHandler,
+ MasterWorkerServer,
+ log_date_time_string)
+
+inteproxy_version = "0.1.2"
+
+
+class IntePasswordManager(urllib2.HTTPPasswordMgr):
+
+ def find_user_password(self, realm, authuri):
+ user, password \
+ = urllib2.HTTPPasswordMgr.find_user_password(self, realm, authuri)
+ if user is None:
+ # no password known yet. Ask the user
+ authuri = "https://" + "".join(self.reduce_uri(authuri))
+ title = "Username for %r realm %r: " % (authuri, realm)
+ user, password = getpassword(title)
+ return user, password
+
+def setup_urllib2(debuglevel):
+ auth_handler = urllib2.HTTPBasicAuthHandler(IntePasswordManager())
+ if os.environ.has_key('https_proxy'):
+ https_proxy = urlparse.urlsplit(os.getenv('https_proxy'))[1]
+ del os.environ['https_proxy']
+ sys.stderr.write("[%s] Using HTTPS proxy: %s\n"
+ % (log_date_time_string(), https_proxy))
+ opener = urllib2.build_opener(
+ auth_handler,
+ proxyconnection.ConnectHTTPHandler(proxy=https_proxy,
+ debuglevel=debuglevel),
+ proxyconnection.ConnectHTTPSHandler(proxy=https_proxy,
+ debuglevel=debuglevel))
+ else:
+ httphandler = urllib2.HTTPHandler(debuglevel=debuglevel)
+ httpshandler = urllib2.HTTPSHandler(debuglevel=debuglevel)
+ opener = urllib2.build_opener(auth_handler, httphandler,
+ httpshandler)
+ urllib2.install_opener(opener)
+
+
+def run_server(HandlerClass = InteProxyHTTPRequestHandler,
+ ServerClass = MasterWorkerServer):
+ """Run the InteProxy server"""
+ parser = optparse.OptionParser()
+ # The default config file name. It's an absolute filename for the
+ # default config file, so that it must be in a specific directory
+ # (for now the same directory as InteProxy.py) and we don't
+ # accidentally pick up other config files if InteProxy is started
+ # with a different working directory.
+ default_config_file = os.path.join(os.path.dirname(__file__), "..",
+ "inteproxy.cfg")
+ parser.set_defaults(port=64609, workers=5, debug_level=0,
+ config_file=default_config_file)
+ parser.add_option("--logfile")
+ parser.add_option("--allow-shutdown", action="store_true")
+ parser.add_option("--port", type="int")
+ parser.add_option("--workers", type="int")
+ parser.add_option("--debug-level", type="int")
+ parser.add_option("--config-file")
+ opts, rest = parser.parse_args()
+
+ HandlerClass.allow_shutdown = opts.allow_shutdown
+ HandlerClass.debug_level = opts.debug_level
+
+ transcoder_map.read_config(opts.config_file)
+
+ setup_urllib2(opts.debug_level)
+
+ server_address = ('localhost', opts.port)
+
+ if opts.logfile:
+ sys.stderr = open(opts.logfile, "a", 0)
+
+ sys.stderr.write("InteProxy Version %s\n" % inteproxy_version)
+ sys.stderr.write("[%s] server starting up\n" % log_date_time_string())
+
+ httpd = ServerClass(server_address, HandlerClass, opts.workers)
+
+ print "Serving HTTP on port", opts.port, "..."
+ sys.stderr.write("[%s] serving HTTP on port %d\n"
+ % (log_date_time_string(), opts.port))
+ httpd.serve_forever()
+ logmessage = "[%s] server stopped" % (log_date_time_string(),)
+ print logmessage
+ sys.stderr.write(logmessage + "\n")
Property changes on: trunk/inteproxy/main.py
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the Inteproxy-commits
mailing list