# Path: scripts/pkgs/constants.py
# PREFIX = os.path.join(SW, 'sw')
# 
# Path: scripts/pkgs/utils.py
# class ModifiedEnv(object):
# 
#     def __init__(self, **kwargs):
#         self.mods = kwargs
# 
#     def apply(self, mods):
#         for k, val in mods.iteritems():
#             if val:
#                 worker_env[k] = val
#             else:
#                 worker_env.pop(k, None)
# 
#     def __enter__(self):
#         self.orig = {k: worker_env.get(k) for k in self.mods}
#         self.apply(self.mods)
# 
#     def __exit__(self, *args):
#         self.apply(self.orig)
# 
# def python_build(extra_args=()):
#     if isinstance(extra_args, type('')):
#         extra_args = split(extra_args)
#     run(PYTHON, 'setup.py', 'install', '--root', build_dir(), *extra_args, library_path=True)
# 
# def python_install():
#     ddir = 'python' if isosx else 'private' if iswindows else 'lib'
#     os.rename(os.path.join(build_dir(), os.path.basename(SW), os.path.basename(PREFIX), ddir), os.path.join(build_dir(), ddir))
#     shutil.rmtree(os.path.join(build_dir(), os.path.basename(SW)))


import os
from .constants import PREFIX
from .utils import ModifiedEnv, python_build, python_install
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)



def main(args):
    env = {}
    p = PREFIX.replace(os.sep, '/')
    env = dict(
        UNRAR_INCLUDE='{}/include'.format(p),
        UNRAR_LIBDIRS='{0}/lib'.format(p),
    )
    with ModifiedEnv(**env):
        python_build()
    python_install()


def install_name_change_predicate(x):
    return x.endswith('unrar.so')


def install_name_change(old_name, is_dep):
    bn = os.path.basename(old_name)
    if bn.startswith('libunrar'):

# Path: scripts/pkgs/constants.py
# PREFIX = os.path.join(SW, 'sw')
# 
# Path: scripts/pkgs/utils.py
# class ModifiedEnv(object):
# 
#     def __init__(self, **kwargs):
#         self.mods = kwargs
# 
#     def apply(self, mods):
#         for k, val in mods.iteritems():
#             if val:
#                 worker_env[k] = val
#             else:
#                 worker_env.pop(k, None)
# 
#     def __enter__(self):
#         self.orig = {k: worker_env.get(k) for k in self.mods}
#         self.apply(self.mods)
# 
#     def __exit__(self, *args):
#         self.apply(self.orig)
# 
# def python_build(extra_args=()):
#     if isinstance(extra_args, type('')):
#         extra_args = split(extra_args)
#     run(PYTHON, 'setup.py', 'install', '--root', build_dir(), *extra_args, library_path=True)
# 
# def python_install():
#     ddir = 'python' if isosx else 'private' if iswindows else 'lib'
#     os.rename(os.path.join(build_dir(), os.path.basename(SW), os.path.basename(PREFIX), ddir), os.path.join(build_dir(), ddir))
#     shutil.rmtree(os.path.join(build_dir(), os.path.basename(SW)))


# Path: scripts/pkgs/unrardll.py
import os
from .constants import PREFIX
from .utils import ModifiedEnv, python_build, python_install

#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)



def main(args):
    env = {}
    p = PREFIX.replace(os.sep, '/')
    env = dict(
        UNRAR_INCLUDE='{}/include'.format(p),
        UNRAR_LIBDIRS='{0}/lib'.format(p),
    )
    with ModifiedEnv(**env):
        python_build()
    python_install()


def install_name_change_predicate(x):
    return x.endswith('unrar.so')


def install_name_change(old_name, is_dep):
    bn = os.path.basename(old_name)
    if bn.startswith('libunrar'):

        return os.path.join(PREFIX, 'lib', bn)