#!/usr/bin/python
import errno, os, shutil, sys

path = set()

class Stop(Exception):
    pass

class SysPath(tuple):
    def __setitem__(self, i, v):
        path.update(v)
        raise Stop

sys_path = sys.path
try:
    sys.path = SysPath(sys_path)
    for x in sys.argv[2:]:
        x = os.path.join("bin", x)
        try:
            exec(compile(open(x, "rb").read(), x, 'exec'))
        except Stop:
            pass
finally:
    sys.path = sys_path

dest = sys.argv[1]
for x in path:
    x = os.path.relpath(x)
    d = os.path.join(dest, x)
    try:
        os.mkdir(os.path.basename(x))
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
    if os.path.isdir(x):
        shutil.copytree(x, d, True)
    else:
        shutil.copy2(x, d)
