summaryrefslogtreecommitdiff
path: root/pbr/packaging.py
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2015-06-24 16:06:01 -0400
committerSean Dague <sean@dague.net>2015-07-14 11:40:39 -0400
commit5b46cb85740ab8b5d8e8577b75dd9f4f6df29db5 (patch)
tree2903ee429a6c41865937533a5fa4d8dd3a66323a /pbr/packaging.py
parent7d974fb7eae9a137901bb9d3c713cd439c35a884 (diff)
downloadpbr-5b46cb85740ab8b5d8e8577b75dd9f4f6df29db5.tar.gz
Add wsgi_scripts support to PBR
As we attempt to get more of OpenStack API servers to be runnable as a regular WSGI application, we should provide support in PBR for building these base scripts just like the console scripts. This adds a new 'wsgi_scripts' group which builds a base script that will run under mod_wsgi as expected. It also has a CLI fallback mode, so that the application can be brought up as a wsgiref simple_server for quick local testing and development. All wsgiref servers default to binding to port 8000, but that can be overridden. To support this, and possible future expansion of the script types, the group list now iterates over a dictionary of group_name => template mappings. This includes basic testing. It also includes tests which would run an actual wsgi environment. These are currently skipped as they can't be reliably run in the gate for timing reasons on stdout processing. Change-Id: I334639d7ecaad2703d1ff675880a314cc28e2334
Diffstat (limited to 'pbr/packaging.py')
-rw-r--r--pbr/packaging.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index ebdfb09..be5eb74 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -212,6 +212,36 @@ except ImportError:
def have_nose():
return _have_nose
+_wsgi_text = """#PBR Generated from %(group)r
+
+from %(module_name)s import %(import_target)s
+
+if __name__ == "__main__":
+ import argparse
+ import socket
+ import wsgiref.simple_server as wss
+
+ my_ip = socket.gethostbyname(socket.gethostname())
+ parser = argparse.ArgumentParser(
+ description=%(import_target)s.__doc__,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--port', '-p', type=int, default=8000,
+ help='TCP port to listen on')
+ args = parser.parse_args()
+ server = wss.make_server('', args.port, %(invoke_target)s())
+
+ print("*" * 80)
+ print("STARTING test server %(module_name)s.%(invoke_target)s")
+ url = "http://%%s:%%d/" %% (my_ip, server.server_port)
+ print("Available at %%s" %% url)
+ print("DANGER! For testing only, do not use in production")
+ print("*" * 80)
+
+ server.serve_forever()
+else:
+ application = %(invoke_target)s()
+
+"""
_script_text = """# PBR Generated from %(group)r
@@ -225,16 +255,25 @@ if __name__ == "__main__":
"""
+# the following allows us to specify different templates per entry
+# point group when generating pbr scripts.
+ENTRY_POINTS_MAP = {
+ 'console_scripts': _script_text,
+ 'gui_scripts': _script_text,
+ 'wsgi_scripts': _wsgi_text
+}
+
+
def override_get_script_args(
dist, executable=os.path.normpath(sys.executable), is_wininst=False):
"""Override entrypoints console_script."""
header = easy_install.get_script_header("", executable, is_wininst)
- for group in 'console_scripts', 'gui_scripts':
+ for group, template in ENTRY_POINTS_MAP.items():
for name, ep in dist.get_entry_map(group).items():
if not ep.attrs or len(ep.attrs) > 2:
raise ValueError("Script targets must be of the form "
"'func' or 'Class.class_method'.")
- script_text = _script_text % dict(
+ script_text = template % dict(
group=group,
module_name=ep.module_name,
import_target=ep.attrs[0],