#!/usr/bin/python

# To use, you must first install Python, and some Python modules:
# a) Debian Linux (e.g. Ubuntu):
#    $ sudo aptitude install python-numpy python-scipy python-sympy \
#      python-matplotlib python-setuptools python-pyodbc
# b) Windows:
#    - Download and install Python from
#          http://www.python.org/
#      accepting all the defaults
#    - Download and install setuptools from
#          http://pypi.python.org/pypi/setuptools
#    - Add the following directories to the PATH environment variable
#      Start > Settings > Control Panel > System > Advanced > Environment
#      Variables > System Variables > PATH); use semicolons to separate
#      directories in the PATH variable.
#          - the main Python directory, e.g. C:\Python27,
#            so Windows can find "python"
#          - the "Scripts" directory, e.g. C:\Python27\Scripts,
#            so Windows can find "easy_install.exe"
#      For example, you might end up adding this to the end of the PATH
#      variable (without the quotes): ";c:\python27;c:\python27\scripts"
#    - From a command prompt (e.g. Start > Programs > Accessories > Command
#      Prompt), type this:
#          easy_install pyodbc numpy ipython
#    - Download/install matplotlib:
#          http://matplotlib.sourceforge.net/
#          then Download (use the .EXE appropriate to your version of Python),
#          then run the executable, accepting all defaults
# c) Both:
#    - Download http://www.whiskercontrol.com/examples/whisker.py
#      and store it somewhere
#    - Add that somewhere (the directory where you stored whisker.py) to the
#      environment variable PYTHONPATH (create teh environment variable if
#      necessary)

import errno
import os
import urllib


def mkdir_p(path):
    """Makes a directory if it doesn't exist."""
    try:
        os.makedirs(path)
    except OSError as exc:  # Python >2.5
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise


def fetch(filename, urlstem, dir):
    print "Fetching " + filename + " to " + dir
    urllib.urlretrieve(urlstem + filename, dir + filename)


def main():
    urlstem = "http://pobox.com/~rudolf/pythonlib/"
    dir = "c:\\whisker_python_modules\\"
    mkdir_p(dir)

    MODULES = [
        "whisker.py",
        "rnc_ui.py",
        "rnc_db.py",
        "rnc_text.py"
    ]

    for m in MODULES:
        fetch(m, urlstem, dir)

if __name__ == "__main__":
    main()
