#!/usr/bin/env python
"""
SETUP-EXAMPLES script for Package PLIB
Copyright (C) 2008 by Peter A. Donis

This script sets up symlinks in $PREFIX/bin to each of the
example programs that come with PLIB.
"""

import sys
import os
import glob
import compileall

binpath = os.path.split(__file__)[0]
sharepath = os.path.join(os.path.split(binpath)[0], 'share', 'plib', 'examples')

pyfiles = [filename for dirname in glob.glob(os.path.join(sharepath, '*'))
    for filename in glob.glob('%s/*.py' % dirname)]

print "Creating symlinks in", binpath, "to examples in", sharepath, "..."
for pyfile in pyfiles:
    linkfile = os.path.join(binpath, os.path.basename(pyfile))
    if os.path.exists(linkfile):
        os.remove(linkfile)
    os.symlink(pyfile, linkfile)

print "Byte-compiling examples..."
compileall.compile_dir(sharepath)

print "PLIB examples setup done!"
