Ejemplo n.º 1
0
 def __init__(self, stream, **kw):
     self._output = stream
     self.data = tempita.bunch(
         filename=self._output.name,
         today=datetime.date.today(),
         **kw
         )
     try:
         import pkg_resources
         template_txt = pkg_resources.resource_string('fatghol', 'template.tex')
     except ImportError:
         # try to open in current directory
         if os.path.exists('template.tex') and os.path.isfile('template.tex'):
             with open('template.tex', 'r') as template_file:
                 template_txt = template_file.read()
         else:
             raise
     self._template = tempita.Template(
         template_txt,
         delimeters=('<<', '>>'),
         name='fatghol/template.tex',
         namespace=self.data,
         )
     self._total_graphs = 0
     self._total_marked_graphs = 0
     # document appendices
     self._appendix_graph_markings = None
Ejemplo n.º 2
0
def view_market(environ):
    user = environ["emapps.user"]
    table = []
    for (charname, staname, volentered, volremaining, minvolume, typename,
         range, wallet, duration, escrow,
         price, bid, issued) in list(csv.reader(file(MORDERFILE))):
        if int(bid) == 0:
            continue
        b = tempita.bunch()
        
        b.update({'pilot': charname,
                  'station': staname,
                  'volentered': int(volentered),
                  'volremaining': int(volremaining),
                  'minvolume': int(minvolume),
                  'typename': typename,
                  'range': int(range),
                  'wallet': wallet,
                  'duration': datetime.timedelta(days=int(duration)),
                  'escrow': escrow,
                  'price': float(price),
                  'bid': bid,
                  'issued': datetime.datetime.utcfromtimestamp(int(issued))})
        table.append(b)
    return kgi.template_response('gradient/marketorders.html',
                                 user=user,
                                 orders=table)
Ejemplo n.º 3
0
def get_table_head(runSetResults, commonFileNamePrefix):

    # This list contains the number of columns each run set has
    # (the width of a run set in the final table)
    # It is used for calculating the column spans of the header cells.
    runSetWidths = [len(runSetResult.columns) for runSetResult in runSetResults]

    for runSetResult in runSetResults:
        # Ugly because this overwrites the entries in the map,
        # but we don't need them anymore and this is the easiest way
        for key in runSetResult.attributes:
            if key == 'turbo':
                turbo_values = list(set(runSetResult.attributes['turbo']))
                if len(turbo_values) > 1:
                    turbo = 'mixed'
                elif turbo_values[0] == 'true':
                    turbo = 'enabled'
                elif turbo_values[0] == 'false':
                    turbo = 'disabled'
                else:
                    turbo = None
                runSetResult.attributes['turbo'] = ', Turbo Boost {}'.format(turbo) if turbo else ''
            else:
                runSetResult.attributes[key] = Util.prettylist(runSetResult.attributes[key])

    def get_row(rowName, format_string, collapse=False, onlyIf=None, default='Unknown'):
        def format_cell(attributes):
            if onlyIf and not onlyIf in attributes:
                formatStr = default
            else:
                formatStr = format_string
            return formatStr.format(**attributes)

        values = [format_cell(runSetResult.attributes) for runSetResult in runSetResults]
        if not any(values):
            return None # skip row without values completely

        valuesAndWidths = list(Util.collapse_equal_values(values, runSetWidths)) \
                          if collapse else list(zip(values, runSetWidths))

        return tempita.bunch(id=rowName.lower().split(' ')[0],
                             name=rowName,
                             content=valuesAndWidths)

    titles      = [column.title for runSetResult in runSetResults for column in runSetResult.columns]
    runSetWidths1 = [1]*sum(runSetWidths)
    titleRow    = tempita.bunch(id='columnTitles', name=commonFileNamePrefix,
                                content=list(zip(titles, runSetWidths1)))

    return {'tool':    get_row('Tool', '{tool} {version}', collapse=True),
            'limit':   get_row('Limits', 'timelimit: {timelimit}, memlimit: {memlimit}, CPU core limit: {cpuCores}', collapse=True),
            'host':    get_row('Host', '{host}', collapse=True, onlyIf='host'),
            'os':      get_row('OS', '{os}', collapse=True, onlyIf='os'),
            'system':  get_row('System', 'CPU: {cpu} with {cores} cores, frequency: {freq}{turbo}; RAM: {ram}', collapse=True, onlyIf='cpu'),
            'date':    get_row('Date of execution', '{date}', collapse=True),
            'runset':  get_row('Run set', '{niceName}'),
            'branch':  get_row('Branch', '{branch}'),
            'options': get_row('Options', '{options}'),
            'property':get_row('Propertyfile', '{propertyfiles}', collapse=True, onlyIf='propertyfiles', default=''),
            'title':   titleRow}
Ejemplo n.º 4
0
    def settings_py(self):
        if 'settings-template' in self.options:
            template_fname = self.options['settings-template']
        else:
            template_fname = os.path.join(
                os.path.dirname(__file__),
                'settings.py.in'
            )
        self._logger.debug(
            "Loading settings template from %s" % template_fname
        )
        stream = open(template_fname, 'rb')
        template_definition = stream.read().decode('utf-8')
        stream.close()
        if 'settings-template-extension' in self.options:
            self._logger.debug(
                "Loading settings extension template from %s" % (
                    self.options['settings-template-extension'],
                )
            )
            stream = open(
                self.options['settings-template-extension'],
                'rb'
            )
            template_definition += u"\n\n# Extension template %s\n\n" % (
                self.options['settings-template-extension'],
            )
            template_definition += stream.read().decode('utf-8')
            stream.close()

        variables = {}
        for section in self.buildout.keys():
            variables[section] = bunch(
                **dict(normalize_keys(self.buildout[section]))
            )
        variables.update(dict(normalize_keys(self.options)))
        self.fix_databases(variables)
        variables.update({ 'name': self.name, 'secret': self.secret })
        self._logger.debug(
            "Variable computation terminated:\n%s" % pprint.pformat(variables)
        )
        template = Template(
            template_definition,
            namespace=self._template_namespace
        )
        self._logger.debug(
            "Interpolating template, namespace is:\n%s" % pprint.pformat(
                self._template_namespace
            )
        )
        return template.substitute(variables)
Ejemplo n.º 5
0
def getTableHead(runSetResults, commonFileNamePrefix):

    # This list contains the number of columns each run set has
    # (the width of a run set in the final table)
    # It is used for calculating the column spans of the header cells.
    runSetWidths = [len(runSetResult.columns) for runSetResult in runSetResults]

    for runSetResult in runSetResults:
        # Ugly because this overwrites the entries in the map,
        # but we don't need them anymore and this is the easiest way
        for key in runSetResult.attributes:
            runSetResult.attributes[key] = Util.prettylist(runSetResult.attributes[key])

    def getRow(rowName, format, collapse=False, onlyIf=None):
        def formatCell(attributes):
            if onlyIf and not onlyIf in attributes:
                formatStr = 'Unknown'
            else:
                formatStr = format
            return formatStr.format(**attributes)

        values = [formatCell(runSetResult.attributes) for runSetResult in runSetResults]
        if not any(values): return None # skip row without values completely

        valuesAndWidths = list(Util.collapseEqualValues(values, runSetWidths)) \
                          if collapse else list(zip(values, runSetWidths))

        return tempita.bunch(id=rowName.lower().split(' ')[0],
                             name=rowName,
                             content=valuesAndWidths)

    benchmarkNames = [runSetResult.attributes['benchmarkname'] for runSetResult in runSetResults]
    allBenchmarkNamesEqual = benchmarkNames.count(benchmarkNames[0]) == len(benchmarkNames)

    titles      = [column.title for runSetResult in runSetResults for column in runSetResult.columns]
    runSetWidths1 = [1]*sum(runSetWidths)
    titleRow    = tempita.bunch(id='columnTitles', name=commonFileNamePrefix,
                                content=list(zip(titles, runSetWidths1)))

    return {'tool':    getRow('Tool', '{tool} {version}', collapse=True),
            'limit':   getRow('Limits', 'timelimit: {timelimit}, memlimit: {memlimit}, CPU core limit: {cpuCores}', collapse=True),
            'host':    getRow('Host', '{host}', collapse=True, onlyIf='host'),
            'os':      getRow('OS', '{os}', collapse=True, onlyIf='os'),
            'system':  getRow('System', 'CPU: {cpu} with {cores} cores, frequency: {freq}; RAM: {ram}', collapse=True, onlyIf='cpu'),
            'date':    getRow('Date of execution', '{date}', collapse=True),
            'runset':  getRow('Run set', '{name}' if allBenchmarkNamesEqual else '{benchmarkname}.{name}'),
            'branch':  getRow('Branch', '{branch}'),
            'options': getRow('Options', '{options}'),
            'title':   titleRow}
Ejemplo n.º 6
0
    def getRow(rowName, format, collapse=False, onlyIf=None):
        def formatCell(attributes):
            if onlyIf and not onlyIf in attributes:
                formatStr = 'Unknown'
            else:
                formatStr = format
            return formatStr.format(**attributes)

        values = [formatCell(runSetResult.attributes) for runSetResult in runSetResults]
        if not any(values): return None # skip row without values completely

        valuesAndWidths = list(Util.collapseEqualValues(values, runSetWidths)) \
                          if collapse else list(zip(values, runSetWidths))

        return tempita.bunch(id=rowName.lower().split(' ')[0],
                             name=rowName,
                             content=valuesAndWidths)
Ejemplo n.º 7
0
def get_summary(runSetResults):
    summaryStats = []
    available = False
    for runSetResult in runSetResults:
        for column in runSetResult.columns:
            if column.title in runSetResult.summary and runSetResult.summary[column.title] != '':
                available = True
                value = runSetResult.summary[column.title]
            else:
                value = ''
            summaryStats.append(StatValue(value))

    if available:
        return tempita.bunch(id=None, title='local summary',
            description='(This line contains some statistics from local execution. Only trust those values, if you use your own computer.)',
            content=summaryStats)
    else:
        return None
Ejemplo n.º 8
0
def getStats(rows):
    countFalse = len([row for row in rows if result.fileIsFalse(row.fileName)])
    countTrue = len([row for row in rows if result.fileIsTrue(row.fileName)])
    maxScore = result.SCORE_CORRECT_FALSE * countFalse + result.SCORE_CORRECT_TRUE * countTrue

    stats = [getStatsOfRunSet(runResults) for runResults in rowsToColumns(rows)] # column-wise
    rowsForStats = list(map(Util.flatten, zip(*stats))) # row-wise

    return [tempita.bunch(default=None, title='total files', content=rowsForStats[0]),
            tempita.bunch(default=None, title='correct results', description='(no bug exists + result is TRUE) OR (bug exists + result is FALSE)', content=rowsForStats[1]),
            tempita.bunch(default=None, title='false negatives', description='bug exists + result is TRUE', content=rowsForStats[2]),
            tempita.bunch(default=None, title='false positives', description='no bug exists + result is FALSE', content=rowsForStats[3]),
            tempita.bunch(default=None, title='false properties', description='bug exists + bug found, but not searched for it', content=rowsForStats[4]),
            tempita.bunch(default=None, title='score ({0} files, max score: {1})'.format(len(rows), maxScore), id='score', description='{0} true files, {1} false files'.format(countTrue, countFalse), content=rowsForStats[5])
            ]
Ejemplo n.º 9
0
def view_standings(environ):
    update_rc(environ)
    positive = []
    negative = []
    for (tid, subject, edittime, prefix, editor) in get_threads(standings_forums[environ["org"]]):
        p = parse_subject(subject)
        if p is None:
            continue
        (entity, ticker, standing, comments, internal) = p
        standing = normalize_standing(standing)
        if standing == 0:
            continue
        b = tempita.bunch(entity=entity,
                          ticker=ticker,
                          standing=standing,
                          comments=comments,
                          tid=tid)
        if standing > 0:
            positive.append(b)
        else:
            negative.append(b)
    positive.sort(lambda a, b: cmp(a.entity.lower(), b.entity.lower()))
    negative.sort(lambda a, b: cmp(a.entity.lower(), b.entity.lower()))
    form = cgi.FieldStorage()
    format = form.getfirst("format", "html")
    if (format == 'igb'
        or (format == 'html'
            and environ["HTTP_USER_AGENT"].startswith("EVE-minibrowser"))):
        return kgi.template_response('standings/list_igb.html',
                              positive=positive,
                              negative=negative)
    elif format == 'xml':
        return kgi.template_response('standings/list_xml.html',
                                     header=[('Content-Type', 'text/xml')],
                                     standings=positive + negative)
    else:
        return kgi.template_response('standings/list.html',
                                     user=environ['emapps.user'],
                                     current_time=eve_time(),
                                     positive=positive,
                                     negative=negative)
Ejemplo n.º 10
0
    def start_section(self, num_edges, num_vertices, intro=""):
        """
        Start a new section with the given title text.

        The `intro` text is printed between the title text and the
        ensuing list content.
        """
        if 'sections' not in self.data:
            self.data.sections = list()
        title = ("Fatgraphs with %(edges)s / %(vertices)s" % dict(
            edges = ("%d edges" % num_edges) if num_edges > 1 else "1 edge",
            vertices = ("%d vertices" % num_vertices) if num_vertices > 1 else "1 vertex",
            ))
        self._current_section = tempita.bunch(
            title=title,
            intro=intro,
            graphs=list(),
            )
        self._section_graphs = 0
        self._section_marked_graphs = 0
        self._section_orientable_marked_graphs = 0
Ejemplo n.º 11
0
def get_stats(rows):
    stats = parallel.map(get_stats_of_run_set, rows_to_columns(rows)) # column-wise
    rowsForStats = list(map(Util.flatten, zip(*stats))) # row-wise

    # Calculate maximal score and number of true/false files for the given properties
    count_true = count_false = max_score = 0
    for row in rows:
        if not row.properties:
            # properties missing for at least one task, result would be wrong
            count_true = count_false = 0
            logging.info('Missing property for %s.', row.filename)
            break
        correct_result = result.satisfies_file_property(row.filename, row.properties)
        if correct_result is True:
            count_true += 1
        elif correct_result is False:
            count_false += 1
        max_score += result.score_for_task(row.filename, row.properties, result.CATEGORY_CORRECT)
    task_counts = 'in total {0} true tasks, {1} false tasks'.format(count_true, count_false)

    if max_score:
        score_row = tempita.bunch(id='score',
                                  title='score ({0} tasks, max score: {1})'.format(len(rows), max_score),
                                  description=task_counts,
                                  content=rowsForStats[7])

    def indent(n):
        return '&nbsp;'*(n*4)

    return [tempita.bunch(id=None, title='total tasks', description=task_counts, content=rowsForStats[0]),
            tempita.bunch(id=None, title=indent(1)+'correct results', description='(property holds + result is true) OR (property does not hold + result is false)', content=rowsForStats[1]),
            tempita.bunch(id=None, title=indent(2)+'correct true', description='property holds + result is true', content=rowsForStats[2]),
            tempita.bunch(id=None, title=indent(2)+'correct false', description='property does not hold + result is false', content=rowsForStats[3]),
            tempita.bunch(id=None, title=indent(1)+'incorrect results', description='(property holds + result is false) OR (property does not hold + result is true)', content=rowsForStats[4]),
            tempita.bunch(id=None, title=indent(2)+'incorrect true', description='property does not hold + result is true', content=rowsForStats[5]),
            tempita.bunch(id=None, title=indent(2)+'incorrect false', description='property holds + result is false', content=rowsForStats[6]),
            ] + ([score_row] if max_score else [])
Ejemplo n.º 12
0
 def start_graph(self, name, graph, pool):
     """
     Start constructing the section relative to the given graph in the output.
     """
     assert num_orientable_markings >= 0
     num_orientable_markings = sum((1 if NG.is_oriented() else 0) for NG in pool)
     self._current_graph = graph
     self._current_marked_graph = pool[0]
     self._current_marked_graph_automorphisms = list(self._current_marked_graph.automorphisms())
     self._total_graphs += 1
     self._total_marked_graphs += len(pool)
     self._section_graphs += 1
     self._section_marked_graphs += len(pool)
     self._section_orientable_marked_graphs += num_orientable_markings
     self._current_graph_data = tempita.bunch(
         name=name,
         orientable=graph.is_oriented(),
         num_orientable_markings=num_orientable_markings,
         latex_repr=LaTeXOutput.render_to_xypic(graph, cross_out=False),
         python_repr=LaTeXOutput.render_to_python(graph),
         boundary_cycles=LaTeXOutput._fmt_boundary_cycles(graph.boundary_cycles)
         )
    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)
Ejemplo n.º 14
0
#snmp_auth = ""
#snmp_priv = ""
wifi_vlanid = yaml_conf['wifi']['vlan_id']

# Enable this if we cannot set special option82 tags
franken_net_switches = []

# If you have franken net, you need snmpv3 credentials to dist
# NOTE: THERE IS NO NEED TO USE THIS IF is_franken_net == False
snmpv3_username = ''
snmpv3_auth = ''
snmpv3_priv = ''

models = {}
for model in yaml_conf['models']:
    data = bunch(template=model['path'], eth=model['ports'])
    if 'image' in model:
        data.image = model['image']
    models.update({model['name']: data})

wifi_switches = yaml_conf['wifi']['switches']

# Files to be served as they are to all devices
static_files = {}
for sf in yaml_conf['static_files']:
    static_files.update(sf)

# ===============================================================
# Do not change below this if you do not know what you're doing!
# ===============================================================
Ejemplo n.º 15
0
#snmp_priv = ""
wifi_vlanid = yaml_conf['wifi']['vlan_id']

# Enable this if we cannot set special option82 tags
franken_net_switches = []

# If you have franken net, you need snmpv3 credentials to dist
# NOTE: THERE IS NO NEED TO USE THIS IF is_franken_net == False
snmpv3_username = ''
snmpv3_auth = ''
snmpv3_priv = ''

models = {}
for model in yaml_conf['models']:
    models.update(
        {model['name']: bunch(template=model['path'], eth=model['ports'])})

wifi_switches = yaml_conf['wifi']['switches']

# Files to be served as they are to all devices
static_files = {}
for sf in yaml_conf['static_files']:
    static_files.update(sf)

# ===============================================================
# Do not change below this if you do not know what you're doing!
# ===============================================================


def generate(switch, model_id):
    model = config.models[model_id]
titles_and_urls = sorted(all_talks_urls.items())

import tempita

# First create the information that will go in the file
topics = list()
for topic, loading in itertools.izip(nmf.components_, doc_loadings.T):
    frequencies = [(f, w) for f, w in itertools.izip(topic, feature_names)
                   if f != 0]
    frequencies.sort(reverse=True)
    titles = [(l, t) for l, t in itertools.izip(loading, titles_and_urls)
              if l != 0]
    titles.sort(reverse=True)
    talks = [
        tempita.bunch(
            title=t[0],
            url=t[1],
            description=(all_talks_description[t[0]] if
                         len(all_talks_description[t[0]].strip()) > 1 else ""))
        for l, t in titles
    ]
    topic_desc = tempita.bunch(first_word=frequencies[0][1],
                               second_word=frequencies[1][1],
                               talks=talks[:10])
    topics.append(topic_desc)

template = tempita.HTMLTemplate.from_filename('index_template.html')

html = template.substitute(topics=topics)
open(os.path.join(OUTPUT_DIR, 'index.html'), 'w').write(html)
Ejemplo n.º 17
0
#snmp_user = ""
#snmp_auth = ""
#snmp_priv = ""
wifi_vlanid = 851

# Enable this if we cannot set special option82 tags
franken_net_switches = [ ]

# If you have franken net, you need snmpv3 credentials to dist
# NOTE: THERE IS NO NEED TO USE THIS IF is_franken_net == False
snmpv3_username = ''
snmpv3_auth = ''
snmpv3_priv = ''

models = {
  "WS-C2950T-24"      : bunch(template="switchconfig/c2950t.cfg",eth=24),
  "WS-C2950G-24-EI"   : bunch(template="switchconfig/c2950t.cfg",eth=24),
  "WS-C2950T-48-SI"   : bunch(template="switchconfig/c2950t.cfg",eth=48),
  "WS-C2960G-48TC-L"  : bunch(template="switchconfig/c2960g.cfg",eth=48),
  "WS-C2960X-48TS-L"  : bunch(template="switchconfig/c2960x.cfg",eth=48),
}

wifi_switches = [ ]

#wifi_switches = [
#  "B01-A", "B05-A", "B10-A", "B16-A", "B22-C", "B26-C", "B31-C", "B37-C", 
#  "C04-A", "C08-A", "C12-A", "C17-C", "C21-C", "C25-C", "C29-C",
#  "D03-A", "D09-B", "D19-B", "D23-A", "D29-A", "D34-C", "D40-C", "D44-C", "D48-C", "D56-C", "D62-C"
#]

# Files to be served as they are to all devices
Ejemplo n.º 18
0
Name: {{ person["name"] | plus_filter }} Role: {{ person["role"] }} {{if person.has_key("blackhat") }} (Bad guy) {{else}} (Good guy) {{endif}}
{{endfor}}
"""
t = Template(template_string)

def plus_filter(s): return "++ " + s + " ++"

context_params = {
    "my_name" : "alice",
    "names" : [ "alice", "bob", "eve" ],
    "people" : [
        { "name" : "alice", "role" : "communicator" },
        { "name" : "bob", "role" : "communicator" },
        { "name" : "eve", "role" : "eavesdropper", "blackhat" : True },
        ],
    "a_bunch" : bunch(a=1,b=2,c=3),
    "plus_filter" : plus_filter,  # Make available as filter
}

print t.substitute(context_params)

print "\nDoing HTML subsitution..."

html_template_string="""
{{# A little counter-intuitive, but use 'html()' to substitute without quotes }}
<a href="{{ target_url | html }}">{{ target_name }}</a>
"""

t2 = HTMLTemplate(html_template_string)

context_params2 = {
Ejemplo n.º 19
0
titles_and_urls = sorted(all_talks_urls.items())

import tempita

# First create the information that will go in the file
topics = list()
for topic, loading in itertools.izip(nmf.components_, doc_loadings.T):
    frequencies = [(f, w)
                   for f, w in itertools.izip(topic, feature_names)
                   if f != 0]
    frequencies.sort(reverse=True)
    titles = [(l, t)
              for l, t in itertools.izip(loading, titles_and_urls)
              if l != 0]
    titles.sort(reverse=True)
    talks = [tempita.bunch(title=t[0], url=t[1],
              description=(all_talks_description[t[0]]
                           if len(all_talks_description[t[0]].strip()) > 1
                           else ""))
             for l, t in titles]
    topic_desc = tempita.bunch(first_word=frequencies[0][1],
                               second_word=frequencies[1][1],
                               talks=talks[:10])
    topics.append(topic_desc)

template = tempita.HTMLTemplate.from_filename('index_template.html')

html = template.substitute(topics=topics)
open(os.path.join(OUTPUT_DIR, 'index.html'), 'w').write(html)

Ejemplo n.º 20
0
#snmp_auth = ""
#snmp_priv = ""
wifi_vlanid = yaml_conf['wifi']['vlan_id']

# Enable this if we cannot set special option82 tags
franken_net_switches = [ ]

# If you have franken net, you need snmpv3 credentials to dist
# NOTE: THERE IS NO NEED TO USE THIS IF is_franken_net == False
snmpv3_username = ''
snmpv3_auth = ''
snmpv3_priv = ''

models = {}
for model in yaml_conf['models']:
  models.update({model['name']: bunch(template=model['path'],eth=model['ports'])})

wifi_switches = yaml_conf['wifi']['switches']

# Files to be served as they are to all devices
static_files = {}
for sf in yaml_conf['static_files']:
  static_files.update(sf)


# ===============================================================
# Do not change below this if you do not know what you're doing!
# ===============================================================

def generate(switch, model_id):
  model = config.models[model_id]