Changeset - 637ca012b778
[Not reviewed]
1 0 1
Brett Smith (brett) - 3 years ago 2018-05-04 20:05:32
brett@sfconservancy.org
policies: Extend publication script to handle any Conservancy policy.
1 file changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/projects/policies/publish-policy.py
Show inline comments
 
file renamed from www/conservancy/static/projects/policies/publish-travel-policy.py to www/conservancy/static/projects/policies/publish-policy.py
...
 
@@ -24,7 +24,7 @@ except ImportError:
 
    markdown_import_success = False
 

	
 
TEMPLATE_HEADER = """{% extends "base_projects.html" %}
 
{% block subtitle %}Travel and Reimburseable Expense Policy - {% endblock %}
 
{% block subtitle %}{% endblock %}
 
{% block submenuselection %}Policies{% endblock %}
 
{% block content %}
 

	
...
 
@@ -181,7 +181,7 @@ Setting any flag will always override the default behavior.
 
    )
 
    add_parser_flag(
 
        parser, 'commit',
 
        help="Commit changes to the travel policy",
 
        help="Commit changes to the website repository",
 
    )
 
    parser.add_argument(
 
        '-m', dest='commit_message',
...
 
@@ -194,7 +194,7 @@ Setting any flag will always override the default behavior.
 
    )
 
    parser.add_argument(
 
        'input_path', type=pathlib.Path,
 
        help="Path to the Conservancy travel policy Markdown source",
 
        help="Path to the Conservancy policy Markdown source",
 
    )
 
    parser.add_argument(
 
        'output_path', type=pathlib.Path,
...
 
@@ -221,7 +221,7 @@ Try `apt install python3-markdown` or `python3 -m pip install --user Markdown`."
 
            pass
 
        if args.revision is None:
 
            parser.error("no --revision specified and not found from input path")
 
    args.output_link_path = args.git_output.dir_path / 'conservancy-travel-policy.html'
 
    args.output_link_path = args.git_output.dir_path / args.input_path.with_suffix('.html').name
 
    args.output_file_path = args.output_link_path.with_suffix('.{}.html'.format(args.revision))
 
    return args
 

	
...
 
@@ -299,7 +299,17 @@ def write_output(args):
 
        ],
 
        output_format='html5',
 
    )
 
    header = TEMPLATE_HEADER
 
    with args.input_path.open(encoding=args.encoding) as src_file:
 
        for line in src_file:
 
            if line.startswith('# '):
 
                subtitle = line[2:].replace('Software Freedom Conservancy', '').strip()
 
                header = header.replace(
 
                    '{% block subtitle %}',
 
                    '{{% block subtitle %}}{} - '.format(subtitle),
 
                )
 
                break
 
        src_file.seek(0)
 
        body = converter.convert(src_file.read())
 
    with tempfile.NamedTemporaryFile(
 
            'w',
...
 
@@ -309,7 +319,7 @@ def write_output(args):
 
            delete=False,
 
    ) as tmp_out:
 
        try:
 
            tmp_out.write(TEMPLATE_HEADER)
 
            tmp_out.write(header)
 
            tmp_out.write(body)
 
            tmp_out.write(TEMPLATE_FOOTER)
 
            tmp_out.flush()
0 comments (0 inline, 0 general)