Exemplo n.º 1
0
def build_docs(project, pdf):
    """
    A helper function for the celery task to do the actual doc building.
    """
    if not project.path:
        return ('','Conf file not found.',-1)
    try:
        profile = project.user.get_profile()
        if profile.whitelisted:
            print "Project whitelisted"
            sanitize_conf(project.conf_filename)
        else:
            print "Writing conf to disk"
            project.write_to_disk()
    except (OSError, SiteProfileNotAvailable, ObjectDoesNotExist):
        try:
            print "Writing conf to disk"
            project.write_to_disk()
        except (OSError, IOError):
            print "Conf file not found. Error writing to disk."
            return ('','Conf file not found. Error writing to disk.',-1)


    try:
        makes = [makefile for makefile in project.find('Makefile') if 'doc' in makefile]
        make_dir = makes[0].replace('/Makefile', '')
        os.chdir(make_dir)
        html_results = run('make html')
        if html_results[0] != 0:
            raise OSError
        if pdf:
            latex_results = run('make latex')
            match = latex_re.search(latex_results[1])
            if match:
                latex_dir = match.group(1).strip()
                os.chdir(latex_dir)
                pdf_results = run('make')
                pdf = glob.glob('*.pdf')[0]
                run('ln -s %s %s/%s.pdf' % (os.path.join(os.getcwd(), pdf),
                                            settings.MEDIA_ROOT,
                                            project.slug
                                           ))
    except (IndexError, OSError):
        os.chdir(project.path)
        html_results = run('sphinx-build -b html . _build/html')
    return html_results
Exemplo n.º 2
0
 def _match_file(self, to_match):
     pre_match = file(to_match, 'r').readlines()
     num_matched = sanitize_conf(to_match)
     post_match = file(to_match, 'r').readlines()
     return (pre_match, num_matched, post_match)