Beispiel #1
0
    def __init__(self):
        self.title = 'HTML Tag'
        #from string import Template
        #self._t = Template('<$tag class="$class">\n</$tag>')
        from jinja import from_string
        self._t = from_string(
            """<{{ tag }}{% if class %} class="{{ class }}"{% endif %}>\n</{{ tag }}>"""
        )

        #self._defaults = {'class': '', 'extra': ''}
        self._t = from_string('''
{#
This is a comment
#}
class {{ name }}({% if super %}{{ super }}{% else %}object{% endif %}):
{% if docstring %}    """{{ docstring }}"""\n{% endif %}
    def __init__(self):
''')
Beispiel #2
0
    def __init__(self):
        self.title = 'HTML Tag'
        #from string import Template
        #self._t = Template('<$tag class="$class">\n</$tag>')
        from jinja import from_string
        self._t = from_string("""<{{ tag }}{% if class %} class="{{ class }}"{% endif %}>\n</{{ tag }}>""")

        #self._defaults = {'class': '', 'extra': ''}
        self._t = from_string(
'''
{#
This is a comment
#}
class {{ name }}({% if super %}{{ super }}{% else %}object{% endif %}):
{% if docstring %}    """{{ docstring }}"""\n{% endif %}
    def __init__(self):
'''
)
Beispiel #3
0
def handle_html(filename, fp, dst):
    now = datetime.now()
    title = os.path.basename(filename)[:-4]
    content = fp.read()
    c = generate_documentation(content, (lambda x: './%s.html' % x))
    result = file(os.path.join(dst, title + '.html'), 'w')
    c['style'] = STYLESHEET + PYGMENTS_FORMATTER.get_style_defs('.syntax')
    c['generation_date'] = now
    c['file_id'] = title
    t = from_string(TEMPLATE)
    result.write(t.render(c).encode('utf-8'))
    result.close()
def output_spotlight_config(row, args):
    data = open("spotlight-config/content-dashboard-template.json").read()
    data = data.decode("utf8")

    template = jinja.from_string(data)

    try:
        os.makedirs("spotlight-config/output")
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    if "feedback_abbrev" not in row:
        row["feedback_abbrev"] = row["dept_abbrev"].lower()

    fmt = "spotlight-config/output/site-activity-{dept_slug}.json"
    path = fmt.format(**row)
    with open(path, "w") as fd:
        fd.write(template.render(**row).encode("utf8"))
Beispiel #5
0
def output_spotlight_config(row, args):
    data = open("spotlight-config/content-dashboard-template.json").read()
    data = data.decode("utf8")

    template = jinja.from_string(data)

    try:
        os.makedirs("spotlight-config/output")
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    if "feedback_abbrev" not in row:
        row["feedback_abbrev"] = row["dept_abbrev"].lower()

    fmt = "spotlight-config/output/site-activity-{dept_slug}.json"
    path = fmt.format(**row)
    with open(path, "w") as fd:
        fd.write(template.render(**row).encode("utf8"))
 def format_template(template, **kw):
     return jinja.from_string(template, **kw)
Beispiel #7
0
 def format_template(template, **kw):
     return jinja.from_string(template, **kw)
Beispiel #8
0
            lines = ['']
        else:
            lines = ['.. code-block:: python', '']
        lines += ['    %s' % row.rstrip() for row in code.split('\n')]
        source_code = "\n".join(lines)
    else:
        source_code = ""

    opts = [
        ':%s: %s' % (key, val) for key, val in options.items()
        if key in ('alt', 'height', 'width', 'scale', 'align', 'class')
    ]

    result = jinja.from_string(TEMPLATE).render(link_dir=link_dir.replace(
        os.path.sep, '/'),
                                                source_link=source_link,
                                                options=opts,
                                                image_names=image_names,
                                                source_code=source_code)

    lines = result.split("\n")
    if len(lines):
        state_machine.insert_input(lines, state_machine.input_lines.source(0))

    return []


if hasattr(os.path, 'relpath'):
    relpath = os.path.relpath
else:

    def relpath(target, base=os.curdir):
Beispiel #9
0
    if options['include-source']:
        if is_doctest:
            lines = ['']
        else:
            lines = ['.. code-block:: python', '']
        lines += ['    %s' % row.rstrip() for row in code.split('\n')]
        source_code = "\n".join(lines)
    else:
        source_code = ""

    opts = [':%s: %s' % (key, val) for key, val in options.items()
            if key in ('alt', 'height', 'width', 'scale', 'align', 'class')]

    result = jinja.from_string(TEMPLATE).render(
        link_dir=link_dir.replace(os.path.sep, '/'),
        source_link=source_link,
        options=opts,
        image_names=image_names,
        source_code=source_code)

    lines = result.split("\n")
    if len(lines):
        state_machine.insert_input(
            lines, state_machine.input_lines.source(0))

    return []


if hasattr(os.path, 'relpath'):
    relpath = os.path.relpath
else:
    def relpath(target, base=os.curdir):
def output_ga_collector_config(row, args):

    template = jinja.from_string(
        open("collector-config/ga-collector-template.json").read())

    def split(sep, what):
        if not what:
            return []

        def strip(x):
            x = x.strip()
            if x.startswith("ga:"):
                x = x[len("ga:"):]
            if x.startswith("-ga:"):
                x = "-" + x[len("-ga:"):]
            return x
        return [strip(x) for x in what.split(sep)]

    metrics = split(",", row["Metrics"])
    dimensions = split(",", row["Dimensions"])
    filters = split(";", row["Filters"])
    sort = split(";", row["Sort"])

    if sort == ["date"]:
        sort = []

    def fix_filter(f):
        if "{{departments}}" not in f:
            return f

        DEPARTMENTS = ("D1|D2|D3|D4|D5|D6|D7|D8|D9|D10|D11|D12|D13|D14|D15|D16"
                       "|D17|D18|D19|D23|D24|D25|EA74|EA75|EA79|OT532|OT537"
                       "|D20|D21|D22|D241|D117|EA199|D98|EA321|OT554|EA570")
        return f.replace("{{departments}}", "<({})>".format(DEPARTMENTS))

    filters = [fix_filter(f) for f in filters]

    if not metrics:
        print "Skipping {} (no metrics)".format(row["dataType"])
        return

    row["ga_id"] = args["<ga-id>"]
    row["metrics"] = json.dumps(metrics)
    row["dimensions"] = json.dumps(dimensions)
    row["filters"] = json.dumps(filters)
    row["sort"] = json.dumps(sort)
    row["maxResults"] = row["maxResults"] or 0

    # Hardwired in template
    if "customVarValue9" in dimensions:
        dimensions.remove("customVarValue9")

    row["id_params"] = ", ".join("'{}'".format(m) for m in dimensions)

    def agg(m):
        func = "aggregate_count"
        return "{}('{}')".format(func, m)

    row["aggregation_params"] = ", ".join(agg(m) for m in metrics)

    row["bearer_token"] = args["<bearer-token>"]
    row["backdrop_target"] = args["<backdrop-target>"]

    fmt = "{dataGroup}_{dataType}"
    row["bucket_name"] = fmt.format(**row).replace("-", "_")

    # If we need to have many filtersets
    row["separateQueries"] = make_bool(row.get("separateQueries"))

    try:
        os.makedirs("collector-config/output")
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    # Data type must be -'ified
    row["dataType"] = row["dataType"].replace("_", "-")

    path = "collector-config/output/{}.json".format(row["bucket_name"])
    with open(path, "w") as fd:
        fd.write(template.render(**row))
def run(arguments, content, options, state_machine, state, lineno):
    if arguments and content:
        raise RuntimeError("plot:: directive can't have both args and content")

    document = state_machine.document
    config = document.settings.env.config

    options.setdefault('include-source', config.plot_include_source)
    if options['include-source'] is None:
        options['include-source'] = config.plot_include_source

    # determine input
    rst_file = document.attributes['source']
    rst_dir = os.path.dirname(rst_file)

    if arguments:
        file_name = os.path.join(rst_dir, directives.uri(arguments[0]))
        code = open(file_name, 'r').read()
        output_base = os.path.basename(file_name)
    else:
        file_name = rst_file
        code = textwrap.dedent("\n".join(map(str, content)))
        counter = document.attributes.get('_plot_counter', 0) + 1
        document.attributes['_plot_counter'] = counter
        output_base = '%d-%s' % (counter, os.path.basename(file_name))

    rel_name = relative_path(file_name, setup.confdir)

    base, ext = os.path.splitext(output_base)
    if ext in ('.py', '.rst', '.txt'):
        output_base = base

    # is it in doctest format?
    is_doctest = contains_doctest(code)
    if options.has_key('format'):
        if options['format'] == 'python':
            is_doctest = False
        else:
            is_doctest = True

    # determine output
    file_rel_dir = os.path.dirname(rel_name)
    while file_rel_dir.startswith(os.path.sep):
        file_rel_dir = file_rel_dir[1:]

    output_dir = os.path.join(setup.confdir, setup.config.plot_output_dir,
                              file_rel_dir)

    if not os.path.exists(output_dir):
        cbook.mkdirs(output_dir)

    # copy script
    target_name = os.path.join(output_dir, output_base)
    f = open(target_name, 'w')
    f.write(unescape_doctest(code))
    f.close()

    source_link = relative_path(target_name, rst_dir)

    # determine relative reference
    link_dir = relative_path(output_dir, rst_dir)

    # make figures
    num_figs = makefig(code, file_name, output_dir, output_base, config)

    # generate output
    if options['include-source']:
        if is_doctest:
            lines = ['']
        else:
            lines = ['.. code-block:: python', '']
        lines += ['    %s' % row.rstrip() for row in code.split('\n')]
        source_code = "\n".join(lines)
    else:
        source_code = ""

    if num_figs > 0:
        image_names = []
        for i in range(num_figs):
            if num_figs == 1:
                image_names.append(output_base)
            else:
                image_names.append("%s_%02d" % (output_base, i))
    else:
        reporter = state.memo.reporter
        sm = reporter.system_message(3,
                                     "Exception occurred rendering plot",
                                     line=lineno)
        return [sm]

    opts = [
        ':%s: %s' % (key, val) for key, val in options.items()
        if key in ('alt', 'height', 'width', 'scale', 'align', 'class')
    ]

    result = jinja.from_string(TEMPLATE).render(link_dir=link_dir.replace(
        os.path.sep, '/'),
                                                source_link=source_link,
                                                options=opts,
                                                image_names=image_names,
                                                source_code=source_code)

    lines = result.split("\n")
    if len(lines):
        state_machine.insert_input(lines, state_machine.input_lines.source(0))
    return []
 def __init__(self):
   self.root = "/home/hevi"
   self.session = session.Session()
   self.reg_render_tmpl = jinja.from_string(_reg_render_tmpl)
   self.dir_render_tmpl = jinja.from_string(_dir_render_tmpl)
   self.page_render_tmpl = jinja.from_string(_page_render_tmpl)
 def __init__(self):
     self.root = "/home/hevi"
     self.session = session.Session()
     self.reg_render_tmpl = jinja.from_string(_reg_render_tmpl)
     self.dir_render_tmpl = jinja.from_string(_dir_render_tmpl)
     self.page_render_tmpl = jinja.from_string(_page_render_tmpl)
Beispiel #14
0
import locale
from termcolor import colored
import settings
from colorama import init

init()

os.environ['OPENSSL_CONF'] = './openssl.cnf'

encoding = locale.getdefaultlocale()[1]

OPENSSL_OUTPUT_COLOR = 'magenta'

# Create openssl.cnf file
import jinja
template = jinja.from_string(open('openssl.cnf.template').read())
cnf = template.render(BEE2EVP_ENGINE_LIBRARY_PATH=settings.BEE2EVP_ENGINE_LIBRARY_PATH)
cnf_file = open('openssl.cnf', 'w')
cnf_file.write(cnf)
cnf_file.close()
#########################


def openssl_call(cmd):

    print(colored('openssl ' + cmd, 'green'))
    p = subprocess.Popen(settings.OPENSSL_EXE_PATH + ' ' + cmd,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         shell=True)
Beispiel #15
0
def output_ga_collector_config(row, args):

    template = jinja.from_string(
        open("collector-config/ga-collector-template.json").read())

    def split(sep, what):
        if not what:
            return []

        def strip(x):
            x = x.strip()
            if x.startswith("ga:"):
                x = x[len("ga:"):]
            if x.startswith("-ga:"):
                x = "-" + x[len("-ga:"):]
            return x

        return [strip(x) for x in what.split(sep)]

    metrics = split(",", row["Metrics"])
    dimensions = split(",", row["Dimensions"])
    filters = split(";", row["Filters"])
    sort = split(";", row["Sort"])

    if sort == ["date"]:
        sort = []

    def fix_filter(f):
        if "{{departments}}" not in f:
            return f

        DEPARTMENTS = ("D1|D2|D3|D4|D5|D6|D7|D8|D9|D10|D11|D12|D13|D14|D15|D16"
                       "|D17|D18|D19|D23|D24|D25|EA74|EA75|EA79|OT532|OT537"
                       "|D20|D21|D22|D241|D117|EA199|D98|EA321|OT554|EA570")
        return f.replace("{{departments}}", "<({})>".format(DEPARTMENTS))

    filters = [fix_filter(f) for f in filters]

    if not metrics:
        print "Skipping {} (no metrics)".format(row["dataType"])
        return

    row["ga_id"] = args["<ga-id>"]
    row["metrics"] = json.dumps(metrics)
    row["dimensions"] = json.dumps(dimensions)
    row["filters"] = json.dumps(filters)
    row["sort"] = json.dumps(sort)
    row["maxResults"] = row["maxResults"] or 0

    # Hardwired in template
    if "customVarValue9" in dimensions:
        dimensions.remove("customVarValue9")

    row["id_params"] = ", ".join("'{}'".format(m) for m in dimensions)

    def agg(m):
        func = "aggregate_count"
        return "{}('{}')".format(func, m)

    row["aggregation_params"] = ", ".join(agg(m) for m in metrics)

    row["bearer_token"] = args["<bearer-token>"]
    row["backdrop_target"] = args["<backdrop-target>"]

    fmt = "{dataGroup}_{dataType}"
    row["bucket_name"] = fmt.format(**row).replace("-", "_")

    # If we need to have many filtersets
    row["separateQueries"] = make_bool(row.get("separateQueries"))

    try:
        os.makedirs("collector-config/output")
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    # Data type must be -'ified
    row["dataType"] = row["dataType"].replace("_", "-")

    path = "collector-config/output/{}.json".format(row["bucket_name"])
    with open(path, "w") as fd:
        fd.write(template.render(**row))
template = from_string(u'''\
<h1>Unfilled</h1>
<div class="index">
  {%- for column in items|slice(3) %}
  <div class="col-{{ loop.index }}">
    <ul>
    {%- for item in column %}
      <li>{{ item }}</li>
    {%- endfor %}
    </ul>
  </div>
  {%- endfor %}
</div>

<h1>Filled</h1>
<div class="index">
  {%- for column in items|slice(3, 'missing') %}
  <div class="col-{{ loop.index }}">
    <ul>
    {%- for item in column %}
      <li>{{ item }}</li>
    {%- endfor %}
    </ul>
  </div>
  {%- endfor %}
</div>

<h1>Filled Table</h1>
<table>
  {%- for row in items|batch(3, '&nbsp;') %}
  <tr>
    {%- for column in row %}
    <td>{{ column }}</td>
    {%- endfor %}
  </tr>
  {%- endfor %}
</table>

<h1>Unfilled Table</h1>
<table>
  {%- for row in items|batch(3) %}
  <tr>
    {%- for column in row %}
    <td>{{ column }}</td>
    {%- endfor %}
    {%- if row|length < 3 %}
    <td colspan="{{ 3 - (row|length) }}">&nbsp;</td>
    {%- endif %}
  </tr>
  {%- endfor %}
</table>''')