#!/usr/bin/env python

import os
import scipy.io as sio

PYTHON_DIR = os.path.dirname(os.path.realpath(__file__))
DATA_DIR = os.path.join(os.path.dirname(PYTHON_DIR), 'pmtkdataCopy')


def load_mat(matName):
    """look for the .mat file in pmtk3/pmtkdataCopy/
    currently only support .mat files create by Matlab 5,6,7~7.2,
    """
    try:
        data = sio.loadmat(os.path.join(DATA_DIR, matName))
    except NotImplementedError:
        raise
    except FileNotFoundError:
        raise
    return data

@@ -48,16 +48,28 @@
 o as sio
+%0Aimport glob
 %0A%0APYTHON
@@ -515,8 +515,625 @@
 rn data%0A
+%0A%0Adef generate_rst():%0A    %22%22%22generate chX.rst in current working directory%22%22%22%0A    scripts = glob.glob('*.py')%0A    chapter = os.path.basename(os.getcwd())%0A    rst_file = chapter + '.rst'%0A    with open(rst_file, 'w') as f:%0A        f.write(chapter)%0A        f.write('%5Cn========================================%5Cn')%0A        for script in scripts:%0A            f.write('%5Cn' + script%5B:-3%5D)%0A            f.write('%5Cn----------------------------------------%5Cn')%0A            for img in glob.glob(script%5B:-3%5D + '*.png'):%0A                f.write(%22.. image::%22 + img + %22%5Cn%22)%0A            f.write(%22.. literalinclude:: %22 + script + %22%5Cn%22)%0A

add function gengerate_rst() to genetate chX.rst