def build_index(journal_list):
  """Create an index.html file for HTML output from journal list.

  Args:
    journal_list: [array of path] Path to the journal files to put in the index.
       Assumes that there is a corresponding .html file for each to link to.
  """
  document_manager = HtmlDocumentManager(title='Journal Summary')
  document_manager.has_key = False
  document_manager.has_global_expand = False

  processor = HtmlIndexRenderer(document_manager)
  for journal in journal_list:
    processor.process(journal)
  processor.terminate()

  tr = document_manager.make_tag_container(
      'tr',
      [document_manager.make_tag_text('th', name)
       for name in processor.output_column_names])
  table = document_manager.make_tag_container(
      'table', [tr], style='font-size:12pt')
  document_manager.wrap_tag(table)

  document_manager.build_to_path('index.html')
def build_table(journal_list, output_dir):
  document_manager = HtmlDocumentManager(title='Journal Summary')
  document_manager.has_key = False
  document_manager.has_global_expand = False

  HtmlIndexTableRenderer.process_all(document_manager, journal_list, output_dir)
  document_manager.build_to_path(os.path.join(output_dir, 'table_index.html'))
    def test_expandable_control(self):
        """Test the production of HTML controller for show/hide."""
        manager = HtmlDocumentManager('test_json')

        # Test block both as being initially expanded then not.
        tag = manager.make_expandable_control_tag('SID', 'TEST')
        self.assertEqual(
            '<a class="toggle" onclick="toggle_inline(\'SID\');">TEST</a>',
            str(tag))
Exemple #4
0
  def test_expandable_control(self):
    """Test the production of HTML controller for show/hide."""
    manager = HtmlDocumentManager('test_json')

    # Test block both as being initially expanded then not.
    tag = manager.make_expandable_control_tag('SID', 'TEST')
    self.assertEqual(
        '<a class="toggle" onclick="toggle_inline(\'SID\');">TEST</a>',
        str(tag))
Exemple #5
0
  def test_expandable_tag_attrs(self):
    """Test the production of HTML tag decorators controling show/hide."""
    manager = HtmlDocumentManager('test_json')

    section_id = 'SID'

    # Test block both as being initially expanded then not.
    detail_tags, summary_tags = manager.make_expandable_tag_attr_kwargs_pair(
        section_id, default_expanded=True)
    self.assertEqual({'id': 'SID.1'}, detail_tags)
    self.assertEqual({'id': 'SID.0', 'style': 'display:none'}, summary_tags)

    detail_tags, summary_tags = manager.make_expandable_tag_attr_kwargs_pair(
        section_id, default_expanded=False)
    self.assertEqual({'id': 'SID.1', 'style': 'display:none'}, detail_tags)
    self.assertEqual({'id': 'SID.0'}, summary_tags)
Exemple #6
0
    def test_expandable_tag_attrs(self):
        """Test the production of HTML tag decorators controling show/hide."""
        manager = HtmlDocumentManager('test_json')

        section_id = 'SID'

        # Test block both as being initially expanded then not.
        detail_tags, summary_tags = manager.make_expandable_tag_attr_pair(
            section_id, default_expanded=True)
        self.assertEqual(' id="SID.1"', detail_tags)
        self.assertEqual(' id="SID.0" style="display:none"', summary_tags)

        detail_tags, summary_tags = manager.make_expandable_tag_attr_pair(
            section_id, default_expanded=False)
        self.assertEqual(' id="SID.1" style="display:none"', detail_tags)
        self.assertEqual(' id="SID.0"', summary_tags)
Exemple #7
0
    def test_process_snapshot(self):
        """Test the conversion of a snapshot into HTML."""
        tail = TestLinkedList(name='tail')
        head = TestLinkedList(name='head', next_elem=tail)
        snapshot = JsonSnapshot()
        snapshot.make_entity_for_object(head)
        json_snapshot = snapshot.to_json_object()

        entity_manager = ProcessedEntityManager()
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        entity_manager)
        processor.max_uncollapsable_json_lines = 20
        processor.max_uncollapsable_metadata_rows = 20
        processor.max_uncollapsable_entity_rows = 20
        processor.default_force_top_level_collapse = False

        in_relation = None
        entity_manager.push_entity_map(json_snapshot['_entities'])
        html_info = processor.process_entity_id(json_snapshot['_subject_id'],
                                                json_snapshot, in_relation)
        entity_manager.pop_entity_map(json_snapshot['_entities'])

        expect = """<table>
  <tr>
    <th><i>metadata</i></th>
    <td>
      <table>
        <tr><th>_id</th><td>1</td></tr>
        <tr><th>class</th><td>type TestLinkedList</td></tr>
        <tr><th>name</th><td>head</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <th>Next</th>
    <td>
      <table>
        <tr>
          <th><i>metadata</i></th>
          <td>
            <table>
              <tr><th>_id</th><td>2</td></tr>
              <tr><th>class</th><td>type TestLinkedList</td></tr>
              <tr><th>name</th><td>tail</td></tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
"""
        # Test without regard to whitespace formatting.
        self.assertEquals(''.join(expect.split()),
                          ''.join(str(html_info.detail_block).split()))
Exemple #8
0
    def test_json(self):
        """Test rendering literal json values"""
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        ProcessedEntityManager())
        processor.max_uncollapsable_json_lines = 20
        processor.max_uncollapsable_entity_rows = 20

        # Numeric literals wont be treated as json.
        for n in [-1, 0, 1, 3.14]:
            info = processor.process_json_html_if_possible(n)
            self.assertEquals('{0}'.format(n), info.detail_html)
            self.assertEquals(None, info.summary_html)

        # None of these strings are well-defined JSON documents
        # so should just be strings.
        for s in ['test', 'a phrase', 'True']:
            info = processor.process_json_html_if_possible(s)
            self.assertEquals('"{0}"'.format(s), info.detail_html)
            self.assertEquals(None, info.summary_html)

        # Boolean values wont be considered JSON.
        for b in [True, False]:
            info = processor.process_json_html_if_possible(b)
            self.assertEquals('{0}'.format(str(b)), info.detail_html)
            self.assertEquals(None, info.summary_html)

        # Dictionaries and JSON dictionary strings normalize to JSON.
        for d in [{'A': 'a', 'B': True}, '{"A":"a", "B":true}']:
            info = processor.process_json_html_if_possible(d)
            self.assertEquals(
                '<pre>{{\n  "A": "a",\n'
                '  "B": true\n'
                '}}</pre>'.format(), info.detail_html)
            self.assertEquals(None, info.summary_html)
            self.assertEquals(None, info.summary_html)

        # Lists and JSON lists strings normalize to JSON.
        for l in [[123, 'abc', True, {
                'A': 'a',
                'B': 'b'
        }], '[123, "abc", true, {"A":"a", "B":"b"}]']:
            info = processor.process_json_html_if_possible(l)
            self.assertEquals(
                '<pre>[\n  123,\n  "abc",\n  true,\n'
                '  {{\n'
                '    "A": "a",\n'
                '    "B": "b"\n'
                '  }}\n'
                ']</pre>'.format(), info.detail_html)
            self.assertEquals(None, info.summary_html)
def build_table(journal_list, output_dir):
    document_manager = HtmlDocumentManager(title='Journal Summary')
    document_manager.has_key = False
    document_manager.has_global_expand = False

    HtmlIndexTableRenderer.process_all(document_manager, journal_list,
                                       output_dir)
    document_manager.build_to_path(os.path.join(output_dir,
                                                'table_index.html'))
    def test_cycle(self):
        tail = TestLinkedList(name='tail')
        head = TestLinkedList(name='head', next_elem=tail)
        tail.next = head
        snapshot = JsonSnapshot()

        entity_manager = ProcessedEntityManager()
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        entity_manager)

        snapshot.make_entity_for_object(head)
        json_snapshot = snapshot.to_json_object()
        self.assertEqual(1, json_snapshot.get('_subject_id'))
        entity_manager.push_entity_map(json_snapshot.get('_entities'))
        info = processor.process_entity_id(1, snapshot)
Exemple #11
0
    def test_yaml(self):
        """Test rendering literal json values"""
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_yaml'),
                                        ProcessedEntityManager())
        processor.max_uncollapsable_json_lines = 20
        processor.max_uncollapsable_entity_rows = 20

        # Numeric literals wont be treated as yaml
        for n in [-1, 0, 1, 3.14]:
            info = processor.process_yaml_html_if_possible(n)
            self.assertEquals('{0}'.format(n), info.detail_block)
            self.assertEquals(None, info.summary_block)

        # None of these strings are well-defined YAML documents
        # so should just be strings.
        for s in ['test', 'a phrase']:
            info = processor.process_yaml_html_if_possible(s)
            self.assertEquals('<pre>%s\n</pre>' % s, info.detail_block)
            self.assertEquals(None, info.summary_block)
        info = processor.process_yaml_html_if_possible('True')
        self.assertEquals('<pre>true\n</pre>', info.detail_block)

        # Boolean values wont be considered YAML
        for b in [True, False]:
            info = processor.process_yaml_html_if_possible(b)
            self.assertEquals('{0}'.format(str(b)), info.detail_block)
            self.assertEquals(None, info.summary_block)

        # Dictionaries and YAML dictionary strings normalize to YAML
        import yaml
        for d in [{'A': 'a', 'B': True}, 'A: a\nB: true\n']:
            info = processor.process_yaml_html_if_possible(d)
            # The eolns here show that it is being yaml formatted.
            self.assertEquals('<pre>A:a\nB:true\n</pre>',
                              str(info.detail_block).replace(' ', ''))
            self.assertEquals(None, info.summary_block)
            self.assertEquals(None, info.summary_block)

        # Lists and YAML lists strings normalize to YAML.
        for l in [[123, 'abc', True, {
                'A': 'a',
                'B': 'b'
        }], '[123, "abc", true, {"A":"a", "B":"b"}]']:
            info = processor.process_yaml_html_if_possible(l)
            self.assertEquals(
                '<pre>-123\n-abc\n-true\n-A:a\nB:b\n</pre>',
                str(info.detail_block).replace(' ', '').replace('\n', '\n'))
            self.assertEquals(None, info.summary_block)
Exemple #12
0
def journal_to_html(input_path, prune=False):
    """Main program for converting a journal JSON file into HTML.

  This will write a file using in the input_path directory with the
  same basename as the JSON file, but with 'html' extension instead.

  Args:
    input_path: [string] Path the journal file.
  """
    output_path = os.path.basename(os.path.splitext(input_path)[0]) + '.html'

    document_manager = HtmlDocumentManager(
        title='Report for {0}'.format(os.path.basename(input_path)))

    processor = HtmlRenderer(document_manager, prune=prune)
    processor.process(StreamJournalNavigator.new_from_path(input_path))
    processor.terminate()
    document_manager.wrap_tag(document_manager.new_tag('table'))
    document_manager.build_to_path(output_path)
Exemple #13
0
def journal_to_html(input_path):
  """Main program for converting a journal JSON file into HTML.

  This will write a file using in the input_path directory with the
  same basename as the JSON file, but with 'html' extension instead.

  Args:
    input_path: [string] Path the journal file.
  """
  output_path = os.path.basename(os.path.splitext(input_path)[0]) + '.html'

  document_manager = HtmlDocumentManager(
      title='Report for {0}'.format(os.path.basename(input_path)))

  processor = HtmlRenderer(document_manager)
  processor.process(input_path)
  processor.terminate()
  document_manager.wrap_tag(document_manager.new_tag('table'))
  document_manager.build_to_path(output_path)
Exemple #14
0
def build_index(journal_list, output_dir):
    """Create an index.html file for HTML output from journal list.

  Args:
    journal_list: [array of path] Path to the journal files to put in the index.
       Assumes that there is a corresponding .html file for each to link to.
  """
    document_manager = HtmlDocumentManager(title='Journal Summary')
    document_manager.has_key = False
    document_manager.has_global_expand = False

    processor = HtmlIndexRenderer(document_manager)
    for journal in journal_list:
        processor.process(StreamJournalNavigator.new_from_path(journal))
    processor.terminate()

    tr_tag = document_manager.make_tag_container('tr', [
        document_manager.make_tag_text('th', name)
        for name in processor.output_column_names
    ])
    table = document_manager.make_tag_container('table', [tr_tag],
                                                style='font-size:12pt')
    document_manager.wrap_tag(table)

    document_manager.build_to_path(os.path.join(output_dir, 'index.html'))