def main(argv=None): if hasattr(os, "getuid"): if os.getuid() == 0: pprint("RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N") ans = raw_input() if not ans.lower() in ["y", "yes"]: raise bento.errors.UsageException("bentomaker execution canceld (not using bentomaker with admin privileges)") if argv is None: argv = sys.argv[1:] options_context = create_global_options_context() popts = parse_global_options(options_context, argv) cmd_name = popts.cmd_name if popts.show_version: print(bento.__version__) return if popts.show_full_version: print(bento.__version__ + "git" + bento.__git_revision__) return # FIXME: top_node vs srcnode source_root = os.path.join(os.getcwd(), os.path.dirname(popts.bento_info)) build_root = os.path.join(os.getcwd(), popts.build_directory) # FIXME: create_root_with_source_tree should return source node and build # node so that we don't have to find them and take the risk of # inconsistency root = bento.core.node.create_root_with_source_tree(source_root, build_root) run_node = root.find_node(os.getcwd()) top_node = root.find_node(source_root) build_node = root.find_node(build_root) if run_node != top_node and run_node.is_src(): raise bento.errors.UsageException("You cannot execute bentomaker in a subdirectory of the source tree !") if run_node != build_node and run_node.is_bld(): raise bento.errors.UsageException("You cannot execute bentomaker in a subdirectory of the build tree !") global_context = GlobalContext(build_node.make_node(CMD_DATA_DUMP), CommandRegistry(), ContextRegistry(), OptionsRegistry(), CommandScheduler()) global_context.register_options_context_without_command("", options_context) if not popts.disable_autoconfigure: global_context.set_before("build", "configure") global_context.set_before("build_egg", "build") global_context.set_before("build_wininst", "build") global_context.set_before("install", "build") if cmd_name and cmd_name not in ["convert"]: return _wrapped_main(global_context, popts, run_node, top_node, build_node) else: # XXX: is cached package necessary here ? cached_package = None register_stuff(global_context) for cmd_name in global_context.command_names(): register_options(global_context, cmd_name) return _main(global_context, cached_package, popts, run_node, top_node, build_node)
def global_context_factory(package_options): # FIXME: factor this out with the similar code in bentomakerlib global_context = GlobalContext(None) global_context.register_package_options(package_options) register_commands(global_context) register_command_contexts(global_context) for cmd_name in global_context.command_names(): cmd = global_context.retrieve_command(cmd_name) options_context = OptionsContext.from_command(cmd) if not global_context.is_options_context_registered(cmd_name): global_context.register_options_context(cmd_name, options_context) return global_context
def main(argv=None): if hasattr(os, "getuid"): if os.getuid() == 0: pprint( "RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N" ) ans = input() if not ans.lower() in ["y", "yes"]: raise bento.errors.UsageException( "bentomaker execution canceld (not using bentomaker with admin privileges)" ) if argv is None: argv = sys.argv[1:] options_context = create_global_options_context() popts = parse_global_options(options_context, argv) cmd_name = popts.cmd_name if popts.show_version: print(bento.__version__) return if popts.show_full_version: print(bento.__version__ + "git" + bento.__git_revision__) return source_root = os.path.join(os.getcwd(), os.path.dirname(popts.bento_info)) build_root = os.path.join(os.getcwd(), popts.build_directory) top_node, build_node, run_node = bento.core.node.create_base_nodes( source_root, build_root) if run_node != top_node and run_node.is_src(): raise bento.errors.UsageException( "You cannot execute bentomaker in a subdirectory of the source tree !" ) if run_node != build_node and run_node.is_bld(): raise bento.errors.UsageException( "You cannot execute bentomaker in a subdirectory of the build tree !" ) global_context = GlobalContext(build_node.make_node(CMD_DATA_DUMP), CommandRegistry(), ContextRegistry(), OptionsRegistry(), CommandScheduler()) global_context.register_options_context_without_command( "", options_context) if not popts.disable_autoconfigure: global_context.set_before("build", "configure") global_context.set_before("build_egg", "build") global_context.set_before("build_wheel", "build") global_context.set_before("build_wininst", "build") global_context.set_before("install", "build") if cmd_name and cmd_name not in ["convert"]: return _wrapped_main(global_context, popts, run_node, top_node, build_node) else: # XXX: is cached package necessary here ? cached_package = None register_stuff(global_context) for cmd_name in global_context.command_names(): register_options(global_context, cmd_name) return _main(global_context, cached_package, popts, run_node, top_node, build_node)