def handle_request(self, environ, start_response): if self.startup_error: status = '200 OK' result, headers = self.error_page(environ, message=self.startup_error) start_response(status, headers) return result if environ['REQUEST_METHOD'] not in ['GET', 'POST', 'HEAD']: status = '405 Method Not Allowed' result, headers = self.error_page(environ, message="Method Not Allowed") start_response(status, headers) return result environ['koji.options'] = self.options try: environ['koji.headers'] = [] func, data = self.prep_handler(environ) result = func(environ, **data) status = '200 OK' except ServerRedirect: status = '302 Found' location = environ['koji.redirect'] result = '<p>Redirect: <a href="%s">here</a></p>\n' % location environ['koji.headers'].append(['Location', location]) except URLNotFound: status = "404 Not Found" msg = "Not found: %s" % environ['REQUEST_URI'] result, headers = self.error_page(environ, message=msg, err=False) start_response(status, headers) return result except Exception: tb_str = ''.join(traceback.format_exception(*sys.exc_info())) self.logger.error(tb_str) status = '500 Internal Server Error' result, headers = self.error_page(environ) start_response(status, headers) return result headers = { 'allow': ('Allow', 'GET, POST, HEAD'), } extra = [] for name, value in environ.get('koji.headers', []): key = name.lower() if key == 'set-cookie': extra.append((name, value)) else: # last one wins headers[key] = (name, value) if isinstance(result, six.string_types): headers.setdefault('content-length', ('Content-Length', str(len(result)))) headers.setdefault('content-type', ('Content-Type', 'text/html')) headers = to_list(headers.values()) + extra self.logger.debug("Headers:") self.logger.debug(koji.util.LazyString(pprint.pformat, [headers])) start_response(status, headers) if isinstance(result, six.string_types): result = [result] return result
def handle_request(self, environ, start_response): if self.startup_error: status = '200 OK' result, headers = self.error_page(environ, message=self.startup_error) start_response(status, headers) return result if environ['REQUEST_METHOD'] not in ['GET', 'POST', 'HEAD']: status = '405 Method Not Allowed' result, headers = self.error_page(environ, message="Method Not Allowed") start_response(status, headers) return result environ['koji.options'] = self.options try: environ['koji.headers'] = [] func, data = self.prep_handler(environ) result = func(environ, **data) status = '200 OK' except ServerRedirect: status = '302 Found' location = environ['koji.redirect'] result = '<p>Redirect: <a href="%s">here</a></p>\n' % location environ['koji.headers'].append(['Location', location]) except URLNotFound: status = "404 Not Found" msg = "Not found: %s" % environ['REQUEST_URI'] result, headers = self.error_page(environ, message=msg, err=False) start_response(status, headers) return result except Exception: tb_str = ''.join(traceback.format_exception(*sys.exc_info())) self.logger.error(tb_str) status = '500 Internal Server Error' result, headers = self.error_page(environ) start_response(status, headers) return result headers = { 'allow': ('Allow', 'GET, POST, HEAD'), } extra = [] for name, value in environ.get('koji.headers', []): key = name.lower() if key == 'set-cookie': extra.append((name, value)) else: # last one wins headers[key] = (name, value) if isinstance(result, six.string_types): headers.setdefault('content-length', ('Content-Length', str(len(result)))) headers.setdefault('content-type', ('Content-Type', 'text/html')) headers = to_list(headers.values()) + extra self.logger.debug("Headers:") self.logger.debug(koji.util.LazyString(pprint.pformat, [headers])) start_response(status, headers) return self._tobytes(result)
def get_epilog_str(progname=None): if progname is None: progname = os.path.basename(sys.argv[0]) or 'koji' categories_ordered=', '.join(sorted(['all'] + to_list(categories.keys()))) epilog_str = ''' Try "%(progname)s --help" for help about global options Try "%(progname)s help" to get all available commands Try "%(progname)s <command> --help" for help about the options of a particular command Try "%(progname)s help <category>" to get commands under a particular category Available categories are: %(categories)s ''' % ({'progname': progname, 'categories': categories_ordered}) return _(epilog_str)
def all_actions(self): """report a list of all actions in the ruleset (only the first word of the action is considered) """ def _recurse(rules, index): for tests, negate, action in rules: if isinstance(action, list): _recurse(action, index) else: name = action.split(None, 1)[0] index[name] = 1 index = {} _recurse(self.ruleset, index) return to_list(index.keys())
# Example Koji callback # Copyright (c) 2009-2014 Red Hat, Inc. # This callback simply logs all of its args using the logging module # # Authors: # Mike Bonnet <*****@*****.**> from __future__ import absolute_import import logging from koji.plugin import callback, callbacks, ignore_error from koji.util import to_list @callback(*to_list(callbacks.keys())) @ignore_error def echo(cbtype, *args, **kws): logging.getLogger('koji.plugin.echo').info( 'Called the %s callback, args: %s; kws: %s', cbtype, str(args), str(kws))
# Example Koji callback # Copyright (c) 2009-2014 Red Hat, Inc. # This callback simply logs all of its args using the logging module # # Authors: # Mike Bonnet <*****@*****.**> from __future__ import absolute_import from koji.plugin import callbacks, callback, ignore_error from koji.util import to_list import logging @callback(*to_list(callbacks.keys())) @ignore_error def echo(cbtype, *args, **kws): logging.getLogger('koji.plugin.echo').info('Called the %s callback, args: %s; kws: %s', cbtype, str(args), str(kws))