コード例 #1
0
def main(args):
    # Parse and validate command line options.
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) != 1:
        usage()
    if options.profile:
        if options.howmany <= 0:
            die("-P requires a -c value")
        if options.servtype not in ('default', 'plain'):
            die("-P conflicts with -f and -t")
        stype = "plain"
    else:
        stype = options.servtype
        if stype == "default":
            stype = "thread"

    # Load up the configuration from the single argument, and then
    # create the dependant services and stuff.
    procfunc, _ = dwconfig.materialize(args[0], options)

    # Generate an appropriate WSGI server.
    httpd = wsgi.server.gen_server((options.addr, options.port), procfunc,
                                   stype)

    # Depending on the options, serve the server in various ways.
    if options.profile:
        doProfile(httpd, options.howmany)
    elif options.howmany > 0:
        runLimited(httpd, options.howmany)
    else:
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            pass
コード例 #2
0
def main(args):
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) not in (2, 3):
        usage()

    url = args[1]
    rend = None
    if len(args) == 3:
        try:
            rend = htmlrends.get_renderer(args[2])
        except derrors.RendErr as e:
            die(str(e))

    try:
        app, r = dwconfig.materialize(args[0], options)
        # We're one of the people who actually needs this.
        cfg, ms, webserv, staticstore, cachestore = r
    except derrors.WikiErr as e:
        die("dwiki error: " + str(e))

    env = setup_env(url)
    if rend:
        httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore)
        env['dwiki.logger'] = None
        rdata = httpcore.gather_reqdata(env)
        if 'query' not in rdata:
            die("URL %s is not accepted by the core" % url)
        ctx = context.HTMLContext(cfg, ms, webserv, rdata)
        if cachestore:
            ctx.setvar(':_cachestore', cachestore)
        runrend(rend, ctx)
    else:
        runwsgi(env, app)
コード例 #3
0
ファイル: dwiki-serv.py プロジェクト: siebenmann/dwiki
def main(args):
	# Parse and validate command line options.
	parser = setup_options()
	(options, args) = parser.parse_args(args)
	if len(args) != 1:
		usage()
	if options.profile:
		if options.howmany <= 0:
			die("-P requires a -c value")
		if options.servtype not in ('default', 'plain'):
			die("-P conflicts with -f and -t")
		stype = "plain"
	else:
		stype = options.servtype
		if stype == "default":
			stype = "thread"

	# Load up the configuration from the single argument, and then
	# create the dependant services and stuff.
	procfunc, _ = dwconfig.materialize(args[0], options)

	# Generate an appropriate WSGI server.
	httpd = wsgi.server.gen_server((options.addr, options.port),
				       procfunc, stype)

	# Depending on the options, serve the server in various ways.
	if options.profile:
		doProfile(httpd, options.howmany)
	elif options.howmany > 0:
		runLimited(httpd, options.howmany)
	else:
		try:
			httpd.serve_forever()
		except KeyboardInterrupt:
			pass
コード例 #4
0
ファイル: dwiki-cat.py プロジェクト: siebenmann/dwiki
def main(args):
	parser = setup_options()
	(options, args) = parser.parse_args(args)
	if len(args) not in (2, 3):
		usage()

	url = args[1]
	rend = None
	if len(args) == 3:
		try:
			rend = htmlrends.get_renderer(args[2])
		except derrors.RendErr as e:
			die(str(e))

	try:
		app, r = dwconfig.materialize(args[0], options)
		# We're one of the people who actually needs this.
		cfg, ms, webserv, staticstore, cachestore = r
	except derrors.WikiErr as e:
		die("dwiki error: "+str(e))

	env = setup_env(url)
	if rend:
		httpcore.environSetup(env, cfg, ms, webserv, staticstore,
				      cachestore)
		env['dwiki.logger'] = None
		rdata = httpcore.gather_reqdata(env)
		if 'query' not in rdata:
			die("URL %s is not accepted by the core" % url)
		ctx = context.HTMLContext(cfg, ms, webserv, rdata)
		if cachestore:
			ctx.setvar(':_cachestore', cachestore)
		runrend(rend, ctx)
	else:
		runwsgi(env, app)
コード例 #5
0
def main(args):
	parser = setup_options()
	(options, args) = parser.parse_args(args)
	if len(args) != 1:
		usage()
	try:
		app, _ = dwconfig.materialize(args[0], options)
		if options.nullapp:
			app = NullApp
		wsgi.cgi.run_with_cgi(app)
	except derrors.WikiErr as e:
		die("dwiki error: "+str(e))
コード例 #6
0
ファイル: testbench.py プロジェクト: samveen/dwiki
def main(args):
	parser = setup_options()
	(options, args) = parser.parse_args(args)
	op = options.operation
	if len(args) not in (3, 4):
		usage()

	cnt = int(args[2])
	url = args[1]
	rend = None
	if len(args) == 4:
		try:
			rend = htmlrends.get_renderer(args[3])
		except derrors.RendErr as e:
			die(str(e))

	try:
		app, r = dwconfig.materialize(args[0], options)
		# We're one of the people who actually needs this.
		cfg, ms, webserv, staticstore, cachestore = r

	except derrors.WikiErr as e:
		die("dwiki error: "+str(e))

	env = setup_env(url)
	if options.ip6origin:
		# This format matches what the Fedora 17 lighttpd
		# puts into $REMOTE_ADDR. Your mileage may vary for
		# other web servers, although it's probably right
		# for Apache too.
		env['REMOTE_ADDR'] = "::1"
		
	if rend:
		httpcore.environSetup(env, cfg, ms, webserv, staticstore,
				      cachestore)
		env['dwiki.logger'] = None
		rdata = httpcore.gather_reqdata(env)
		if 'query' not in rdata:
			die("URL %s is not accepted by the core" % url)
		ctx = context.HTMLContext(cfg, ms, webserv, rdata)
		if cachestore:
			ctx.setvar(':_cachestore', cachestore)
		if options.prerun:
			runLimited(*(options.prerun, runrend, rend, ctx))
		op(cnt, runrend, rend, ctx)
	else:
		if options.prerun:
			runLimited(*(options.prerun, runwsgi, env, app))
		op(cnt, runwsgi, env, app)
コード例 #7
0
ファイル: dwiki-cache.py プロジェクト: siebenmann/dwiki
def main(args):
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) < 3:
        usage()

    options.extraconfig.append("internal_bfc-force-caching")
    try:
        app, r = dwconfig.materialize(args[0], options)
    except derrors.WikiErr as e:
        die("dwiki error: " + str(e))

    for url in args[2:]:
        env = setup_env(url, args[1], options)
        runwsgi(env, app)
コード例 #8
0
ファイル: dwiki-cache.py プロジェクト: samveen/dwiki
def main(args):
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) < 3:
        usage()

    options.extraconfig.append("internal_bfc-force-caching")
    try:
        app, r = dwconfig.materialize(args[0], options)
    except derrors.WikiErr as e:
        die("dwiki error: " + str(e))

    for url in args[2:]:
        env = setup_env(url, args[1], options)
        runwsgi(env, app)
コード例 #9
0
ファイル: testbench.py プロジェクト: siebenmann/dwiki
def main(args):
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    op = options.operation
    if len(args) not in (3, 4):
        usage()

    cnt = int(args[2])
    url = args[1]
    rend = None
    if len(args) == 4:
        try:
            rend = htmlrends.get_renderer(args[3])
        except derrors.RendErr as e:
            die(str(e))

    try:
        app, r = dwconfig.materialize(args[0], options)
        # We're one of the people who actually needs this.
        cfg, ms, webserv, staticstore, cachestore = r

    except derrors.WikiErr as e:
        die("dwiki error: " + str(e))

    env = setup_env(url)
    if options.ip6origin:
        # This format matches what the Fedora 17 lighttpd
        # puts into $REMOTE_ADDR. Your mileage may vary for
        # other web servers, although it's probably right
        # for Apache too.
        env["REMOTE_ADDR"] = "::1"

    if rend:
        httpcore.environSetup(env, cfg, ms, webserv, staticstore, cachestore)
        env["dwiki.logger"] = None
        rdata = httpcore.gather_reqdata(env)
        if "query" not in rdata:
            die("URL %s is not accepted by the core" % url)
        ctx = context.HTMLContext(cfg, ms, webserv, rdata)
        if cachestore:
            ctx.setvar(":_cachestore", cachestore)
        if options.prerun:
            runLimited(*(options.prerun, runrend, rend, ctx))
        op(cnt, runrend, rend, ctx)
    else:
        if options.prerun:
            runLimited(*(options.prerun, runwsgi, env, app))
        op(cnt, runwsgi, env, app)
コード例 #10
0
ファイル: dwiki-scgi.py プロジェクト: siebenmann/dwiki
def main(args):
    # Parse and validate command line options.
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) != 1:
        usage()
    if options.lockfile:
        try:
            fd = os.open(options.lockfile, os.O_RDONLY)
        except EnvironmentError as e:
            die("Could not open lockfile: " + str(e))
        try:
            fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
        except EnvironmentError:
            # All failures are assumed to be 'cannot lock,
            # someone else is already there', and we die.
            sys.exit(0)
            # Note that is important that we never close 'fd';
            # locks die on close.

            # ... I wish there was a better way.
    x = [x for x in [options.sockfile, options.port, options.systemd] if x]
    if len(x) > 1:
        die("can only use one of -s, -p, or --systemd-socket")
    elif len(x) == 0:
        die("must supply one of -s, -p, or --systemd-socket")
    elif options.perms and not options.sockfile:
        die("-P requires -s")

    if options.systemd:
        lsocks = sockact.sd_listen_sockets()
        if not lsocks:
            die("--systemd-socket given but no socket(s) found")
        elif len(lsocks) > 1:
            die("sadly I cannot listen on multiple sockets yet, passed %d sockets" % len(lsocks))
        saddr = lsocks[0]
    elif options.sockfile:
        saddr = options.sockfile
        # Apparently required by Unix? Sigh.
        try:
            st = os.stat(options.sockfile)
            if stat.S_ISSOCK(st.st_mode):
                os.unlink(options.sockfile)
        except EnvironmentError:
            pass
    elif options.port:
        saddr = (options.addr, options.port)
    if options.perms:
        try:
            options.perms = int(options.perms, 0)
        except ValueError:
            die("cannot convert permissions '%s' to integer" % options.perms)

    if options.idletimeout:
        options.idletimeout *= 60
    if options.workertimeout:
        options.workertimeout *= 60

        # Load up the configuration from the single argument, and then
        # create the dependant services and stuff.
    procfunc, _ = dwconfig.materialize(args[0], options, "scgi-%s" % options.servtype)

    # If we have been asked to do timings, overwrite the WSGI process
    # function with the null WSGI app.
    if options.nullapp:
        procfunc = NullApp

        # Create the function that will tell the server when it should
        # stop.
    s_time = time.time()

    def stopNow():
        try:
            if options.stopfile and s_time < os.path.getmtime(options.stopfile):
                return True
        except EnvironmentError:
            pass
        if options.minlifetime:
            r_time = time.time() - s_time
            if (options.minlifetime * 60) > r_time:
                return False
        if options.minloadavg:
            cla = get_load()
            if cla and options.minloadavg > max(cla):
                return True
        return False
        # To make our shutdown more orderly, remove the socket file
        # when we are shutting down so that new connections can't be
        # made.

    def stopNow2():
        r = stopNow()
        if r and options.sockfile:
            try:
                os.unlink(options.sockfile)
            except EnvironmentError:
                pass
        return r

    sfunc = None
    if options.stopfile or options.minloadavg:
        sfunc = stopNow2

        # Generate the SCGI server, and then serve it out.
    if options.servtype == "prefork":
        builder = wsgi.scgipf.gen_server
    else:
        builder = wsgi.scgiserv.gen_server
    scgi = builder(saddr, procfunc, sfunc, options)

    try:
        if options.verbose:
            sys.stderr.write("[%s] [note] dwiki-scgi starting\n" % timestamp())
        scgi.serve_forever()
    except KeyboardInterrupt:
        pass
    if options.verbose:
        sys.stderr.write("[%s] [note] dwiki-scgi stopping\n" % timestamp())
コード例 #11
0
ファイル: dwiki-scgi.py プロジェクト: samveen/dwiki
def main(args):
    # Parse and validate command line options.
    parser = setup_options()
    (options, args) = parser.parse_args(args)
    if len(args) != 1:
        usage()
    if options.lockfile:
        try:
            fd = os.open(options.lockfile, os.O_RDONLY)
        except EnvironmentError as e:
            die("Could not open lockfile: " + str(e))
        try:
            fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
        except EnvironmentError:
            # All failures are assumed to be 'cannot lock,
            # someone else is already there', and we die.
            sys.exit(0)
        # Note that is important that we never close 'fd';
        # locks die on close.

    # ... I wish there was a better way.
    x = [x for x in [options.sockfile, options.port, options.systemd] if x]
    if len(x) > 1:
        die("can only use one of -s, -p, or --systemd-socket")
    elif len(x) == 0:
        die("must supply one of -s, -p, or --systemd-socket")
    elif options.perms and not options.sockfile:
        die("-P requires -s")

    if options.systemd:
        lsocks = sockact.sd_listen_sockets()
        if not lsocks:
            die("--systemd-socket given but no socket(s) found")
        elif len(lsocks) > 1:
            die("sadly I cannot listen on multiple sockets yet, passed %d sockets"
                % len(lsocks))
        saddr = lsocks[0]
    elif options.sockfile:
        saddr = options.sockfile
        # Apparently required by Unix? Sigh.
        try:
            st = os.stat(options.sockfile)
            if stat.S_ISSOCK(st.st_mode):
                os.unlink(options.sockfile)
        except EnvironmentError:
            pass
    elif options.port:
        saddr = (options.addr, options.port)
    if options.perms:
        try:
            options.perms = int(options.perms, 0)
        except ValueError:
            die("cannot convert permissions '%s' to integer" % options.perms)

    if options.idletimeout:
        options.idletimeout *= 60
    if options.workertimeout:
        options.workertimeout *= 60

    # Load up the configuration from the single argument, and then
    # create the dependant services and stuff.
    procfunc, _ = dwconfig.materialize(args[0], options,
                                       "scgi-%s" % options.servtype)

    # If we have been asked to do timings, overwrite the WSGI process
    # function with the null WSGI app.
    if options.nullapp:
        procfunc = NullApp

    # Create the function that will tell the server when it should
    # stop.
    s_time = time.time()

    def stopNow():
        try:
            if options.stopfile and \
               s_time < os.path.getmtime(options.stopfile):
                return True
        except EnvironmentError:
            pass
        if options.minlifetime:
            r_time = time.time() - s_time
            if (options.minlifetime * 60) > r_time:
                return False
        if options.minloadavg:
            cla = get_load()
            if cla and options.minloadavg > max(cla):
                return True
        return False

    # To make our shutdown more orderly, remove the socket file
    # when we are shutting down so that new connections can't be
    # made.
    def stopNow2():
        r = stopNow()
        if r and options.sockfile:
            try:
                os.unlink(options.sockfile)
            except EnvironmentError:
                pass
        return r

    sfunc = None
    if options.stopfile or options.minloadavg:
        sfunc = stopNow2

    # Generate the SCGI server, and then serve it out.
    if options.servtype == "prefork":
        builder = wsgi.scgipf.gen_server
    else:
        builder = wsgi.scgiserv.gen_server
    scgi = builder(saddr, procfunc, sfunc, options)

    try:
        if options.verbose:
            sys.stderr.write("[%s] [note] dwiki-scgi starting\n" % timestamp())
        scgi.serve_forever()
    except KeyboardInterrupt:
        pass
    if options.verbose:
        sys.stderr.write("[%s] [note] dwiki-scgi stopping\n" % timestamp())