Exemplo n.º 1
0
def exposed_astor_roundtrip_parser_functions():
	'''
	Shove the feed-functions through the astor "round-trip"
	facility.

	Mostly, this homogenizes the indentation, and reformats the function.
	'''

	with db.session_context() as sess:
		res = sess.query(db.RssFeedEntry) \
			.all()

		for row in res:
			func = row.get_func()
			_ast = row._get_ast()
			src = astor.to_source(_ast, indent_with="	", pretty_source=better_pretty_source)

			if src.strip() != row.func.strip():
				try:
					rfdb.str_to_function(src, "testing_compile")
					print("Compiled OK")
					row.func = src
				except Exception:
					print("Compilation failed?")
		sess.commit()
Exemplo n.º 2
0
def update_function_text(feedrow, new_func):
    current = feedrow.func.strip()
    new_func = new_func.strip()
    print("New function:", new_func)
    print("Current function:", current)

    if current == new_func:
        return {
            'error': True,
            'message': "Function has not changed? Nothing to do!",
            'reload': False,
        }

    try:
        rfdb.str_to_function(new_func, "testing_compile")
    except Exception:
        resp = '<div class="center-block text-center"><h4>New function failed to compile!</h4></div>'
        resp += "<pre><code>" + traceback.format_exc() + "</code></pre>"
        return {
            'error': True,
            'message': resp,
            'reload': False,
        }

    feedrow.func = new_func
    feedrow.last_changed = datetime.datetime.now()

    return {
        'error': False,
        'message': "Function updated successfully!",
        'reload': True,
    }