Esempio n. 1
0
	def blog_post_edit(self, req, arg, v):
		f=v["form"]=self.t.form("post_edit",arg,so2dict(v["post"]))
		if f.valid:
			v["post"].set(**f.collect())
		req.write(self.t.render("post_edit", v))

	def blog_post_commentadd(self, req, arg, v):
		v["comment"] = comment(post=v['post'])
		return "blog_comment_edit"

	# Ensure that all blog_comment_* handlers have a valid 'comment' argument
	def blog_comment(self, req, arg, v):
		if not "comment" in v:
			v['comment'] = comment.get(arg.int('comment'))
			v['post']=v['comment'].post

	def blog_comment_edit(self, req, arg, v):
		f=v["form"]=self.t.form("comment_edit",arg,so2dict(v["comment"]))
		if f.valid:
			v["comment"].set(**f.collect())
			return "blog_post_view"
		req.write(self.t.render("comment_edit", v))


if __name__=='__main__':
	initdb()
	b=BlogApp()
	qweb.qweb_wsgi_autorun(b,threaded=0)

Esempio n. 2
0
def main():
    parser = optparse.OptionParser()
    parser.add_option("-p", "--port", dest="port", default="8022", help="Set the TCP port (default: 8022)")
    parser.add_option(
        "-c", "--command", dest="cmd", default=None, help="set the command (default: /bin/login or ssh localhost)"
    )
    parser.add_option(
        "-l", "--log", action="store_true", dest="log", default=0, help="log requests to stderr (default: quiet mode)"
    )
    parser.add_option(
        "-d", "--daemon", action="store_true", dest="daemon", default=0, help="run as daemon in the background"
    )
    parser.add_option(
        "-P",
        "--pidfile",
        dest="pidfile",
        default="/var/run/ajaxterm.pid",
        help="set the pidfile (default: /var/run/ajaxterm.pid)",
    )
    parser.add_option(
        "-i", "--index", dest="index_file", default="ajaxterm.html", help="default index file (default: ajaxterm.html)"
    )
    parser.add_option("-u", "--uid", dest="uid", help="Set the daemon's user id")
    parser.add_option("-x", "--xenid", dest="domid", help="ID of the Xen domain to connect to")
    parser.add_option("-n", "--domname", dest="domname", help="Name of Xen domain to connect to")
    parser.add_option("-b", "--bind", dest="addr", help="IP or address to bind to")
    parser.add_option("-a", "--all", action="store_true", dest="all", default=0, help="starts for all Xen domains")

    (o, a) = parser.parse_args()

    import socket

    if o.addr:
        myname = o.addr
    else:
        myname = socket.gethostname()

    if o.all:
        import subprocess, re

        output, error = subprocess.Popen(["xm", "list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

        port = int(o.port)
        lines = output.split("\n")
        for line in lines[2:-1]:
            xen_domain = re.sub(" +", " ", line).split(" ")[0]
            print xen_domain

            pid = os.fork()
            if pid == 0:
                # os.setsid() ?
                os.setpgrp()
                nullin = file("/dev/null", "r")
                nullout = file("/dev/null", "w")
                os.dup2(nullin.fileno(), sys.stdin.fileno())
                os.dup2(nullout.fileno(), sys.stdout.fileno())
                os.dup2(nullout.fileno(), sys.stderr.fileno())
                if os.getuid() == 0 and o.uid:
                    try:
                        os.setuid(int(o.uid))
                    except:
                        os.setuid(pwd.getpwnam(o.uid).pw_uid)

                at = AjaxTerm(o.cmd, o.index_file, xen_domain)
                qweb.qweb_wsgi_autorun(at, ip=myname, port=port, threaded=0, log=o.log, callback_ready=None)
                at.multi.die()

            else:
                try:
                    file(o.pidfile, "w+").write(str(pid) + "\n")
                except:
                    pass
                print "%s,%s" % (xen_domain, str(port))
                print "AjaxTerm for %s at http://%s:%s/ pid: %d" % (xen_domain, myname, port, pid)

            port += 1

    else:
        if o.daemon:
            pid = os.fork()
            if pid == 0:
                # os.setsid() ?
                os.setpgrp()
                nullin = file("/dev/null", "r")
                nullout = file("/dev/null", "w")
                os.dup2(nullin.fileno(), sys.stdin.fileno())
                os.dup2(nullout.fileno(), sys.stdout.fileno())
                os.dup2(nullout.fileno(), sys.stderr.fileno())
                if os.getuid() == 0 and o.uid:
                    try:
                        os.setuid(int(o.uid))
                    except:
                        os.setuid(pwd.getpwnam(o.uid).pw_uid)
            else:
                try:
                    file(o.pidfile, "w+").write(str(pid) + "\n")
                except:
                    pass
                print "AjaxTerm at http://%s:%s/ pid: %d" % (myname, o.port, pid)
                sys.exit(0)
        else:
            print "AjaxTerm at http://%s:%s/" % (myname, o.port)

        print "starting ajaxterm"
        at = AjaxTerm(o.cmd, o.index_file, o.domname)

        print "starting web server"
        qweb.qweb_wsgi_autorun(at, ip=myname, port=int(o.port), threaded=0, log=o.log, callback_ready=None)

        print "Successfully started AjaxTerm server"
        at.multi.die()