Beispiel #1
0
def cleanup():
	"""logout testuser and cleanup"""
	from lib.chai import db
	db.begin()
	db.sql("""delete from session where user=%s""", userobj['name'])
	db.sql("""delete from user where name=%s""", userobj['name'])
	db.commit()
Beispiel #2
0
def handle_method():
    """pass control to a whitelisted method"""
    from lib.chai import req

    parts = req.params["_method"].split(".")
    module = ".".join(parts[:-1])
    method = parts[-1]

    # import the module
    __import__(module)

    from lib.chai import whitelisted

    if module in sys.modules:
        # check if the method is whitelisted
        if getattr(sys.modules[module], method) not in whitelisted:
            return {"error": "Method `%s` not allowed" % method}

            # execute
        if req.method == "POST":
            db.begin()

        t = getattr(sys.modules[module], method)(**req.params)

        if req.method == "POST":
            db.commit()

        if type(t) in (str, unicode):
            t = {"message": t}

        return t or {"message": "no response"}
    else:
        return {"error": "Unable to load method"}
Beispiel #3
0
def handle_method():
    """pass control to a whitelisted method"""
    from lib.chai import req

    parts = req.params['_method'].split('.')
    module = '.'.join(parts[:-1])
    method = parts[-1]

    # import the module
    __import__(module)

    from lib.chai import whitelisted

    if module in sys.modules:
        # check if the method is whitelisted
        if getattr(sys.modules[module], method) not in whitelisted:
            return {"error": "Method `%s` not allowed" % method}

        # execute
        if req.method == 'POST':
            db.begin()

        t = getattr(sys.modules[module], method)(**req.params)

        if req.method == 'POST':
            db.commit()

        if type(t) in (str, unicode):
            t = {"message": t}

        return t or {"message": "no response"}
    else:
        return {"error": "Unable to load method"}
Beispiel #4
0
def publish():
    db.begin()

    nestedset.rebuild('page')
    toc.make()
    #pages.make()

    db.commit()
Beispiel #5
0
def publish():
	db.begin()
	
	nestedset.rebuild('page')
	toc.make()
	#pages.make()

	db.commit()
Beispiel #6
0
def main():
    """call action based on options"""
    import os, sys, conf
    (options, args) = getparser().parse_args()

    import lib.chai
    lib.chai.site = options.site or conf.default_site

    from lib.chai import db

    if options.newapp is not None:
        newapp()

    elif options.setup is not None:
        setup_db()

    elif options.update is not None:
        if options.update == 'all':
            sync_tables()
        else:
            from lib.chai import db
            db.get().sync_table(options.update)

    elif options.publish is not None:
        publish()

    elif options.adduser:
        from lib.chai import db, objstore
        db.begin()
        objstore.insert(type="user",
                        name=options.adduser[0],
                        password=options.adduser[1])
        db.commit()

    elif options.uwsgi is not None:
        from lib.chai.util import uwsgi_manager
        m = uwsgi_manager.manager('conf/uwsgi.xml')
        getattr(m, options.uwsgi)(1)

    elif options.replace is not None:
        from lib.chai.util import replacer
        # in code
        replacer.replace(conf.sites[lib.chai.site]['path'], options.replace[0], \
         options.replace[1], options.replace[2])

        # replace in framework
        replacer.replace('lib', options.replace[0], options.replace[1],
                         options.replace[2])

    elif options.concat is not None:
        concat()

    db.close()
Beispiel #7
0
def main():
	"""call action based on options"""
	import os, sys, conf
	(options, args) = getparser().parse_args()
	
	import lib.chai
	lib.chai.site = options.site or conf.default_site

	from lib.chai import db

	if options.newapp is not None:
		newapp()
	
	elif options.setup is not None:
		setup_db()

	elif options.update is not None:
		if options.update=='all':
			sync_tables()
		else:
			from lib.chai import db
			db.get().sync_table(options.update)
	
	elif options.publish is not None:
		publish()
			
	elif options.adduser:
		from lib.chai import db, objstore
		db.begin()
		objstore.insert(type="user", name=options.adduser[0], password=options.adduser[1])
		db.commit()
		
	elif options.uwsgi is not None:
		from lib.chai.util import uwsgi_manager
		m = uwsgi_manager.manager('conf/uwsgi.xml')
		getattr(m, options.uwsgi)(1)

	elif options.replace is not None:
		from lib.chai.util import replacer
		# in code
		replacer.replace(conf.sites[lib.chai.site]['path'], options.replace[0], \
			options.replace[1], options.replace[2])

		# replace in framework
		replacer.replace('lib', options.replace[0], options.replace[1], options.replace[2])

	elif options.concat is not None:
		concat()

	db.close()
Beispiel #8
0
def create_index():
	"""create index page"""
	from lib.chai import objstore, db
	
	content = '''
	<h1>[Default Index]</h1>
	<p>To edit this page:</p>
	<ol>
		<li>Login
		<li>Admin -> Edit
	</ol>
	'''
	db.begin()
	# index page
	objstore.insert(type="page", html=content, name="index", label=conf.app_name)
	db.commit()
	print "index created"
Beispiel #9
0
def create_index():
    """create index page"""
    from lib.chai import objstore, db

    content = '''
	<h1>[Default Index]</h1>
	<p>To edit this page:</p>
	<ol>
		<li>Login
		<li>Admin -> Edit
	</ol>
	'''
    db.begin()
    # index page
    objstore.insert(type="page",
                    html=content,
                    name="index",
                    label=conf.app_name)
    db.commit()
    print "index created"
Beispiel #10
0
 def setUp(self):
     import lib.chai
     lib.chai.blank()
     db.begin()
	def setUp(self):
		db.begin()
		import lib.chai
		lib.chai.blank()
Beispiel #12
0
 def setUp(self):
     db.begin()
Beispiel #13
0
 def setUp(self):
     db.begin()
Beispiel #14
0
	def setUp(self):
		db.begin()
		# clear existing (temp)
		db.sql("set foreign_key_checks = 0")
		db.sql("delete from page")
		db.sql("set foreign_key_checks = 1")