Embed client and server release numbers

Note that this also removes the changelog - I'm going to re-add the
changelog differently soon.
This commit is contained in:
Daniel Wagner-Hall 2015-12-01 17:02:23 +00:00
parent bcead3b0a5
commit 97fd1fdd62
6 changed files with 73 additions and 42 deletions

View file

@ -44,6 +44,7 @@ import importlib
import json
import logging
import os
import re
import sys
from textwrap import TextWrapper
@ -56,7 +57,7 @@ def check_unaccessed(name, store):
log("Found %s unused %s keys." % (len(unaccessed_keys), name))
log(unaccessed_keys)
def main(input_module, file_stream=None, out_dir=None, verbose=False):
def main(input_module, file_stream=None, out_dir=None, verbose=False, substitutions={}):
if out_dir and not os.path.exists(out_dir):
os.makedirs(out_dir)
@ -167,6 +168,12 @@ def main(input_module, file_stream=None, out_dir=None, verbose=False):
temp = Template(temp_str)
log("Creating output for: %s" % file_stream.name)
output = create_from_template(temp, sections)
# Do these substitutions outside of the ordinary templating system because
# we want them to apply to things like the underlying swagger used to
# generate the templates, not just the top-level sections.
for old, new in substitutions.items():
output = output.replace(old, new)
with open(
os.path.join(out_dir, os.path.basename(file_stream.name)), "w"
) as f:
@ -209,6 +216,10 @@ if __name__ == '__main__':
"--verbose", "-v", action="store_true",
help="Turn on verbose mode."
)
parser.add_argument(
"--substitution", action="append",
help="Substitutions to apply to the generated output, of form NEEDLE=REPLACEMENT."
)
args = parser.parse_args()
if args.verbose:
@ -226,7 +237,14 @@ if __name__ == '__main__':
parser.print_help()
sys.exit(1)
substitutions = {}
for substitution in args.substitution:
parts = substitution.split("=", 1)
if len(parts) != 2:
raise Exception("Invalid substitution")
substitutions[parts[0]] = parts[1]
main(
args.input, file_stream=args.file, out_dir=args.out_directory,
verbose=args.verbose
substitutions=substitutions, verbose=args.verbose
)

View file

@ -15,10 +15,6 @@ class MatrixSections(Sections):
def render_git_rev(self):
return self.units.get("git_version")["revision"]
def render_spec_version(self):
spec_meta = self.units.get("spec_meta")
return spec_meta["version"]
def render_spec_changelog(self):
spec_meta = self.units.get("spec_meta")
return spec_meta["changelog"]

View file

@ -18,8 +18,8 @@ import urllib
import yaml
HTTP_APIS = "../api/client-server"
V1_EVENT_EXAMPLES = "../event-schemas/examples"
V1_EVENT_SCHEMA = "../event-schemas/schema"
EVENT_EXAMPLES = "../event-schemas/examples"
EVENT_SCHEMA = "../event-schemas/schema"
CORE_EVENT_SCHEMA = "../event-schemas/schema/core-event-schema"
CHANGELOG = "../CHANGELOG.rst"
TARGETS = "../specification/targets.yaml"
@ -605,7 +605,7 @@ class MatrixUnits(Units):
return event_types
def load_event_examples(self):
path = V1_EVENT_EXAMPLES
path = EVENT_EXAMPLES
examples = {}
for filename in os.listdir(path):
if not filename.startswith("m."):
@ -622,7 +622,7 @@ class MatrixUnits(Units):
return examples
def load_event_schemas(self):
path = V1_EVENT_SCHEMA
path = EVENT_SCHEMA
schemata = {}
for filename in os.listdir(path):
@ -714,7 +714,6 @@ class MatrixUnits(Units):
def load_spec_meta(self):
path = CHANGELOG
title_part = None
version = None
changelog_lines = []
with open(path, "r") as f:
prev_line = None
@ -738,19 +737,11 @@ class MatrixUnits(Units):
break
changelog_lines.append(line)
# parse out version from title
for word in title_part.split():
if re.match("^v[0-9\.]+$", word):
version = word[1:] # strip the 'v'
self.log("Version: %s Title part: %s Changelog line count: %s" % (
version, title_part, len(changelog_lines)
self.log("Title part: %s Changelog line count: %s" % (
title_part, len(changelog_lines)
))
if not version or len(changelog_lines) == 0:
raise Exception("Failed to parse CHANGELOG.rst")
return {
"version": version,
"changelog": "".join(changelog_lines)
}