示例#1
0
    def test_simple(self):
        bscript = """\
from bento.commands import hooks

PRE = False
POST = False

@hooks.pre_configure
def pre_configure(ctx):
    global PRE
    PRE = True

@hooks.post_configure
def post_configure(ctx):
    global POST
    POST = True
"""

        bento = """\
Name: foo
Version: 1.0

HookFile: bscript
"""

        create_fake_package_from_bento_infos(self.top_node, {"bento.info": bento},
                {"bscript": bscript})

        conf, configure = prepare_configure(self.top_node, bento,
                ConfigureContext)
        bscript = self.top_node.search("bscript")
        m = create_hook_module(bscript.abspath())
        self.assertEqual(len(find_pre_hooks([m], "configure")), 1)
        self.assertEqual(len(find_post_hooks([m], "configure")), 1)
示例#2
0
    def test_simple(self):
        bscript = """\
from bento.commands import hooks

PRE = False
POST = False

@hooks.pre_configure
def pre_configure(ctx):
    global PRE
    PRE = True

@hooks.post_configure
def post_configure(ctx):
    global POST
    POST = True
"""

        bento = """\
Name: foo
Version: 1.0

HookFile: bscript
"""

        create_fake_package_from_bento_infos(self.top_node,
                                             {"bento.info": bento},
                                             {"bscript": bscript})

        conf, configure = prepare_configure(self.top_node, bento,
                                            ConfigureContext)
        bscript = self.top_node.search("bscript")
        m = create_hook_module(bscript.abspath())
        self.assertEqual(len(find_pre_hooks([m], "configure")), 1)
        self.assertEqual(len(find_post_hooks([m], "configure")), 1)
示例#3
0
    def test_hook(self):
        root = self.root
        top_node = self.top_node

        bento_info = """\
Name: foo

HookFile:
    bar/bscript

Recurse:
    bar
"""
        bento_info2 = """\
Library:
    Packages: fubar
"""

        bscript = """\
from bento.commands import hooks
@hooks.pre_configure
def configure(ctx):
    packages = ctx.local_pkg.packages
    ctx.local_node.make_node("test").write(str(packages))
"""
        bentos = {
            "bento.info": bento_info,
            os.path.join("bar", "bento.info"): bento_info2
        }
        bscripts = {os.path.join("bar", "bscript"): bscript}
        create_fake_package_from_bento_infos(top_node, bentos, bscripts)

        conf, configure = prepare_configure(self.run_node, bento_info,
                                            ConfigureYakuContext)
        try:
            hook = top_node.search("bar/bscript")
            m = create_hook_module(hook.abspath())
            for hook in find_pre_hooks([m], "configure"):
                conf.pre_recurse(root.find_dir(hook.local_dir))
                try:
                    hook(conf)
                finally:
                    conf.post_recurse()

            test = top_node.search("bar/test")
            if test:
                self.assertEqual(test.read(), "['fubar']")
            else:
                self.fail("test dummy not found")
        finally:
            configure.finish(conf)
            conf.finish()
示例#4
0
def set_main(pkg, top_node, build_node):
    modules = []
    hook_files = pkg.hook_files
    for name, spkg in pkg.subpackages.items():
        hook_files.extend([os.path.join(spkg.rdir, h) for h in spkg.hook_files])

    # TODO: find doublons
    for f in hook_files:
        hook_node = top_node.make_node(f)
        if hook_node is None or not os.path.exists(hook_node.abspath()):
            raise ValueError("Hook file %s not found" % f)
        modules.append(create_hook_module(hook_node.abspath()))
    return modules
示例#5
0
def set_main(pkg, top_node, build_node):
    modules = []
    hook_files = pkg.hook_files
    for name, spkg in pkg.subpackages.items():
        hook_files.extend([os.path.join(spkg.rdir, h) for h in spkg.hook_files])

    # TODO: find doublons
    for f in hook_files:
        hook_node = top_node.make_node(f)
        if hook_node is None or not os.path.exists(hook_node.abspath()):
            raise ValueError("Hook file %s not found" % f)
        modules.append(create_hook_module(hook_node.abspath()))
    return modules
示例#6
0
    def test_hook(self):
        root = self.root
        top_node = self.top_node

        bento_info = """\
Name: foo

HookFile:
    bar/bscript

Recurse:
    bar
"""
        bento_info2 = """\
Library:
    Packages: fubar
"""

        bscript = """\
from bento.commands import hooks
@hooks.pre_configure
def configure(ctx):
    packages = ctx.local_pkg.packages
    ctx.local_node.make_node("test").write(str(packages))
"""
        bentos = {"bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2}
        bscripts = {os.path.join("bar", "bscript"): bscript}
        create_fake_package_from_bento_infos(top_node, bentos, bscripts)

        conf, configure = prepare_configure(self.run_node, bento_info, ConfigureYakuContext)
        try:
            hook = top_node.search("bar/bscript")
            m = create_hook_module(hook.abspath())
            for hook in find_pre_hooks([m], "configure"):
                conf.pre_recurse(root.find_dir(hook.local_dir))
                try:
                    hook(conf)
                finally:
                    conf.post_recurse()

            test = top_node.search("bar/test")
            if test:
                self.failUnlessEqual(test.read(), "['fubar']")
            else:
                self.fail("test dummy not found")
        finally:
            configure.finish(conf)
            conf.finish()
示例#7
0
def set_main(top_node, build_node, pkg):
    # Some commands work without a bento description file (convert, help)
    # FIXME: this should not be called here then - clearly separate commands
    # which require bento.info from the ones who do not
    n = top_node.find_node(BENTO_SCRIPT)
    if n is None:
        return []

    modules = []
    hook_files = pkg.hook_files
    for name, spkg in pkg.subpackages.items():
        hook_files.extend([os.path.join(spkg.rdir, h) for h in spkg.hook_files])
    # TODO: find doublons
    for f in hook_files:
        hook_node = top_node.make_node(f)
        if hook_node is None or not os.path.exists(hook_node.abspath()):
            raise ValueError("Hook file %s not found" % f)
        modules.append(create_hook_module(hook_node.abspath()))
    return modules
示例#8
0
文件: bentomaker.py 项目: dagss/Bento
def set_main():
    # Some commands work without a bento description file (convert, help)
    if not os.path.exists(BENTO_SCRIPT):
        return []

    pkg_cache = CachedPackage()
    try:
        pkg = pkg_cache.get_package(BENTO_SCRIPT)
    finally:
        pkg_cache.close()
    #create_package_description(BENTO_SCRIPT)

    modules = []
    for f in pkg.hook_files:
        main_file = os.path.abspath(f)
        if not os.path.exists(main_file):
            raise ValueError("Hook file %s not found" % main_file)
        modules.append(create_hook_module(f))
    return modules