Ejemplo n.º 1
0
def restify(example_file, filehash, fname):
    """
    Takes a whole file ie., the result of file.read(), its md5 hash, and
        the filename
    Parse the file
    Write the new .rst
    Update the hash_dict
    """
    write_filename = os.path.join(docs_rst_dir, fname[:-2] + 'rst')
    try:
        rst_file = parse_file(example_file)
    except IOError as err:
        raise IOError(err.message % fname)
    write_file(rst_file, write_filename)
    hash_funcs.update_hash_dict(filehash, fname)
Ejemplo n.º 2
0
def restify(example_file, filehash, fname):
    """
    Takes a whole file ie., the result of file.read(), its md5 hash, and
        the filename
    Parse the file
    Write the new .rst
    Update the hash_dict
    """
    write_filename = os.path.join(docs_rst_dir, fname[:-2] + 'rst')
    try:
        rst_file = parse_file(example_file)
    except IOError as err:
        raise IOError(err.message % fname)
    write_file(rst_file, write_filename)
    if filehash is not None:
        hash_funcs.update_hash_dict(filehash, fname)
Ejemplo n.º 3
0
if __name__ == "__main__":

    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)

    for dataset in datasets:
        write_pth = join(dest_dir, dataset + '.rst')
        data_mod = datasets[dataset]
        title = getattr(data_mod, 'TITLE')
        descr = getattr(data_mod, 'DESCRLONG')
        copyr = getattr(data_mod, 'COPYRIGHT')
        notes = getattr(data_mod, 'NOTE')
        source = getattr(data_mod, 'SOURCE')
        write_file = doc_template.substitute(TITLE=title,
                                             title_='=' * len(title),
                                             DESCRIPTION=descr,
                                             NOTES=notes,
                                             SOURCE=source,
                                             COPYRIGHT=copyr)
        to_write, filehash = hash_funcs.check_hash(write_file.encode(),
                                                   data_mod.__name__.encode())
        if not to_write:
            print("Hash has not changed for docstring of dataset "
                  "{}".format(dataset))
            continue
        with open(os.path.realpath(write_pth), 'w') as rst_file:
            rst_file.write(write_file)
        if filehash is not None:
            hash_funcs.update_hash_dict(filehash, data_mod.__name__)
Ejemplo n.º 4
0
                    shutil.move(fname_only+"_files",
                            os.path.join(rst_target_dir, fname_only+"_files"))
            elif OUTPUT == "html":
                from notebook_output_template import notebook_template
                new_html = os.path.join(rst_target_dir, fname_only+".rst")
                # get the title out of the notebook because sphinx needs it
                title_cell = nb['worksheets'][0]['cells'].pop(0)
                try:
                    assert title_cell['cell_type'] == 'heading'
                except:
                    print "Title not in first cell for ", fname_only
                    print "Not generating rST"

                html_out = nb2html(nb)
                # indent for insertion into raw html block in rST
                html_out = "\n".join(["   "+i for i in html_out.split("\n")])
                with io.open(new_html, "w", encoding="utf-8") as f:
                    f.write(title_cell["source"]+u"\n")
                    f.write(u"="*len(title_cell["source"])+u"\n\n")
                    f.write(notebook_template.substitute(name=fname_only,
                                                         body=html_out))
            hash_funcs.update_hash_dict(filehash, fname_only)
    except Exception, err:
        raise err

    finally:
        os.chdir(cur_dir)

    # probably not necessary
    del notebook_runner
Ejemplo n.º 5
0
                    shutil.move(
                        fname_only + "_files",
                        os.path.join(rst_target_dir, fname_only + "_files"))
            elif OUTPUT == "html":
                from notebook_output_template import notebook_template
                new_html = os.path.join(rst_target_dir, fname_only + ".rst")
                # get the title out of the notebook because sphinx needs it
                title_cell = nb['worksheets'][0]['cells'].pop(0)
                try:
                    assert title_cell['cell_type'] == 'heading'
                except:
                    print "Title not in first cell for ", fname_only
                    print "Not generating rST"

                html_out = nb2html(nb)
                # indent for insertion into raw html block in rST
                html_out = "\n".join(["   " + i for i in html_out.split("\n")])
                with io.open(new_html, "w", encoding="utf-8") as f:
                    f.write(title_cell["source"] + u"\n")
                    f.write(u"=" * len(title_cell["source"]) + u"\n\n")
                    f.write(notebook_template.substitute(body=html_out))
            hash_funcs.update_hash_dict(filehash, fname_only)
    except Exception, err:
        raise err

    finally:
        os.chdir(cur_dir)

    # probably not necessary
    del notebook_runner
Ejemplo n.º 6
0
$COPYRIGHT
""")

if __name__ == "__main__":

    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)

    for dataset in datasets:
        write_pth = join(dest_dir, dataset + '.rst')
        data_mod = datasets[dataset]
        title = getattr(data_mod, 'TITLE')
        descr = getattr(data_mod, 'DESCRLONG')
        copyr = getattr(data_mod, 'COPYRIGHT')
        notes = getattr(data_mod, 'NOTE')
        source = getattr(data_mod, 'SOURCE')
        write_file = doc_template.substitute(TITLE=title,
                                             title_='='*len(title),
                                             DESCRIPTION=descr, NOTES=notes,
                                             SOURCE=source, COPYRIGHT=copyr)
        to_write, filehash = hash_funcs.check_hash(write_file.encode(),
                                                   data_mod.__name__.encode())
        if not to_write:
            print("Hash has not changed for docstring of dataset "
                  "{}".format(dataset))
            continue
        with open(os.path.realpath(write_pth), 'w') as rst_file:
            rst_file.write(write_file)
        if filehash is not None:
            hash_funcs.update_hash_dict(filehash, data_mod.__name__)