def handle_exception(event=None, log=True, short=False, txt=""): errormsg = exceptionmsg() #logging.error(errormsg) if log: rlog(1000, 'EXCEPTION', errormsg) if event: event.reply(errormsg)
def modification_callback(file): rlog(10, 'tserver', 'Detected modification of %s, restarting.' \ % file)
def main(startstring): if not gottrac: rlog(100, 'tracserver', 'trac is not installed') return global httpd from optparse import OptionParser, OptionValueError parser = OptionParser(usage='usage: %prog [options] [projenv] ...', version='%%prog %s' % VERSION) auths = {} def _auth_callback(option, opt_str, value, parser, cls): info = value.split(',', 3) if len(info) != 3: raise OptionValueError("Incorrect number of parameters for %s" % option) env_name, filename, realm = info auths[env_name] = cls(os.path.abspath(filename), realm) def _validate_callback(option, opt_str, value, parser, valid_values): if value not in valid_values: raise OptionValueError('%s must be one of: %s, not %s' % (opt_str, '|'.join(valid_values), value)) setattr(parser.values, option.dest, value) parser.add_option('-a', '--auth', action='callback', type='string', metavar='DIGESTAUTH', callback=_auth_callback, callback_args=(DigestAuthentication,), help='[projectdir],[htdigest_file],[realm]') parser.add_option('--basic-auth', action='callback', type='string', metavar='BASICAUTH', callback=_auth_callback, callback_args=(BasicAuthentication,), help='[projectdir],[htpasswd_file],[realm]') parser.add_option('-p', '--port', action='store', type='int', dest='port', help='the port number to bind to') parser.add_option('-b', '--hostname', action='store', dest='hostname', help='the host name or IP address to bind to') parser.add_option('--protocol', action='callback', type="string", dest='protocol', callback=_validate_callback, callback_args=(('http', 'scgi', 'ajp', 'fcgi'),), help='http|scgi|ajp|fcgi') parser.add_option('-e', '--env-parent-dir', action='store', dest='env_parent_dir', metavar='PARENTDIR', help='parent directory of the project environments') parser.add_option('--base-path', action='store', type='string', # XXX call this url_base_path? dest='base_path', help='the initial portion of the request URL\'s "path"') parser.add_option('-r', '--auto-reload', action='store_true', dest='autoreload', help='restart automatically when sources are modified') parser.add_option('-s', '--single-env', action='store_true', dest='single_env', help='only serve a single ' 'project without the project list', default=False) if os.name == 'posix': parser.add_option('-d', '--daemonize', action='store_true', dest='daemonize', help='run in the background as a daemon') parser.add_option('--pidfile', action='store', dest='pidfile', help='When daemonizing, file to which to write pid') parser.add_option('--umask', action='store', type='int', dest='umask', metavar='MASK', help='When daemonizing, file mode creation mask ' 'to use (default 022)') parser.set_defaults(port=None, hostname='', base_path='', daemonize=False, protocol='http', umask=022) options, args = parser.parse_args(startstring.split()) if not args and not options.env_parent_dir: parser.error('either the --env-parent-dir option or at least one ' 'environment must be specified') if options.single_env: if options.env_parent_dir: parser.error('the --single-env option cannot be used with ' '--env-parent-dir') elif len(args) > 1: parser.error('the --single-env option cannot be used with ' 'more than one enviroment') if options.daemonize and options.autoreload: parser.error('the --auto-reload option cannot be used with ' '--daemonize') if options.port is None: options.port = { 'http': 80, 'scgi': 4000, 'ajp': 8009, 'fcgi': 8000, }[options.protocol] server_address = (options.hostname, options.port) # relative paths don't work when daemonized args = [os.path.abspath(a) for a in args] if options.env_parent_dir: options.env_parent_dir = os.path.abspath(options.env_parent_dir) if parser.has_option('pidfile') and options.pidfile: options.pidfile = os.path.abspath(options.pidfile) wsgi_app = TracEnvironMiddleware(dispatch_request, options.env_parent_dir, args, options.single_env) if auths: if options.single_env: project_name = os.path.basename(args[0]) wsgi_app = AuthenticationMiddleware(wsgi_app, auths, project_name) else: wsgi_app = AuthenticationMiddleware(wsgi_app, auths) base_path = options.base_path.strip('/') if base_path: wsgi_app = BasePathMiddleware(wsgi_app, base_path) try: httpd = TracHTTPServer(server_address, wsgi_app, options.env_parent_dir, args) except socket.error, ex: if 'already in use' in str(ex): rlog(10, 'tserver', 'server is already running') return
project_name = os.path.basename(args[0]) wsgi_app = AuthenticationMiddleware(wsgi_app, auths, project_name) else: wsgi_app = AuthenticationMiddleware(wsgi_app, auths) base_path = options.base_path.strip('/') if base_path: wsgi_app = BasePathMiddleware(wsgi_app, base_path) try: httpd = TracHTTPServer(server_address, wsgi_app, options.env_parent_dir, args) except socket.error, ex: if 'already in use' in str(ex): rlog(10, 'tserver', 'server is already running') return rlog(10, 'tserver', 'Server starting in PID %i.' % os.getpid()) addr, port = server_address if not addr or addr == '0.0.0.0': rlog(10, 'tserver', 'Serving on 0.0.0.0:%s view at http://127.0.0.1:%s/%s' \ % (port, port, base_path)) else: rlog(10, 'tserver', 'Serving on http://%s:%s/%s' % (addr, port, base_path)) try: if options.daemonize: daemon.daemonize(pidfile=options.pidfile, progname='tracd', umask=options.umask) if options.autoreload: def modification_callback(file): rlog(10, 'tserver', 'Detected modification of %s, restarting.' \
def main(startstring): if not gottrac: rlog(100, 'tracserver', 'trac is not installed') return global httpd from optparse import OptionParser, OptionValueError parser = OptionParser(usage='usage: %prog [options] [projenv] ...', version='%%prog %s' % VERSION) auths = {} def _auth_callback(option, opt_str, value, parser, cls): info = value.split(',', 3) if len(info) != 3: raise OptionValueError("Incorrect number of parameters for %s" % option) env_name, filename, realm = info auths[env_name] = cls(os.path.abspath(filename), realm) def _validate_callback(option, opt_str, value, parser, valid_values): if value not in valid_values: raise OptionValueError('%s must be one of: %s, not %s' % (opt_str, '|'.join(valid_values), value)) setattr(parser.values, option.dest, value) parser.add_option('-a', '--auth', action='callback', type='string', metavar='DIGESTAUTH', callback=_auth_callback, callback_args=(DigestAuthentication, ), help='[projectdir],[htdigest_file],[realm]') parser.add_option('--basic-auth', action='callback', type='string', metavar='BASICAUTH', callback=_auth_callback, callback_args=(BasicAuthentication, ), help='[projectdir],[htpasswd_file],[realm]') parser.add_option('-p', '--port', action='store', type='int', dest='port', help='the port number to bind to') parser.add_option('-b', '--hostname', action='store', dest='hostname', help='the host name or IP address to bind to') parser.add_option('--protocol', action='callback', type="string", dest='protocol', callback=_validate_callback, callback_args=(('http', 'scgi', 'ajp', 'fcgi'), ), help='http|scgi|ajp|fcgi') parser.add_option('-e', '--env-parent-dir', action='store', dest='env_parent_dir', metavar='PARENTDIR', help='parent directory of the project environments') parser.add_option( '--base-path', action='store', type='string', # XXX call this url_base_path? dest='base_path', help='the initial portion of the request URL\'s "path"') parser.add_option('-r', '--auto-reload', action='store_true', dest='autoreload', help='restart automatically when sources are modified') parser.add_option('-s', '--single-env', action='store_true', dest='single_env', help='only serve a single ' 'project without the project list', default=False) if os.name == 'posix': parser.add_option('-d', '--daemonize', action='store_true', dest='daemonize', help='run in the background as a daemon') parser.add_option('--pidfile', action='store', dest='pidfile', help='When daemonizing, file to which to write pid') parser.add_option('--umask', action='store', type='int', dest='umask', metavar='MASK', help='When daemonizing, file mode creation mask ' 'to use (default 022)') parser.set_defaults(port=None, hostname='', base_path='', daemonize=False, protocol='http', umask=022) options, args = parser.parse_args(startstring.split()) if not args and not options.env_parent_dir: parser.error('either the --env-parent-dir option or at least one ' 'environment must be specified') if options.single_env: if options.env_parent_dir: parser.error('the --single-env option cannot be used with ' '--env-parent-dir') elif len(args) > 1: parser.error('the --single-env option cannot be used with ' 'more than one enviroment') if options.daemonize and options.autoreload: parser.error('the --auto-reload option cannot be used with ' '--daemonize') if options.port is None: options.port = { 'http': 80, 'scgi': 4000, 'ajp': 8009, 'fcgi': 8000, }[options.protocol] server_address = (options.hostname, options.port) # relative paths don't work when daemonized args = [os.path.abspath(a) for a in args] if options.env_parent_dir: options.env_parent_dir = os.path.abspath(options.env_parent_dir) if parser.has_option('pidfile') and options.pidfile: options.pidfile = os.path.abspath(options.pidfile) wsgi_app = TracEnvironMiddleware(dispatch_request, options.env_parent_dir, args, options.single_env) if auths: if options.single_env: project_name = os.path.basename(args[0]) wsgi_app = AuthenticationMiddleware(wsgi_app, auths, project_name) else: wsgi_app = AuthenticationMiddleware(wsgi_app, auths) base_path = options.base_path.strip('/') if base_path: wsgi_app = BasePathMiddleware(wsgi_app, base_path) try: httpd = TracHTTPServer(server_address, wsgi_app, options.env_parent_dir, args) except socket.error, ex: if 'already in use' in str(ex): rlog(10, 'tserver', 'server is already running') return
project_name = os.path.basename(args[0]) wsgi_app = AuthenticationMiddleware(wsgi_app, auths, project_name) else: wsgi_app = AuthenticationMiddleware(wsgi_app, auths) base_path = options.base_path.strip('/') if base_path: wsgi_app = BasePathMiddleware(wsgi_app, base_path) try: httpd = TracHTTPServer(server_address, wsgi_app, options.env_parent_dir, args) except socket.error, ex: if 'already in use' in str(ex): rlog(10, 'tserver', 'server is already running') return rlog(10, 'tserver', 'Server starting in PID %i.' % os.getpid()) addr, port = server_address if not addr or addr == '0.0.0.0': rlog(10, 'tserver', 'Serving on 0.0.0.0:%s view at http://127.0.0.1:%s/%s' \ % (port, port, base_path)) else: rlog(10, 'tserver', 'Serving on http://%s:%s/%s' % (addr, port, base_path)) try: if options.daemonize: daemon.daemonize(pidfile=options.pidfile, progname='tracd', umask=options.umask) if options.autoreload: