Exemplo n.º 1
0
def _from_template(tmpl_basename, config, use_html=True):
    tmpl = os.path.join(template_dir, tmpl_basename + '.tmpl')
    if use_html:
        template = tempita.HTMLTemplate(open(tmpl, 'r').read())
    else:
        template = TeXTemplate(open(tmpl, 'r').read())
    return template.substitute(config)
Exemplo n.º 2
0
 def _repr_html_(self):
     import tempita
     return tempita.HTMLTemplate("""
     <h3>{{self.name}}</h3>
     <div style="display: flex; flex-wrap: wrap">
       <div style="margin; 1em">
         <table>
           <tr>
             <th>State name</th>
             <th>BitMask</th>
           {{for state in self.states}}
             <tr>
               <td>{{state.name}}</td>
               <td><code>{{ state.bit_mask.mask_str() }}</code></td>
             </tr>
           {{endfor}}
         </table>
       </div>
       {{for action in self.actions}}
         <div style="border: 1px solid #99f; border-radius: 2px; min-width: 20em; margin: 1em; flex: 1 0 auto">
           <div><strong>{{action.action}}</strong></div>
           <div>
             Must:
               <code style="white-space: nowrap">{{action.must_bits.mask_str()}}</code>
               {{"; ".join(action.must)}}<br>
             Then:
               <code style-"white-space: nowrap">{{action.then_bits.mask_str()}}</code>
               {{"; ".join(action.then)}}
           </div>
         </div>
       {{endfor}}
     </div>
     """).substitute({"self": self})
Exemplo n.º 3
0
def arxiv_html(config):
    mkdir_p(arxiv_dir)
    for name in ['index', 'submissions']:
        dest_fn = os.path.join(arxiv_dir, 'arxiv_%s.html' % name)
        template = tempita.HTMLTemplate(open(os.path.join(template_dir, 'arxiv_%s.html.tmpl' % name), 'r').read())
        content = template.substitute(config)
        with open(dest_fn, mode='w') as f:
            f.write(content)
Exemplo n.º 4
0
def _from_template(tmpl_basename, config, use_html=True):
    tmpl = os.path.join(template_dir, tmpl_basename + '.tmpl')
    if use_html:
        with io.open(tmpl, mode='r', encoding='utf-8') as f:
            template = tempita.HTMLTemplate(f.read())
    else:
        with io.open(tmpl, mode='r', encoding='utf-8') as f:
            template = TeXTemplate(f.read())
    return template.substitute(config)
Exemplo n.º 5
0
 def _repr_html_(self, *, header=True):
     import tempita
     parts = {}
     must_bits = self.null
     then_bits = self.null
     for action in reversed(self.actions):
         current_must_bits = must_bits.except_satisfied_by(action.then_bits)
         must_bits = action.must_bits.union(current_must_bits)
         parts[action] = {"must_bits": must_bits}
         parts[action]["action"] = action
         if isinstance(action, GoalPool):
             parts[action]["repr"] = "Goal"
         elif len(action.actions) > 1:
             parts[action]["repr"] = "In any order: {}".format(", ".join(a.action for a in action.actions))
         else:
             parts[action]["repr"] = action.actions[0].action
     for action in self.actions:
         then_bits = action.then_bits.carry_forward(then_bits)
         parts[action]["then_bits"] = then_bits
     parts[self.actions[0]]["must_style"] = "font-weight: bold"
     parts[self.actions[-1]]["then_style"] = "font-weight: bold"
     parts_seq = [parts[action] for action in self.actions]
     return tempita.HTMLTemplate("""
     {{if header}}
       <h3>Action sequence:</h3>
     {{endif}}
     <ol>
       {{for info in parts_seq}}
         <li>{{info["repr"]}}
           <ul>
             <li>Must:
               <code style="{{info.get('must_style')}}">{{info["must_bits"].mask_str()}}</code></li>
             <li>Then:
               <code style="{{info.get('then_style')}}">{{info["then_bits"].mask_str()}}</code></li>
           </ul>
         </li>
       {{endfor}}
     </ol>
     """).substitute({"self": self, "parts_seq": parts_seq, "header": header})
Exemplo n.º 6
0
 def _repr_html_(self, short=False):
     import tempita
     htmls = []
     for log in self.activity:
         if hasattr(log, "_repr_html_"):
             htmls.append({"html": log._repr_html_()})
         else:
             text = str(log)
             if text:
                 htmls.append({"text": text})
     start_states = []
     goal_states = []
     for state in self.domain.states:
         if self.start_state.is_set(state.bit_mask._bits) and not self.start_state.conflicts(state.bit_mask):
             start_states.append(state.name)
         if self.goal.is_set(state.bit_mask._bits) and not self.goal.conflicts(state.bit_mask):
             goal_states.append(state.name)
     return tempita.HTMLTemplate("""
     {{if not short}}
     <aside style="float: right; background-color: #ddd; padding: 0.75em">
       <div>
         Start state:<br>
         <code>{{self.start_state.mask_str()}}</code>
           <ul style="list-style: none; margin: 0">
             {{for item in start_states}}
               <li>{{item}}</li>
             {{endfor}}
           </ul>
       </div>
       <div>
         Goal:<br>
         <code>{{self.goal.mask_str()}}</code>
           <ul style="list-style: none; margin: 0">
             {{for item in goal_states}}
               <li>{{item}}</li>
             {{endfor}}
           </ul>
       </div>
     </aside>
     {{endif}}
     <h3>Problem solution log:</h3>
     <ul style="list-style: none">
       <li>Tried: <strong>{{self.total_count}}</strong></li>
       <li>Skipped: <strong>{{self.skipped_count}}</strong> ({{int(100*self.skipped_count/self.total_count)}}%)</li>
       <li>Explored: <strong>{{self.seen_count}}</strong></li>
       <li>Time: <strong>{{"{:0.5}".format(self.end - self.start)}}s</strong></li>
       <li>Expansions: {{self.expansions}}</li>
       <li>Goal tests: {{self.goal_tests}}</li>
       <li>New nodes: {{self.new_nodes}}</li>
     </ul>
     {{if not short}}
     <ol>
       {{for h in htmls}}
         {{if h.get("html")}}
           <li>{{h.get("html") | html}}</li>
         {{else}}
           <li>{{h.get("text")}}</li>
         {{endif}}
       {{endfor}}
     </ol>
     {{endif}}
     """).substitute({"self": self, "htmls": htmls, "start_states": start_states, "goal_states": goal_states, "short": short})
Exemplo n.º 7
0
def _from_template(tmpl_basename, config):
    tmpl = os.path.join(template_dir, tmpl_basename + '.tmpl')
    template = tempita.HTMLTemplate(open(tmpl, 'r').read())
    return template.substitute(config)
    def __init__(self, info, outputFile):
        super(HTMLTestReportGenerator, self).__init__(info, outputFile)

        # Load Tempita template.
        self._namespace = tempita.bunch()
        self._template = tempita.HTMLTemplate(content=REPORT_TEMPLATE, name='Test Report', namespace=self._namespace)
Exemplo n.º 9
0
    def write_zipfile(self, dir):
        import os
        import tempfile
        from zipfile import ZipFile
        import tempita

        fd, zip_filename = tempfile.mkstemp(prefix="trac_pluginspector",
                                            suffix=".zip")
        zipfile = ZipFile(zip_filename, 'w')
        try:
            components, interfaces, packages, options = self.get_data()

            tmpl = """---
layout: main
title: {{name}}
---
<h1 class="name">{{name}}</h1>
<h2 class="package">In package <a href="packages/{{package}}/index.html">{{package}}</a></h2>

{{if doc}}
<pre class="doc">{{doc}}</pre>
{{else}}
<p><em>No documentation available</em></p>
{{endif}}
<h2>Implemented by:</h2>
<ul>
{{for component in implemented_by}}
  <li><a href="components/{{component}}/index.html">{{component}}</a></li>
{{endfor}}
</ul>
"""
            tmpl = tempita.HTMLTemplate(tmpl)
            for name in interfaces:
                html = tmpl.substitute(interfaces[name])
                zipfile.writestr("interfaces/%s/index.html" % name, html)

            tmpl = """---
layout: main
title: {{name}}
---
<h1 class="name">{{name}}</h1>
<h2 class="package">In package <a href="packages/{{package}}/index.html">{{package}}</a></h2>

<pre class="doc">{{doc}}</pre>

<h2>Implements:</h2>
<ul>
{{for interface in implements}}
  <li><a href="interfaces/{{interface}}/index.html">{{interface}}</a></li>
{{endfor}}
</ul>

<h2>Contains via Extension Points:</h2>
<ul>
{{for interface in extension_points}}
  <li><a href="interfaces/{{interface}}/index.html">{{interface}}</a></li>
{{endfor}}
</ul>

<h2>Options:</h2>
<table>
  <thead>
    <tr><th>Section</th><th>Name</th><th>Type</th><th>Default</th><th>Docs</th></tr>
  </thead>
{{for option in options}}
  <tr>
    <td>{{option['section']}}</td>
    <td>{{option['name']}}</td>
    <td>{{option['type']}}</td>
    <td>{{option['default']}}</td>
    <td>{{option['doc']}}</td>
  </tr>
{{endfor}}
</table>
"""
            tmpl = tempita.HTMLTemplate(tmpl)

            for name in components:
                html = tmpl.substitute(components[name])
                zipfile.writestr("components/%s/index.html" % name, html)

            tmpl = """---
layout: main
title: {{name}}
---
<h1 class="name">{{name}}</h1>

{{if doc}}
<pre class="doc">{{doc}}</pre>
{{else}}
<p><em>No documentation available</em></p>
{{endif}}

<h2>Interfaces Declared:</h2>
<ul>
{{for interface in interfaces}}
  <li><a href="interfaces/{{interface}}/index.html">{{interface}}</a></li>
{{endfor}}
</ul>
<h2>Components Provided:</h2>
<ul>
{{for component in components}}
  <li><a href="components/{{component}}/index.html">{{component}}</a></li>
{{endfor}}
</ul>

<h2>Package Metadata:</h2>
<pre class="metadata">
{{metadata|pformat}}
</pre>

"""
            from pprint import pformat
            tmpl = tempita.HTMLTemplate(tmpl, namespace={'pformat': pformat})
            for package in packages:
                ctx = dict(
                    name=package,
                    interfaces=packages[package]['interfaces'],
                    components=packages[package]['components'],
                    doc=packages[package]['metadata'].get('description'),
                    metadata=packages[package]['metadata'],
                )
                html = tmpl.substitute(ctx)
                zipfile.writestr("packages/%s/index.html" % package, html)

            tmpl = """---
layout: main
title: Index
---
<h1 class="name">Trac Docs</h1>

<h2>Packages</h2>
<ul>
{{for package in packages}}
  <li><a href="packages/{{package}}/index.html">{{package}}</a></li>
{{endfor}}
</ul>

<h2>Interfaces</h2>
<ul>
{{for interface in interfaces}}
  <li><a href="interfaces/{{interface}}/index.html">{{interface}}</a></li>
{{endfor}}
</ul>

<h2>Components</h2>
<ul>
{{for component in components}}
  <li><a href="components/{{component}}/index.html">{{component}}</a></li>
{{endfor}}
</ul>
"""
            tmpl = tempita.HTMLTemplate(tmpl)
            html = tmpl.substitute(
                dict(
                    components=sorted(components),
                    interfaces=sorted(interfaces),
                    packages=sorted(packages),
                ))
            zipfile.writestr("index.html", html)

        finally:
            zipfile.close()

        unzipper = unzip()
        unzipper.verbose = False
        unzipper.extract(zip_filename, dir)

        os.unlink(zip_filename)