# Path: bento/commands/utils.py
# def has_compiled_code(pkg):
#     has_compiled_code = len(pkg.extensions) > 0 or len(pkg.compiled_libraries) > 0
#     if not has_compiled_code:
#         if pkg.subpackages:
#             for v in pkg.subpackages.values():
#                 if len(v.extensions) > 0 or len(v.compiled_libraries) > 0:
#                     has_compiled_code = True
#                     break
#     return has_compiled_code
# 
# def has_cython_code(pkg):
#     for extension in pkg.extensions.values():
#         for source in extension.sources:
#             if source.endswith("pyx"):
#                 return True
# 
#     if pkg.subpackages:
#         for spkg in pkg.subpackages.values():
#             for extension in spkg.extensions.values():
#                 for source in extension.sources:
#                     if source.endswith("pyx"):
#                         return True
#     return False
# 
# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]
# 
# Path: bento/commands/options.py
# class IndentedHelpFormatter(optparse.IndentedHelpFormatter):
# class OptionsContext(object):
#     def format_usage(self, usage):
#     def from_command(cls, cmd):
#     def __init__(self, usage=None):
#     def setup(self, package_options):
#     def add_option(self, option, group=None):
#     def has_group(self, group):
#     def add_group(self, name, title):


import os
import sys
import logging
import os.path as op
import bento
import waflib
from bento.commands.utils \
    import \
        has_compiled_code, has_cython_code
from bento.backends.core \
    import \
        AbstractBackend
from bento.errors \
    import \
        UsageException
from bento._config \
     import \
        SITEDIR
from bento.utils.utils \
    import \
        extract_exception
from waflib.Context \
    import \
        create_context
from waflib.Options \
    import \
        OptionsContext
from waflib import Options
from waflib import Context
from waflib import Logs
from waflib import Build
from waflib import Utils
from bento.core.node_package \
    import \
        translate_name
from bento.commands.options \
    import \
        Option
from bento.commands.command_contexts \
    import \
        ConfigureContext, BuildContext
    from six.moves import cStringIO
    if not (os.path.isabs(run_path) and os.path.isabs(source_path) and os.path.isabs(build_path)):
        raise ValueError("All paths must be absolute !")
    tooldir = os.path.join(WAFDIR, "Tools")

    sys.path.insert(0, tooldir)
    cwd = os.getcwd()

    if __USE_NO_OUTPUT_LOGGING is True:
        _init_log_no_output()
    else:
        Logs.init_log()

    class FakeModule(object):
        pass
    Context.g_module = FakeModule
    Context.g_module.root_path = os.path.abspath(__file__)
    Context.g_module.top = source_path
    Context.g_module.out = build_path

    Context.top_dir = source_path
    Context.run_dir = run_path
    Context.out_dir = build_path
    Context.waf_dir = WAF_TOP
    Context.launch_dir = run_path

def register_options(global_context):
    opt = Option("--use-distutils-flags", help="Use distutils compilation flags",
                 action="store_true", default=False)
    global_context.add_option("configure", opt)


# Path: bento/commands/utils.py
# def has_compiled_code(pkg):
#     has_compiled_code = len(pkg.extensions) > 0 or len(pkg.compiled_libraries) > 0
#     if not has_compiled_code:
#         if pkg.subpackages:
#             for v in pkg.subpackages.values():
#                 if len(v.extensions) > 0 or len(v.compiled_libraries) > 0:
#                     has_compiled_code = True
#                     break
#     return has_compiled_code
# 
# def has_cython_code(pkg):
#     for extension in pkg.extensions.values():
#         for source in extension.sources:
#             if source.endswith("pyx"):
#                 return True
# 
#     if pkg.subpackages:
#         for spkg in pkg.subpackages.values():
#             for extension in spkg.extensions.values():
#                 for source in extension.sources:
#                     if source.endswith("pyx"):
#                         return True
#     return False
# 
# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]
# 
# Path: bento/commands/options.py
# class IndentedHelpFormatter(optparse.IndentedHelpFormatter):
# class OptionsContext(object):
#     def format_usage(self, usage):
#     def from_command(cls, cmd):
#     def __init__(self, usage=None):
#     def setup(self, package_options):
#     def add_option(self, option, group=None):
#     def has_group(self, group):
#     def add_group(self, name, title):


# Path: bento/backends/waf_backend.py
import os
import sys
import logging
import os.path as op
import bento
import waflib
from bento.commands.utils \
    import \
        has_compiled_code, has_cython_code
from bento.backends.core \
    import \
        AbstractBackend
from bento.errors \
    import \
        UsageException
from bento._config \
     import \
        SITEDIR
from bento.utils.utils \
    import \
        extract_exception
from waflib.Context \
    import \
        create_context
from waflib.Options \
    import \
        OptionsContext
from waflib import Options
from waflib import Context
from waflib import Logs
from waflib import Build
from waflib import Utils
from bento.core.node_package \
    import \
        translate_name
from bento.commands.options \
    import \
        Option
from bento.commands.command_contexts \
    import \
        ConfigureContext, BuildContext
    from six.moves import cStringIO

    if not (os.path.isabs(run_path) and os.path.isabs(source_path) and os.path.isabs(build_path)):
        raise ValueError("All paths must be absolute !")
    tooldir = os.path.join(WAFDIR, "Tools")

    sys.path.insert(0, tooldir)
    cwd = os.getcwd()

    if __USE_NO_OUTPUT_LOGGING is True:
        _init_log_no_output()
    else:
        Logs.init_log()

    class FakeModule(object):
        pass
    Context.g_module = FakeModule
    Context.g_module.root_path = os.path.abspath(__file__)
    Context.g_module.top = source_path
    Context.g_module.out = build_path

    Context.top_dir = source_path
    Context.run_dir = run_path
    Context.out_dir = build_path
    Context.waf_dir = WAF_TOP
    Context.launch_dir = run_path

def register_options(global_context):
    opt = Option("--use-distutils-flags", help="Use distutils compilation flags",
                 action="store_true", default=False)
    global_context.add_option("configure", opt)


    opt = Option("-p", "--progress", help="Use progress bar", action="store_true", dest="progress_bar")