Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,64 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% import 'ConfluenceWiki_Utilities.jinja' as Utils -%}
{% macro WriteClass(uuid, class)%}
{# Header #}
h1. {{ Utils.Sanitize(class.Name) }} {anchor:{{ Utils.ClearBraces(uuid) }}}
{{Utils.Sanitize(class.Description)}}
_Id_: {{ Utils.Sanitize(class.Id) }}
_Uuid_: {{ Utils.Sanitize(uuid) }}
{# Bases #}
{% if class.Bases is defined %}
_Bases_:
{% for base in class.Bases %}
* {{ Utils.Link(SerializeContext, Config, Utils.Sanitize(base.Type), base.Uuid) }}
{% endfor %}
{% endif -%}
{# Generics #}
{% if class.Generics is defined %}
_Generics_:
{% for generic in class.Generics %}
* {{ Utils.Link(SerializeContext, Config, Utils.Sanitize(generic.Type), generic.SpecializedUuid) }}
{% endfor %}
{% endif %}
{# Fields #}
{% if class.Fields is defined %}
||Name||Type||Description||
{% for field in class.Fields %}
|{{ Utils.Sanitize(field.Name) }}|{{ Utils.Link(SerializeContext, Config, Utils.Sanitize(field.Type), field.Uuid) }}|{{Utils.Sanitize(field.Description)}} |
{% endfor %}
{% endif -%}
----
{% endmacro -%}
{expand:Table of contents}
{toc}
{expand}
{info}
This document is automatically generated using the template '{{ self._TemplateReference__context.name }}'
{info}
{% for uuid, class in SerializeContext.items()|sort(attribute='1.Name') %}
{% if Config.Filter is defined %}
{% if class.Name.startswith(Config.Filter|lower) or class.Name.startswith(Config.Filter|upper)%}
{{- WriteClass(uuid, class) }}
{% endif %}
{% else %}
{{- WriteClass(uuid, class) }}
{% endif %}
{% endfor %}
@@ -0,0 +1,29 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{#- This module requires the following additional arguments:
# --parentdoc <name> : Name of the parent doc containing the Serialize Context information
# --issplit <true|false> : Whether or not the parent doc is one document or split over multiple files.
-#}
{%- import 'ConfluenceWiki_Utilities.jinja' as Utils -%}
{info}
This document is automatically generated using the template '{{ self._TemplateReference__context.name }}'
{info}
h1. System Components:
{% for uuid, class in SerializeContext.items()|sort(attribute='1.Name') %}
{% if class.IsSystemComponent %}
* {{ Utils.PrintNamedLink(SerializeContext, uuid, class, Config.issplit, Config.parentdoc) -}}
{% endif %}
{% endfor %}
@@ -0,0 +1,53 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% macro Sanitize(text) -%}
{{text|replace('{', '&#123;')|replace('}', '&#125;')|replace('[', '&#91;')|replace(']', '&#93;')}}
{%- endmacro -%}
{% macro ClearBraces(text) -%}
{{text|replace('{', '')|replace('}', '')}}
{%- endmacro -%}
{%- macro LinkParent(context, isSplit, parentDoc, alias, uuid) -%}
{%- if context[uuid] is defined -%}
{%- if isSplit -%}
[{{ alias }}|{{ parentDoc }} {{ context[uuid].Name[0]|upper }}#{{ ClearBraces(uuid) }}]
{%- else -%}
[{{ alias }}|{{ parentDoc }}#{{ ClearBraces(uuid) }}]
{%- endif -%}
{%- else -%}
{{ alias }}
{%- endif -%}
{%- endmacro -%}
{%- macro Link(context, config, alias, uuid) -%}
{%- if config.Filter is defined -%}
{%- set isSplit = true -%}
{%- else -%}
{%- set isSplit = false -%}
{%- endif -%}
{{- LinkParent(context, isSplit, config.Document, alias, uuid) -}}
{%- endmacro -%}
{%- macro PrintNamedLink(context, uuid, class, isSplit, parentDoc) -%}
{% if class.Namespace is defined -%}
{% set className = "{0}::{1}".format(class.Namespace, class.Name) %}
{% else -%}
{% set className = class.Name %}
{% endif -%}
{% if class.Id == className -%}
{{ LinkParent(context, isSplit, parentDoc, Sanitize(className), uuid) }}
{% else -%}
{{ LinkParent(context, isSplit, parentDoc, Sanitize(className), uuid) }} - {{ Sanitize(class.Id) }}
{% endif -%}
{%- endmacro -%}
@@ -0,0 +1,124 @@
########################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
########################################################################################
import argparse
import getopt
import jinja2
import json
import string
import os
# Creates the folder at the given path is it doesn't already exist.
def CreateOutputFolder(path):
folderPath = os.path.dirname(path)
if not os.path.exists(folderPath):
try:
os.mkdir(folderPath)
except OSError:
print "Failed to create path '{0}'".format(folderPath)
return False
return True
# Function to check if a type is derived from one of the provided classes.
def IsDerivedFrom(context, classInfo, derivedType):
bases = classInfo.get('Bases', [])
for base in bases:
baseUuid = base.get('Uuid')
if baseUuid is not None:
if baseUuid == derivedType:
return True
else:
baseClassInfo = context.get(baseUuid)
if baseClassInfo is not None:
if IsDerivedFrom(context, baseClassInfo, derivedType):
return True
return False
# A Jinja2 filter function that filters any type that's not one of the provided types.
def FilterByBase(context, type):
result = {}
for uuid, classInfo in context.items():
if uuid == type or IsDerivedFrom(context, classInfo, type):
result[uuid] = classInfo
return result
def ParseAdditionalArguments(dict, arguments):
currentArg = None
for arg in arguments:
if arg[:2] == '--' or arg[:1] == '-':
if currentArg is not None:
dict[currentArg] = True
if arg[:2] == '--':
currentArg = arg[2:]
elif arg[:1] == '-':
currentArg = arg[1:]
else:
if currentArg is not None:
dict[currentArg] = arg
currentArg = None
if currentArg is not None:
dict[currentArg] = True
# Convert the json formatted Serialize Context through the provided Jinja2 template.
def Convert(source, output, template, split, additionalArgs):
with open(source) as jsonFile:
data = json.load(jsonFile)
jinjaEnvironment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(template)), trim_blocks=True, lstrip_blocks=True)
jinjaEnvironment.filters['FilterByBase'] = FilterByBase
renderer = jinjaEnvironment.get_template(os.path.basename(template))
path, extension = os.path.splitext(output);
file = os.path.basename(path)
data['Config'] = {}
data['Config']['Document'] = file
ParseAdditionalArguments(data['Config'], additionalArgs)
print "Template arguments: {}".format(data['Config'])
if split:
for c in string.ascii_lowercase:
data['Config']['Filter'] = c
outputFilePath = "{0} {1}{2}".format(path, c, extension)
rendering = renderer.render(data)
with open(outputFilePath, 'w') as outputFile:
outputFile.write(rendering)
else:
rendering = renderer.render(data)
with open(output, 'w') as outputFile:
outputFile.write(rendering)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Takes a json-formatted dump of the Serialize Context and runs it through the provided Jinja2 templates.')
parser.add_argument('--source', help='Path to the json file containing the output of the SerializeContext.', required=True)
parser.add_argument('--output', help='Path to the file to write the converted result to.', required=True)
parser.add_argument('--template', help='Path to the Jinja2 template to use for the conversion.', required=True)
parser.add_argument('--split', help='Only include entries that start with this letter.', action='store_true')
args, remainingArgs = parser.parse_known_args()
sourcePath = args.source
if not os.path.isabs(sourcePath):
sourcePath = os.path.abspath(sourcePath)
outputPath = args.output
if not os.path.isabs(outputPath):
outputPath = os.path.abspath(outputPath)
templatePath = args.template
if not os.path.isabs(templatePath):
templatePath = os.path.abspath(templatePath)
if CreateOutputFolder(outputPath):
print 'Converting from "{0}" to "{1}" using template "{2}".'.format(sourcePath, outputPath, templatePath)
Convert(sourcePath, outputPath, templatePath, args.split, remainingArgs)
@@ -0,0 +1,22 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% import 'Text_Utilities.jinja' as Utils -%}
{% set FilteredCompontents = SerializeContext|FilterByBase('{EDFCB2CF-F75D-43BE-B26B-F35821B29247}') %}
{% set FilteredEntities = SerializeContext|FilterByBase('{75651658-8663-478D-9090-2432DFCAFA44}') %}
{% set FilteredContext = dict(FilteredCompontents.items() + FilteredEntities.items()) %}
{% for uuid, class in FilteredContext.items()|sort(attribute='1.Name') %}
{{- Utils.PrintName(uuid, class) }}
{{- Utils.PrintClassContent(SerializeContext, 2, uuid) }}
{{- safe }}
{% endfor %}
@@ -0,0 +1,19 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% import 'Text_Utilities.jinja' as Utils -%}
{% for uuid, class in SerializeContext.items()|sort(attribute='1.Name') %}
{{- Utils.PrintName(uuid, class) }}
{{- Utils.PrintClassContent(SerializeContext, 2, uuid) -}}
{{- safe }}
{% endfor %}
@@ -0,0 +1,21 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% import 'Text_Utilities.jinja' as Utils -%}
{% for uuid, class in SerializeContext.items()|sort(attribute='1.Name') %}
{% if class.IsSystemComponent %}
{{- Utils.PrintName(uuid, class) }}
{{- Utils.PrintClassContent(SerializeContext, 2, uuid) -}}
{{- safe }}
{% endif %}
{% endfor %}
@@ -0,0 +1,17 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% import 'Text_Utilities.jinja' as Utils -%}
{% for uuid, class in SerializeContext.items()|sort(attribute='1.Name') %}
{{- Utils.PrintName(uuid, class) -}}
{% endfor %}
@@ -0,0 +1,43 @@
{#######################################################################################
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
#####################################################################################-#}
{% macro PrintName(uuid, class) %}
{% if class.Namespace is defined %}
{% set className = "{0}::{1}".format(class.Namespace, class.Name) %}
{% else %}
{% set className = class.Name %}
{% endif %}
{% if class.Id == className %}
{{ uuid }} - {{class.Id}}
{% else %}
{{ uuid }} - {{class.Id}} - {{className}}
{% endif %}
{%- endmacro -%}
{% macro PrintPrimitive(context, uuid) %}
{% if context[uuid] is defined and context[uuid].IsPrimitive %}
[Primitive]
{%- endif -%}
{%- endmacro -%}
{% macro PrintClassContent(context, indention, uuid) %}
{% if context[uuid] is defined %}
{% for base in context[uuid].Bases -%}
{{ ' '|safe*indention}}{{ base.Type }} [Base]
{{ PrintClassContent(context, indention + 2, base.Uuid) -}}
{% endfor -%}
{% for field in context[uuid].Fields -%}
{{ ' '|safe*indention}}{{ field.Type }} {{ field.Name }} {{ PrintPrimitive(context, field.Uuid) }}
{{ PrintClassContent(context, indention + 2, field.Uuid) -}}
{% endfor -%}
{% endif -%}
{% endmacro -%}