# Path: revolver/core.py
# def run(*args, **kwargs):
#     if not env.sudo_forced:
#         return _run(*args, **kwargs)
# 
#     return sudo(*args, **kwargs)
# 
# Path: revolver/contextmanager.py
# def sudo(username=None, login=False):
# def unpatched_state():
# 
# Path: revolver/directory.py
# def temp_local():
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def create(path, recursive=False, mode=None, owner=None, group=None):
# 
# Path: revolver/file.py
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def touch(location, mode=None, owner=None, group=None):
# def copy(source, destination, force=True, mode=None, owner=None, group=None):
# 
# Path: revolver/package.py
# def is_installed(name):
# def install_ppa(name):
# 
# Path: revolver/tool/php_build.py
# def install():
# def ensure():
# def _ensure_autoload(filename):
# 
# Path: revolver/tool/php_phpenv.py
# def install():
# def ensure():
# def _ensure_autoload(filename):


from revolver.core import run
from revolver import contextmanager as ctx
from revolver import directory as dir
from revolver import file, package
from revolver.tool import php_build, php_phpenv

    # We only support this two configuration options! Why?
    # - Xdebug is already integrated into php-build
    # - FPM is a very common flag
    #
    # But if you want to configure php even further? Own definition files!
    # See https://github.com/CHH/php-build/blob/master/man/php-build.1.ronn#L54
    fpm = (fpm and configure("--enable-fpm")) or "true"
    xdebug = (xdebug and "true") or 'export PHP_BUILD_XDEBUG_ENABLE="off"'

    with ctx.prefix(pear):
        with ctx.prefix(xdebug):
            with ctx.prefix(fpm):
                run("php-build %s %s" % (version, prefix))

    # Some executables (like php-fpm) aren't available through phpenv without
    # this symlinks
    with ctx.cd(prefix):
        run('find sbin/ -type f -exec ln -sf "$(pwd)/{}" -t "$(pwd)/bin" \;')


def _install_apc():
    installed = run("pecl list | grep -i apc; true")
    if installed:
        return

    run("yes '' | pecl install apc")

    bin_path = run("phpenv which php")
    conf_path = bin_path.replace("/bin/php", "/etc/conf.d")

# Path: revolver/core.py
# def run(*args, **kwargs):
#     if not env.sudo_forced:
#         return _run(*args, **kwargs)
# 
#     return sudo(*args, **kwargs)
# 
# Path: revolver/contextmanager.py
# def sudo(username=None, login=False):
# def unpatched_state():
# 
# Path: revolver/directory.py
# def temp_local():
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def create(path, recursive=False, mode=None, owner=None, group=None):
# 
# Path: revolver/file.py
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def touch(location, mode=None, owner=None, group=None):
# def copy(source, destination, force=True, mode=None, owner=None, group=None):
# 
# Path: revolver/package.py
# def is_installed(name):
# def install_ppa(name):
# 
# Path: revolver/tool/php_build.py
# def install():
# def ensure():
# def _ensure_autoload(filename):
# 
# Path: revolver/tool/php_phpenv.py
# def install():
# def ensure():
# def _ensure_autoload(filename):


# Path: revolver/tool/php.py
from revolver.core import run
from revolver import contextmanager as ctx
from revolver import directory as dir
from revolver import file, package
from revolver.tool import php_build, php_phpenv


    # We only support this two configuration options! Why?
    # - Xdebug is already integrated into php-build
    # - FPM is a very common flag
    #
    # But if you want to configure php even further? Own definition files!
    # See https://github.com/CHH/php-build/blob/master/man/php-build.1.ronn#L54
    fpm = (fpm and configure("--enable-fpm")) or "true"
    xdebug = (xdebug and "true") or 'export PHP_BUILD_XDEBUG_ENABLE="off"'

    with ctx.prefix(pear):
        with ctx.prefix(xdebug):
            with ctx.prefix(fpm):
                run("php-build %s %s" % (version, prefix))

    # Some executables (like php-fpm) aren't available through phpenv without
    # this symlinks
    with ctx.cd(prefix):
        run('find sbin/ -type f -exec ln -sf "$(pwd)/{}" -t "$(pwd)/bin" \;')


def _install_apc():
    installed = run("pecl list | grep -i apc; true")
    if installed:
        return

    run("yes '' | pecl install apc")

    bin_path = run("phpenv which php")
    conf_path = bin_path.replace("/bin/php", "/etc/conf.d")

    file.write(conf_path + "/apc.ini", "extension=apc.so")