recipes/__init__.py
author David Douard <david.douard@logilab.fr>
Thu, 13 Nov 2014 14:55:11 +0100
changeset 1752 31c34cf9f19f
parent 1740 f3137466457a
child 1613 8297da522f82
permissions -rw-r--r--
[testutils] small improvements

#
from os import listdir
from os.path import join, dirname

def create_recipes(cnx):
    recipes = []
    rdir = dirname(__file__)
    for recipe in listdir(rdir):
        if recipe.endswith('.py') and not recipe.startswith('_'):
            rname = recipe[:-3]
            try:
                script = open(join(rdir, recipe)).read()
                r = cnx.create_entity('Recipe',
                                      name=rname.decode('utf-8'),
                                      script=script.decode('utf-8'))
                recipes.append(r)
            except Exception as exc:
                cnx.warning('Failed to create Recipe %s (%s)'%(rname, exc))
    return recipes