From b24f1b297824618d4df9a8c28725b1ab254a3902 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Jun 27 2017 16:58:56 +0000 Subject: fallback to default config if local fakehub/fakeweb config missing --- diff --git a/devtools/README.md b/devtools/README.md new file mode 100644 index 0000000..601af8d --- /dev/null +++ b/devtools/README.md @@ -0,0 +1,44 @@ +Koji Developer Tools +-------------------- + +This directory contains some tools that developers may find useful. + +fakehub +------- + +This script runs a single hub call in the foreground (no httpd) and +dumps the results. It runs using the code from the checkout. + +The call to be executed is specified on the command line, much like +the ``koji call`` command. + +For example: +``` +[mike@localhost koji]$ devtools/fakehub getTag 1 +``` + +You will see hub logs on the console. The call result is pretty printed +at the end. + +This tool makes it possible to run hub code through the debugger or +or profiler with relative ease. + +fakehub looks for ``fakehub.conf`` or ``fakehub.conf.d`` in the devtools +directory. If either is present, then +``koji.hub.ConfigFile`` and ``koji.hub.ConfigDir`` are set to these values. +If neither is, then the code will fall back to the default (system) config. + + +fakeweb +------- + +This tool is similar to the fakehub tool, instead of a single pass it starts +a web server on port 8000 and starts serving. + +As with the fakehub tool, fakeweb runs in the foreground in a single thread, making +it possible to debug web code. + +Similar to fakehub, fakeweb looks for ``fakeweb.conf`` or ``fakeweb.conf.d`` +in the devtools directory. If either is present, then +``koji.web.ConfigFile`` and ``koji.web.ConfigDir`` are set to these values. +If neither is, then the code will fall back to the default (system) config. diff --git a/devtools/fakehub b/devtools/fakehub index be3d82c..73696f5 100755 --- a/devtools/fakehub +++ b/devtools/fakehub @@ -76,6 +76,14 @@ def parse_response(data): return result +def set_config(environ): + lconfig = "%s/devtools/fakehub.conf" % os.getcwd() + lconfigd = "%s/devtools/fakehub.conf.d" % os.getcwd() + if os.path.exists(lconfig) or os.path.exists(lconfigd): + environ['koji.hub.ConfigFile'] = lconfig + environ['koji.hub.ConfigDir'] = lconfigd + + def main(): environ = {} environ['SCRIPT_FILENAME'] = kojixmlrpc.__file__ @@ -86,8 +94,7 @@ def main(): environ['wsgi.input'] = cStringIO.StringIO(get_request()) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_TYPE'] = 'text/xml' - environ['koji.hub.ConfigFile'] = "%s/devtools/fakehub.conf" % os.getcwd() - environ['koji.hub.ConfigDir'] = "%s/devtools/fakehub.conf.d" % os.getcwd() + set_config(environ) print('RESULT:') data = kojixmlrpc.application(environ, start_response) result = parse_response(data) diff --git a/devtools/fakeweb b/devtools/fakeweb index 9e2da02..7a7326f 100755 --- a/devtools/fakeweb +++ b/devtools/fakeweb @@ -95,14 +95,21 @@ def redirect_static(environ, start_response): return [response] +def set_config(environ): + lconfig = "%s/devtools/fakeweb.conf" % os.getcwd() + lconfigd = "%s/devtools/fakeweb.conf.d" % os.getcwd() + if os.path.exists(lconfig) or os.path.exists(lconfigd): + environ['koji.web.ConfigFile'] = lconfig + environ['koji.web.ConfigDir'] = lconfigd + + def application(environ, start_response): global FIRST setup_testing_defaults(environ) # provide some needed info environ['SCRIPT_FILENAME'] = wsgi_publisher.__file__ environ['REQUEST_URI'] = get_url(environ) - environ['koji.web.ConfigFile'] = "%s/devtools/fakeweb.conf" % os.getcwd() - environ['koji.web.ConfigDir'] = "%s/devtools/fakeweb.conf.d" % os.getcwd() + set_config(environ) if FIRST: pprint.pprint(environ) FIRST = False