Exemplo n.º 1
0
def get_manual_contents(srcdir):
    root = os.getcwd()
    directory = os.path.join(root, srcdir)
    if not os.path.exists(directory):
        msg = 'Expected directory %s' % directory
        raise Exception(msg)
    pattern = '*.md'
    filenames = locate_files(directory,
                             pattern,
                             followlinks=True,
                             include_directories=False,
                             include_files=True,
                             normalize=False)
    ok = []
    for fn in filenames:
        fn = os.path.relpath(fn, root)
        if 'exclude' in fn:
            logger.info('Excluding file %r because of string "exclude" in it' %
                        fn)
            continue
        ok.append(fn)
    filenames = natsorted(ok)
    for f in filenames:
        docname, _extension = os.path.splitext(os.path.basename(f))
        yield 'manual', docname
Exemplo n.º 2
0
    def write_sections(sections, parents):
        assert 'type' in sections
        assert sections['type'] == 'division', sections
        field = sections['field']
        division = sections['division']

        f.write('<ul>')
        sorted_values = natsorted(list(division.keys()))
        for value in sorted_values:
            parents.append(value)
            html_id = "-".join(map(str, parents))
            bottom = division[value]
            if bottom['type'] == 'sample':
                d = {field: value}
                if not bottom['key']:
                    write_li(k=d, filename=bottom['value'], element='li')
                else:
                    f.write('<li> <p id="%s"><a class="self" href="#%s">%s = %s</a></p>\n'
                            % (html_id, html_id, field, value))
                    f.write('<ul>')
                    write_li(k=bottom['key'], filename=bottom['value'], element='li')
                    f.write('</ul>')
                    f.write('</li>')
            else:
                f.write('<li> <p id="%s"><a class="self" href="#%s">%s = %s</a></p>\n'
                        % (html_id, html_id, field, value))

                write_sections(bottom, parents)
                f.write('</li>')
        f.write('</ul>')
Exemplo n.º 3
0
def job_bib_contents(context, bib_files):
    bib_files = natsorted(bib_files)
    # read all contents
    contents = ""
    for fn in bib_files:
        contents += open(fn).read() + '\n\n'
    h = get_md5(contents)[:8]
    job_id = 'bibliography-' + h
    return context.comp(run_bibtex2html, contents, job_id=job_id)
Exemplo n.º 4
0
    def groups_by_field_value(self, field):
        """
            Partitions the contents according to the value of the given
            field.

            Example: ::

                for delta, samples in x.groups_by_field_value('delta'):
                    ...
        """
        field_values = set(self.field(field))
        # convert to string in order to sort
        sorted_values = natsorted(field_values)
        for value in sorted_values:
            query = {field: value}
            samples = self.select(**query)
            assert samples
            assert field in samples.fields_with_unique_values()  # expensive

            yield value, samples
Exemplo n.º 5
0
    def groups_by_field_value(self, field):
        """
            Partitions the contents according to the value of the given
            field.
            
            Example: :: 
            
                for delta, samples in x.groups_by_field_value('delta'):
                    ...
        """
        field_values = set(self.field(field))
        # convert to string in order to sort
        sorted_values = natsorted(field_values)
        for value in sorted_values:
            query = {field: value}
            samples = self.select(**query)
            assert samples
            assert field in samples.fields_with_unique_values()  # expensive

            yield value, samples
Exemplo n.º 6
0
def look_for_files(srcdirs, pattern):
    """
        Excludes files with "excludes" in the name.
    """
    results = []
    results_absolute = set()
    for d0 in srcdirs:
        d = expand_all(d0)
        if not os.path.exists(d):
            msg = 'Could not find directory %r' % d
            msg += '\nSearching from directory %r' % os.getcwd()
            raise Exception(msg)

        filenames = locate_files(d,
                                 pattern,
                                 followlinks=True,
                                 include_directories=False,
                                 include_files=True,
                                 normalize=False)

        ok = []
        for fn in filenames:
            fn0 = os.path.realpath(fn)
            if 'exclude' in fn0:
                logger.info(
                    'Excluding file %r because of string "exclude" in it' % fn)
            else:
                if fn0 in results_absolute:
                    logger.debug('Reached the file %s twice' % fn0)
                    pass
                else:
                    results_absolute.add(fn0)
                    ok.append(fn)

        results.extend(natsorted(ok))

    logger.info('Found %d files with pattern %s in %s' %
                (len(results), pattern, srcdirs))
    return results
Exemplo n.º 7
0
def create_links_html(this_report, other_reports_same_type, index_filename,
                      most_similar_other_type):
    '''
    :param this_report: dictionary with the keys describing the report
    :param other_reports_same_type: StoreResults -> filename
    :returns: html string describing the link
    '''

    def rel_link(f):  # (this is FROM f0 to f) --- trust me, it's ok
        f0 = other_reports_same_type[this_report]
        rl = os.path.relpath(f, os.path.dirname(f0))
        return rl

    s = ""

    # create table by cols
    table = create_links_html_table(this_report, other_reports_same_type)

    s += "<p><a href='%s'>All report</a></p>" % rel_link(index_filename)

    s += "<table class='variations'>"
    s += "<thead><tr>"
    for field, _ in table:
        s += "<th>%s</th>" % field
    s += "</tr></thead>"

    s += "<tr>"

    add_invalid_links = True

    for field, variations in table:
        s += "<td>"

        MAX_VARIATIONS_EXPLICIT = 10

        # hide the n/a
        # variations = [v for v in variations if v[1] is not None]

        all_vars = dict(variations)
        sorted_variations = natsorted([v[0] for v in variations])
        # print('sorted: %s' % sorted_variations)
        variations = [(v, all_vars[v]) for v in sorted_variations]

        if len(variations) > MAX_VARIATIONS_EXPLICIT:
            id_select = 'select-%s' % (field)
            onchange = 'onchange_%s' % (field)
            s += "<select id='%s' onChange='%s()'>\n" % (id_select, onchange)

            for text, link in variations:
                if link is not None:
                    s += "<option value='%s'>%s</a> \n" % (link, text)
                else:
                    if add_invalid_links:
                        s += "<option value=''>%s</a> \n" % (text)
                s += '<br/>'

            s += '</select>\n'

            s += """         
<script>
    $(function(){
      // bind change event to select
      $('#%s').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
""" % id_select

        else:
            for text, link in variations:
                if link is not None:
                    s += "<a href='%s'> %s</a> " % (link, text)
                else:
                    if add_invalid_links:
                        s += "%s " % (text)
                s += '<br/>\n'

        s += "</td>"

    s += "</tr>"
    s += "</table>"

    #     s += '<dl>'
    #     for other_type, most_similar, filename in most_similar_other_type:
    #         s += '<dt><a href="%s">%s</a></dt><dd>%s</dd>' % (rel_link(filename),
    #                                                           other_type, most_similar)
    #     s += '</dl>'

    if most_similar_other_type:
        s += '<p>Other report: '
        for other_type, _, filename in most_similar_other_type:
            s += '<a href="%s">%s</a> ' % (rel_link(filename), other_type)
        s += '</p>'

    s = '<div style="margin-left: 1em;">' + s + '</div>'
    return s