Moving o3de registration scripts to the scripts/o3de folder
This commit is contained in:
Executable
+2438
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,168 @@
|
||||
#
|
||||
# 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 logging
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import pathlib
|
||||
import json
|
||||
import cmake.Tools.registration as registration
|
||||
|
||||
logger = logging.getLogger()
|
||||
logging.basicConfig()
|
||||
|
||||
|
||||
def set_global_project(project_name: str or None,
|
||||
project_path: str or pathlib.Path or None) -> int:
|
||||
"""
|
||||
set what the current project is
|
||||
:param project_name: the name of the project you want to set, resolves project_path
|
||||
:param project_path: the path of the project you want to set
|
||||
:return: 0 for success or non 0 failure code
|
||||
"""
|
||||
if project_path and project_name:
|
||||
logger.error(f'Project Name and Project Path provided, these are mutually exclusive.')
|
||||
return 1
|
||||
|
||||
if not project_name and not project_path:
|
||||
logger.error('Must specify either a Project name or Project Path.')
|
||||
return 1
|
||||
|
||||
if project_name and not project_path:
|
||||
project_path = registration.get_registered(project_name=project_name)
|
||||
|
||||
if not project_path:
|
||||
logger.error(f'Project Path {project_path} has not been registered.')
|
||||
return 1
|
||||
|
||||
project_path = pathlib.Path(project_path).resolve()
|
||||
|
||||
bootstrap_setreg_file = registration.get_o3de_registry_folder() / 'bootstrap.setreg'
|
||||
if bootstrap_setreg_file.is_file():
|
||||
with bootstrap_setreg_file.open('r') as f:
|
||||
try:
|
||||
json_data = json.load(f)
|
||||
except Exception as e:
|
||||
logger.error(f'Bootstrap.setreg failed to load: {str(e)}')
|
||||
else:
|
||||
try:
|
||||
json_data["Amazon"]["AzCore"]["Bootstrap"]["project_path"] = project_path
|
||||
except Exception as e:
|
||||
logger.error(f'Bootstrap.setreg failed to load: {str(e)}')
|
||||
else:
|
||||
try:
|
||||
os.unlink(bootstrap_setreg_file)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to unlink bootstrap file {bootstrap_setreg_file}: {str(e)}')
|
||||
return 1
|
||||
else:
|
||||
json_data = {}
|
||||
json_data.update({"Amazon":{"AzCore":{"Bootstrap":{"project_path":project_path.as_posix()}}}})
|
||||
|
||||
with bootstrap_setreg_file.open('w') as s:
|
||||
s.write(json.dumps(json_data, indent=4))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def get_global_project() -> pathlib.Path or None:
|
||||
"""
|
||||
get what the current project set is
|
||||
:return: project_path or None on failure
|
||||
"""
|
||||
bootstrap_setreg_file = registration.get_o3de_registry_folder() / 'bootstrap.setreg'
|
||||
if not bootstrap_setreg_file.is_file():
|
||||
logger.error(f'Bootstrap.setreg file {bootstrap_setreg_file} does not exist.')
|
||||
return None
|
||||
|
||||
with bootstrap_setreg_file.open('r') as f:
|
||||
try:
|
||||
json_data = json.load(f)
|
||||
except Exception as e:
|
||||
logger.error(f'Bootstrap.setreg failed to load: {str(e)}')
|
||||
else:
|
||||
try:
|
||||
project_path = json_data["Amazon"]["AzCore"]["Bootstrap"]["project_path"]
|
||||
except Exception as e:
|
||||
logger.error(f'Bootstrap.setreg cannot find Amazon:AzCore:Bootstrap:project_path: {str(e)}')
|
||||
else:
|
||||
return pathlib.Path(project_path).resolve()
|
||||
return None
|
||||
|
||||
def _run_get_global_project(args: argparse) -> int:
|
||||
if args.override_home_folder:
|
||||
registration.override_home_folder = args.override_home_folder
|
||||
|
||||
project_path = get_global_project()
|
||||
if project_path:
|
||||
print(project_path.as_posix())
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
def _run_set_global_project(args: argparse) -> int:
|
||||
if args.override_home_folder:
|
||||
registration.override_home_folder = args.override_home_folder
|
||||
|
||||
return set_global_project(args.project_name,
|
||||
args.project_path)
|
||||
|
||||
|
||||
def add_args(parser, subparsers) -> None:
|
||||
"""
|
||||
add_args is called to add expected parser arguments and subparsers arguments to each command such that it can be
|
||||
invoked locally or aggregated by a central python file.
|
||||
Ex. Directly run from this file alone with: python global_project.py set_global_project --project-name TestProject
|
||||
OR
|
||||
o3de.py can aggregate commands by importing global_project, call add_args and
|
||||
execute: python o3de.py set_global_project --project-path C:/TestProject
|
||||
:param parser: the caller instantiates a parser and passes it in here
|
||||
:param subparsers: the caller instantiates subparsers and passes it in here
|
||||
"""
|
||||
get_global_project_subparser = subparsers.add_parser('get-global-project')
|
||||
get_global_project_subparser.add_argument('-ohf', '--override-home-folder', type=str, required=False,
|
||||
help='By default the home folder is the user folder, override it to this folder.')
|
||||
|
||||
get_global_project_subparser.set_defaults(func=_run_get_global_project)
|
||||
|
||||
set_global_project_subparser = subparsers.add_parser('set-global-project')
|
||||
group = set_global_project_subparser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('-pn', '--project-name', required=False,
|
||||
help='The name of the project. If supplied this will resolve the --project-path.')
|
||||
group.add_argument('-pp', '--project-path', required=False,
|
||||
help='The path to the project')
|
||||
|
||||
set_global_project_subparser.add_argument('-ohf', '--override-home-folder', type=str, required=False,
|
||||
help='By default the home folder is the user folder, override it to this folder.')
|
||||
|
||||
set_global_project_subparser.set_defaults(func=_run_set_global_project)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# parse the command line args
|
||||
the_parser = argparse.ArgumentParser()
|
||||
|
||||
# add subparsers
|
||||
the_subparsers = the_parser.add_subparsers(help='sub-command help')
|
||||
|
||||
# add args to the parser
|
||||
add_args(the_parser, the_subparsers)
|
||||
|
||||
# parse args
|
||||
the_args = the_parser.parse_args()
|
||||
|
||||
# run
|
||||
ret = the_args.func(the_args)
|
||||
|
||||
# return
|
||||
sys.exit(ret)
|
||||
Executable
+4381
File diff suppressed because it is too large
Load Diff
Executable
+259
@@ -0,0 +1,259 @@
|
||||
#
|
||||
# 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 os
|
||||
import pytest
|
||||
|
||||
from . import add_remove_gem
|
||||
|
||||
TEST_WITHOUT_NO_GEM_CONTENT = """
|
||||
# {BEGIN_LICENSE}
|
||||
# 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.
|
||||
# {END_LICENSE}
|
||||
|
||||
set(GEM_DEPENDENCIES
|
||||
)
|
||||
"""
|
||||
|
||||
TEST_WITHOUT_ONLY_GEM_CONTENT = """
|
||||
# {BEGIN_LICENSE}
|
||||
# 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.
|
||||
# {END_LICENSE}
|
||||
|
||||
set(GEM_DEPENDENCIES
|
||||
Gem::TestGem
|
||||
)
|
||||
"""
|
||||
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT = """
|
||||
# {BEGIN_LICENSE}
|
||||
# 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.
|
||||
# {END_LICENSE}
|
||||
|
||||
set(GEM_DEPENDENCIES
|
||||
Gem::ExistingGem
|
||||
)
|
||||
"""
|
||||
|
||||
TEST_WITH_ADDED_GEM_CONTENT = """
|
||||
# {BEGIN_LICENSE}
|
||||
# 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.
|
||||
# {END_LICENSE}
|
||||
|
||||
set(GEM_DEPENDENCIES
|
||||
Gem::TestGem
|
||||
Gem::ExistingGem
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"contents, gem, expected_result, runtime_present, expect_failure", [
|
||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITH_ADDED_GEM_CONTENT, True, False),
|
||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITH_ADDED_GEM_CONTENT, False, True),
|
||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "/TestGem", TEST_WITH_ADDED_GEM_CONTENT, True, True),
|
||||
pytest.param(TEST_WITHOUT_NO_GEM_CONTENT, "TestGem", TEST_WITHOUT_ONLY_GEM_CONTENT, True, False),
|
||||
]
|
||||
)
|
||||
def test_add_gem_dependency(tmpdir, contents, gem, expected_result, runtime_present, expect_failure):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
||||
|
||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
||||
if runtime_present:
|
||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
||||
os.unlink(runtime_dependencies_cmake_file)
|
||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
||||
s.write(contents)
|
||||
|
||||
result = add_remove_gem.add_gem_dependency(runtime_dependencies_cmake_file, gem)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"contents, gem, expected_result, runtime_present, expect_failure", [
|
||||
pytest.param(TEST_WITH_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, True, False),
|
||||
pytest.param(TEST_WITH_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, False, True),
|
||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, True, True)
|
||||
]
|
||||
)
|
||||
def test_remove_gem_dependency(tmpdir, contents, gem, expected_result, runtime_present, expect_failure):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
||||
|
||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
||||
if runtime_present:
|
||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
||||
os.unlink(runtime_dependencies_cmake_file)
|
||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
||||
s.write(contents)
|
||||
|
||||
result = add_remove_gem.remove_gem_dependency(runtime_dependencies_cmake_file, gem)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == expected_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("add,"
|
||||
" contents, gem, project, expected_result,"
|
||||
" runtime_present, tool_present,"
|
||||
" ask_for_runtime, ask_for_tool,"
|
||||
" expect_failure", [
|
||||
pytest.param(True,
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITH_ADDED_GEM_CONTENT,
|
||||
True, True,
|
||||
True, True,
|
||||
False),
|
||||
pytest.param(True,
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITH_ADDED_GEM_CONTENT,
|
||||
True, False,
|
||||
True, True,
|
||||
True),
|
||||
pytest.param(True,
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITH_ADDED_GEM_CONTENT,
|
||||
False, True,
|
||||
True, True,
|
||||
True),
|
||||
pytest.param(True,
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITH_ADDED_GEM_CONTENT,
|
||||
False, False,
|
||||
True, True,
|
||||
True),
|
||||
|
||||
pytest.param(False,
|
||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
||||
True, True,
|
||||
True, True,
|
||||
False),
|
||||
pytest.param(False,
|
||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
||||
True, False,
|
||||
True, True,
|
||||
True),
|
||||
pytest.param(False,
|
||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
||||
False, True,
|
||||
True, True,
|
||||
True),
|
||||
pytest.param(False,
|
||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
||||
False, False,
|
||||
True, True,
|
||||
True)
|
||||
]
|
||||
)
|
||||
def test_add_remove_gem(tmpdir,
|
||||
add,
|
||||
contents, gem, project,
|
||||
expected_result,
|
||||
runtime_present, tool_present,
|
||||
ask_for_runtime, ask_for_tool,
|
||||
expect_failure):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
||||
|
||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
||||
if runtime_present:
|
||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
||||
os.unlink(runtime_dependencies_cmake_file)
|
||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
||||
s.write(contents)
|
||||
|
||||
tool_dependencies_cmake_file = f'{dev_project_gem_code}/tool_dependencies.cmake'
|
||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
||||
|
||||
if tool_present:
|
||||
if os.path.isfile(tool_dependencies_cmake_file):
|
||||
os.unlink(tool_dependencies_cmake_file)
|
||||
with open(tool_dependencies_cmake_file, 'w') as s:
|
||||
s.write(contents)
|
||||
|
||||
project_folder = f'{dev_root}/TestProject'
|
||||
os.makedirs(project_folder, exist_ok=True)
|
||||
|
||||
gems_folder = f'{dev_root}/Gems'
|
||||
os.makedirs(gems_folder, exist_ok=True)
|
||||
|
||||
gem_folder = f'{gems_folder}/{gem}'
|
||||
os.makedirs(gem_folder, exist_ok=True)
|
||||
|
||||
result = add_remove_gem.add_remove_gem(add, dev_root, gem, project, ask_for_runtime, ask_for_tool)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
if runtime_present:
|
||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == expected_result
|
||||
if tool_present:
|
||||
with open(tool_dependencies_cmake_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == expected_result
|
||||
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#
|
||||
# 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 os
|
||||
import pytest
|
||||
|
||||
from . import current_project
|
||||
|
||||
TEST_BOOTSTRAP_CONTENT_1 = """
|
||||
project_path = Game1
|
||||
foo = bar
|
||||
key1 = value1
|
||||
key2 = value2
|
||||
assets = pc
|
||||
"""
|
||||
TEST_BOOTSTRAP_CONTENT_2 = """
|
||||
project_path=Game1
|
||||
foo = bar
|
||||
key1 = value1
|
||||
key2 = value2
|
||||
assets = pc
|
||||
"""
|
||||
TEST_BOOTSTRAP_CONTENT_3 = """
|
||||
project_path= Game1
|
||||
foo = bar
|
||||
key1 = value1
|
||||
key2 = value2
|
||||
assets = pc
|
||||
"""
|
||||
TEST_BOOTSTRAP_CONTENT_4 = """
|
||||
project_path =Game1
|
||||
foo = bar
|
||||
key1 = value1
|
||||
key2 = value2
|
||||
assets = pc
|
||||
"""
|
||||
TEST_BOOTSTRAP_CONTENT_5 = """
|
||||
project_path = Game1
|
||||
foo = bar
|
||||
key1 = value1
|
||||
key2 = value2
|
||||
assets = pc
|
||||
"""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"contents, expected_result", [
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, 'Game1'),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_2, 'Game1'),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_3, 'Game1'),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_4, 'Game1'),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_5, 'Game1'),
|
||||
]
|
||||
)
|
||||
def test_get_current_project(tmpdir, contents, expected_result):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
bootstrap_file = f'{dev_root}/bootstrap.cfg'
|
||||
if os.path.isfile(bootstrap_file):
|
||||
os.unlink(bootstrap_file)
|
||||
with open(bootstrap_file, 'a') as s:
|
||||
s.write(contents)
|
||||
|
||||
result = current_project.get_current_project(dev_root)
|
||||
assert expected_result == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"contents, project_to_set, expected_result", [
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, 'Test1', 0),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, ' Test2', 0),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, 'Test3 ', 0),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, '/Test4', 1),
|
||||
pytest.param(TEST_BOOTSTRAP_CONTENT_1, '=Test5', 1),
|
||||
]
|
||||
)
|
||||
def test_set_current_project(tmpdir, contents, project_to_set, expected_result):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
bootstrap_file = f'{dev_root}/bootstrap.cfg'
|
||||
if os.path.isfile(bootstrap_file):
|
||||
os.unlink(bootstrap_file)
|
||||
with open(bootstrap_file, 'a') as s:
|
||||
s.write(contents)
|
||||
|
||||
result = current_project.set_current_project(dev_root, project_to_set)
|
||||
assert expected_result == result
|
||||
|
||||
if result == 0:
|
||||
project_that_is_set = current_project.get_current_project(dev_root)
|
||||
print(project_that_is_set)
|
||||
print(project_to_set)
|
||||
assert project_to_set.strip() == project_that_is_set
|
||||
Executable
+748
@@ -0,0 +1,748 @@
|
||||
#
|
||||
# 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 os
|
||||
import pytest
|
||||
from . import engine_template
|
||||
|
||||
TEST_TEMPLATED_CONTENT_WITH_LICENSE = """\
|
||||
// {BEGIN_LICENSE}
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
// {END_LICENSE}
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace ${Name}
|
||||
{
|
||||
class ${Name}Requests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using ${Name}RequestsBus = AZ::EBus<${Name}Requests>;
|
||||
|
||||
} // namespace ${Name}
|
||||
|
||||
"""
|
||||
|
||||
TEST_TEMPLATED_CONTENT_WITHOUT_LICENSE = """\
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace ${Name}
|
||||
{
|
||||
class ${Name}Requests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using ${Name}RequestsBus = AZ::EBus<${Name}Requests>;
|
||||
|
||||
} // namespace ${Name}
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITHOUT_LICENSE = """\
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestTemplate
|
||||
{
|
||||
class TestTemplateRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestTemplateRequestsBus = AZ::EBus<TestTemplateRequests>;
|
||||
|
||||
} // namespace TestTemplate
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITH_LICENSE = """\
|
||||
// {BEGIN_LICENSE}
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
// {END_LICENSE}
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestTemplate
|
||||
{
|
||||
class TestTemplateRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestTemplateRequestsBus = AZ::EBus<TestTemplateRequests>;
|
||||
|
||||
} // namespace TestTemplate
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTPROJECT_TEMPLATE_CONTENT_WITHOUT_LICENSE = """\
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestProject
|
||||
{
|
||||
class TestProjectRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestProjectRequestsBus = AZ::EBus<TestProjectRequests>;
|
||||
|
||||
} // namespace TestProject
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTPROJECT_TEMPLATE_CONTENT_WITH_LICENSE = """\
|
||||
// {BEGIN_LICENSE}
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
// {END_LICENSE}
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestProject
|
||||
{
|
||||
class TestProjectRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestProjectRequestsBus = AZ::EBus<TestProjectRequests>;
|
||||
|
||||
} // namespace TestProject
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTGEM_TEMPLATE_CONTENT_WITHOUT_LICENSE = """\
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestGem
|
||||
{
|
||||
class TestGemRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestGemRequestsBus = AZ::EBus<TestGemRequests>;
|
||||
|
||||
} // namespace TestGem
|
||||
|
||||
"""
|
||||
|
||||
TEST_CONCRETE_TESTGEM_TEMPLATE_CONTENT_WITH_LICENSE = """\
|
||||
// {BEGIN_LICENSE}
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
// {END_LICENSE}
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
namespace TestGem
|
||||
{
|
||||
class TestGemRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put your public methods here
|
||||
};
|
||||
|
||||
using TestGemRequestsBus = AZ::EBus<TestGemRequests>;
|
||||
|
||||
} // namespace TestGem
|
||||
|
||||
"""
|
||||
|
||||
TEST_DEFAULTTEMPLATE_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "Templates/Default/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"outFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/Platform"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/${Name}"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
TEST_DEFAULTTEMPLATE_RESTRICTED_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "restricted/Salem/Templates/Default/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"outFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code/Include/Platform/Salem"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
TEST_DEFAULTPROJECT_TEMPLATE_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "Templates/DefaultProject/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"outFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/Platform"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/${Name}"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
TEST_DEFAULTPROJECT_TEMPLATE_RESTRICTED_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "restricted/Salem/Templates/DefaultProject/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"outFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code/Include/Platform/Salem"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
TEST_DEFAULTGEM_TEMPLATE_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "Templates/DefaultGem/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"outFile": "Code/Include/${Name}/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/Platform"
|
||||
},
|
||||
{
|
||||
"outDir": "Code/Include/${Name}"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
TEST_DEFAULTGEM_TEMPLATE_RESTRICTED_JSON_CONTENTS = """\
|
||||
{
|
||||
"inputPath": "restricted/Salem/Templates/DefaultGem/Template",
|
||||
"copyFiles": [
|
||||
{
|
||||
"inFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"outFile": "Code/Include/Platform/Salem/${Name}Bus.h",
|
||||
"isTemplated": true,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"createDirectories": [
|
||||
{
|
||||
"outDir": "Code/Include/Platform/Salem"
|
||||
}
|
||||
]
|
||||
}\
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"concrete_contents,"
|
||||
" templated_contents_with_license, templated_contents_without_license,"
|
||||
" keep_license_text, expect_failure,"
|
||||
" template_json_contents, restricted_template_json_contents", [
|
||||
pytest.param(TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITH_LICENSE,
|
||||
TEST_TEMPLATED_CONTENT_WITH_LICENSE, TEST_TEMPLATED_CONTENT_WITHOUT_LICENSE,
|
||||
True, False,
|
||||
TEST_DEFAULTTEMPLATE_JSON_CONTENTS, TEST_DEFAULTTEMPLATE_RESTRICTED_JSON_CONTENTS),
|
||||
pytest.param(TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITH_LICENSE,
|
||||
TEST_TEMPLATED_CONTENT_WITH_LICENSE, TEST_TEMPLATED_CONTENT_WITHOUT_LICENSE,
|
||||
False, False,
|
||||
TEST_DEFAULTTEMPLATE_JSON_CONTENTS, TEST_DEFAULTTEMPLATE_RESTRICTED_JSON_CONTENTS)
|
||||
]
|
||||
)
|
||||
def test_create_template(tmpdir,
|
||||
concrete_contents,
|
||||
templated_contents_with_license, templated_contents_without_license,
|
||||
keep_license_text, expect_failure,
|
||||
template_json_contents, restricted_template_json_contents):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
dev_gem_code_include_testgem = f'{dev_root}/TestTemplate/Code/Include/TestTemplate'
|
||||
os.makedirs(dev_gem_code_include_testgem, exist_ok=True)
|
||||
|
||||
gem_bus_file = f'{dev_gem_code_include_testgem}/TestTemplateBus.h'
|
||||
if os.path.isfile(gem_bus_file):
|
||||
os.unlink(gem_bus_file)
|
||||
with open(gem_bus_file, 'w') as s:
|
||||
s.write(concrete_contents)
|
||||
|
||||
dev_gem_code_include_platform_salem = f'{dev_root}/TestTemplate/Code/Include/Platform/Salem'
|
||||
os.makedirs(dev_gem_code_include_platform_salem, exist_ok=True)
|
||||
|
||||
restricted_gem_bus_file = f'{dev_gem_code_include_platform_salem}/TestTemplateBus.h'
|
||||
if os.path.isfile(restricted_gem_bus_file):
|
||||
os.unlink(restricted_gem_bus_file)
|
||||
with open(restricted_gem_bus_file, 'w') as s:
|
||||
s.write(concrete_contents)
|
||||
|
||||
template_folder = f'{dev_root}/Templates'
|
||||
os.makedirs(template_folder, exist_ok=True)
|
||||
|
||||
restricted_folder = f'{dev_root}/restricted'
|
||||
os.makedirs(restricted_folder, exist_ok=True)
|
||||
|
||||
result = engine_template.create_template(dev_root, 'TestTemplate', 'Default', keep_license_text=keep_license_text)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
new_template_folder = f'{template_folder}/Default'
|
||||
assert os.path.isdir(new_template_folder)
|
||||
new_template_json = f'{new_template_folder}/template.json'
|
||||
assert os.path.isfile(new_template_json)
|
||||
with open(new_template_json, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == template_json_contents
|
||||
|
||||
new_default_name_bus_file = f'{new_template_folder}/Template/Code/Include/' + '${Name}/${Name}Bus.h'
|
||||
assert os.path.isfile(new_default_name_bus_file)
|
||||
with open(new_default_name_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
if keep_license_text:
|
||||
assert s_data == templated_contents_with_license
|
||||
else:
|
||||
assert s_data == templated_contents_without_license
|
||||
|
||||
restricted_template_folder = f'{dev_root}/restricted/Salem/Templates'
|
||||
|
||||
new_restricted_template_folder = f'{restricted_template_folder}/Default'
|
||||
assert os.path.isdir(new_restricted_template_folder)
|
||||
new_restricted_template_json = f'{new_restricted_template_folder}/template.json'
|
||||
assert os.path.isfile(new_restricted_template_json)
|
||||
with open(new_restricted_template_json, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == restricted_template_json_contents
|
||||
|
||||
new_restricted_default_name_bus_file = f'{restricted_template_folder}' \
|
||||
f'/Default/Template/Code/Include/Platform/Salem/' + '${Name}Bus.h'
|
||||
assert os.path.isfile(new_restricted_default_name_bus_file)
|
||||
with open(new_restricted_default_name_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
if keep_license_text:
|
||||
assert s_data == templated_contents_with_license
|
||||
else:
|
||||
assert s_data == templated_contents_without_license
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"concrete_contents, templated_contents,"
|
||||
" keep_license_text, expect_failure,"
|
||||
" template_json_contents, restricted_template_json_contents", [
|
||||
pytest.param(TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITH_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
True, False,
|
||||
TEST_DEFAULTTEMPLATE_JSON_CONTENTS, TEST_DEFAULTTEMPLATE_RESTRICTED_JSON_CONTENTS),
|
||||
pytest.param(TEST_CONCRETE_TESTTEMPLATE_CONTENT_WITHOUT_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
False, False,
|
||||
TEST_DEFAULTTEMPLATE_JSON_CONTENTS, TEST_DEFAULTTEMPLATE_RESTRICTED_JSON_CONTENTS)
|
||||
]
|
||||
)
|
||||
def test_create_from_template(tmpdir,
|
||||
concrete_contents, templated_contents,
|
||||
keep_license_text, expect_failure,
|
||||
template_json_contents, restricted_template_json_contents):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
template_default_folder = f'{dev_root}/Templates/Default'
|
||||
os.makedirs(template_default_folder, exist_ok=True)
|
||||
|
||||
template_json = f'{template_default_folder}/template.json'
|
||||
if os.path.isfile(template_json):
|
||||
os.unlink(template_json)
|
||||
with open(template_json, 'w') as s:
|
||||
s.write(template_json_contents)
|
||||
|
||||
default_name_bus_dir = f'{template_default_folder}/Template/Code/Include/' + '${Name}'
|
||||
os.makedirs(default_name_bus_dir, exist_ok=True)
|
||||
|
||||
default_name_bus_file = f'{default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(default_name_bus_file):
|
||||
os.unlink(default_name_bus_file)
|
||||
with open(default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
restricted_template_default_folder = f'{dev_root}/restricted/Salem/Templates/Default'
|
||||
os.makedirs(restricted_template_default_folder, exist_ok=True)
|
||||
|
||||
restricted_template_json = f'{restricted_template_default_folder}/template.json'
|
||||
if os.path.isfile(restricted_template_json):
|
||||
os.unlink(restricted_template_json)
|
||||
with open(restricted_template_json, 'w') as s:
|
||||
s.write(restricted_template_json_contents)
|
||||
|
||||
restricted_default_name_bus_dir = f'{restricted_template_default_folder}/Template/Code/Include/Platform/Salem'
|
||||
os.makedirs(restricted_default_name_bus_dir, exist_ok=True)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(restricted_default_name_bus_file):
|
||||
os.unlink(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
result = engine_template.create_from_template(dev_root, 'TestTemplate', 'Default',
|
||||
keep_license_text=keep_license_text)
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
|
||||
test_folder = f'{dev_root}/TestTemplate'
|
||||
assert os.path.isdir(test_folder)
|
||||
|
||||
test_bus_file = f'{test_folder}/Code/Include/TestTemplate/TestTemplateBus.h'
|
||||
assert os.path.isfile(test_bus_file)
|
||||
with open(test_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
|
||||
restricted_test_bus_folder = f'{dev_root}/restricted/Salem/TestTemplate/Code/Include/Platform/Salem'
|
||||
assert os.path.isdir(restricted_test_bus_folder)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_test_bus_folder}/TestTemplateBus.h'
|
||||
assert os.path.isfile(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"concrete_contents, templated_contents,"
|
||||
" keep_license_text, expect_failure,"
|
||||
" template_json_contents, restricted_template_json_contents", [
|
||||
pytest.param(TEST_CONCRETE_TESTPROJECT_TEMPLATE_CONTENT_WITH_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
True, False,
|
||||
TEST_DEFAULTPROJECT_TEMPLATE_JSON_CONTENTS, TEST_DEFAULTPROJECT_TEMPLATE_RESTRICTED_JSON_CONTENTS),
|
||||
pytest.param(TEST_CONCRETE_TESTPROJECT_TEMPLATE_CONTENT_WITHOUT_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
False, False,
|
||||
TEST_DEFAULTPROJECT_TEMPLATE_JSON_CONTENTS, TEST_DEFAULTPROJECT_TEMPLATE_RESTRICTED_JSON_CONTENTS)
|
||||
]
|
||||
)
|
||||
def test_create_project(tmpdir,
|
||||
concrete_contents, templated_contents,
|
||||
keep_license_text, expect_failure,
|
||||
template_json_contents, restricted_template_json_contents):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
template_default_folder = f'{dev_root}/Templates/DefaultProject'
|
||||
os.makedirs(template_default_folder, exist_ok=True)
|
||||
|
||||
template_json = f'{template_default_folder}/template.json'
|
||||
if os.path.isfile(template_json):
|
||||
os.unlink(template_json)
|
||||
with open(template_json, 'w') as s:
|
||||
s.write(template_json_contents)
|
||||
|
||||
default_name_bus_dir = f'{template_default_folder}/Template/Code/Include/' + '${Name}'
|
||||
os.makedirs(default_name_bus_dir, exist_ok=True)
|
||||
|
||||
default_name_bus_file = f'{default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(default_name_bus_file):
|
||||
os.unlink(default_name_bus_file)
|
||||
with open(default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
restricted_template_default_folder = f'{dev_root}/restricted/Salem/Templates/DefaultProject'
|
||||
os.makedirs(restricted_template_default_folder, exist_ok=True)
|
||||
|
||||
restricted_template_json = f'{restricted_template_default_folder}/template.json'
|
||||
if os.path.isfile(restricted_template_json):
|
||||
os.unlink(restricted_template_json)
|
||||
with open(restricted_template_json, 'w') as s:
|
||||
s.write(restricted_template_json_contents)
|
||||
|
||||
restricted_default_name_bus_dir = f'{restricted_template_default_folder}/Template/Code/Include/Platform/Salem'
|
||||
os.makedirs(restricted_default_name_bus_dir, exist_ok=True)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(restricted_default_name_bus_file):
|
||||
os.unlink(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
result = engine_template.create_project(dev_root, 'TestProject', keep_license_text=keep_license_text)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
|
||||
test_project_folder = f'{dev_root}/TestProject'
|
||||
assert os.path.isdir(test_project_folder)
|
||||
|
||||
test_project_bus_file = f'{test_project_folder}/Code/Include/TestProject/TestProjectBus.h'
|
||||
assert os.path.isfile(test_project_bus_file)
|
||||
with open(test_project_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
|
||||
restricted_test_project_bus_folder = f'{dev_root}/restricted/Salem/TestProject/Code/Include/Platform/Salem'
|
||||
assert os.path.isdir(restricted_test_project_bus_folder)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_test_project_bus_folder}/TestProjectBus.h'
|
||||
assert os.path.isfile(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"concrete_contents, templated_contents,"
|
||||
" keep_license_text, expect_failure,"
|
||||
" template_json_contents, restricted_template_json_contents", [
|
||||
pytest.param(TEST_CONCRETE_TESTGEM_TEMPLATE_CONTENT_WITH_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
True, False,
|
||||
TEST_DEFAULTGEM_TEMPLATE_JSON_CONTENTS, TEST_DEFAULTGEM_TEMPLATE_RESTRICTED_JSON_CONTENTS),
|
||||
pytest.param(TEST_CONCRETE_TESTGEM_TEMPLATE_CONTENT_WITHOUT_LICENSE, TEST_TEMPLATED_CONTENT_WITH_LICENSE,
|
||||
False, False,
|
||||
TEST_DEFAULTGEM_TEMPLATE_JSON_CONTENTS, TEST_DEFAULTGEM_TEMPLATE_RESTRICTED_JSON_CONTENTS)
|
||||
]
|
||||
)
|
||||
def test_create_gem(tmpdir,
|
||||
concrete_contents, templated_contents,
|
||||
keep_license_text, expect_failure,
|
||||
template_json_contents, restricted_template_json_contents):
|
||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
||||
os.makedirs(dev_root, exist_ok=True)
|
||||
|
||||
template_default_folder = f'{dev_root}/Templates/DefaultGem'
|
||||
os.makedirs(template_default_folder, exist_ok=True)
|
||||
|
||||
template_json = f'{template_default_folder}/template.json'
|
||||
if os.path.isfile(template_json):
|
||||
os.unlink(template_json)
|
||||
with open(template_json, 'w') as s:
|
||||
s.write(template_json_contents)
|
||||
|
||||
default_name_bus_dir = f'{template_default_folder}/Template/Code/Include/' + '${Name}'
|
||||
os.makedirs(default_name_bus_dir, exist_ok=True)
|
||||
|
||||
default_name_bus_file = f'{default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(default_name_bus_file):
|
||||
os.unlink(default_name_bus_file)
|
||||
with open(default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
restricted_template_default_folder = f'{dev_root}/restricted/Salem/Templates/DefaultGem'
|
||||
os.makedirs(restricted_template_default_folder, exist_ok=True)
|
||||
|
||||
restricted_template_json = f'{restricted_template_default_folder}/template.json'
|
||||
if os.path.isfile(restricted_template_json):
|
||||
os.unlink(restricted_template_json)
|
||||
with open(restricted_template_json, 'w') as s:
|
||||
s.write(restricted_template_json_contents)
|
||||
|
||||
restricted_default_name_bus_dir = f'{restricted_template_default_folder}/Template/Code/Include/Platform/Salem'
|
||||
os.makedirs(restricted_default_name_bus_dir, exist_ok=True)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_default_name_bus_dir}/' + '${Name}Bus.h'
|
||||
if os.path.isfile(restricted_default_name_bus_file):
|
||||
os.unlink(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'w') as s:
|
||||
s.write(templated_contents)
|
||||
|
||||
result = engine_template.create_gem(dev_root, 'TestGem', keep_license_text=keep_license_text)
|
||||
|
||||
if expect_failure:
|
||||
assert result != 0
|
||||
else:
|
||||
assert result == 0
|
||||
|
||||
test_gem_folder = f'{dev_root}/Gems/TestGem'
|
||||
assert os.path.isdir(test_gem_folder)
|
||||
|
||||
test_gem_bus_file = f'{test_gem_folder}/Code/Include/TestGem/TestGemBus.h'
|
||||
assert os.path.isfile(test_gem_bus_file)
|
||||
with open(test_gem_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
|
||||
restricted_test_gem_bus_folder = f'{dev_root}/restricted/Salem/Gems/TestGem/Code/Include/Platform/Salem'
|
||||
assert os.path.isdir(restricted_test_gem_bus_folder)
|
||||
|
||||
restricted_default_name_bus_file = f'{restricted_test_gem_bus_folder}/TestGemBus.h'
|
||||
assert os.path.isfile(restricted_default_name_bus_file)
|
||||
with open(restricted_default_name_bus_file, 'r') as s:
|
||||
s_data = s.read()
|
||||
assert s_data == concrete_contents
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# 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 pytest
|
||||
|
||||
from . import utils
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected_result", [
|
||||
pytest.param('Game1', True),
|
||||
pytest.param('0Game1', False),
|
||||
pytest.param('the/Game1', False),
|
||||
pytest.param('', False),
|
||||
pytest.param('-test', False),
|
||||
pytest.param('test-', True),
|
||||
]
|
||||
)
|
||||
def test_validate_identifier(value, expected_result):
|
||||
result = utils.validate_identifier(value)
|
||||
assert result == expected_result
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected_result", [
|
||||
pytest.param('{018427ae-cd08-4ff1-ad3b-9b95256c17ca}', False),
|
||||
pytest.param('', False),
|
||||
pytest.param('{018427aecd084ff1ad3b9b95256c17ca}', False),
|
||||
pytest.param('018427ae-cd08-4ff1-ad3b-9b95256c17ca', True),
|
||||
pytest.param('018427aecd084ff1ad3b9b95256c17ca', False),
|
||||
pytest.param('018427aecd084ff1ad3b9', False),
|
||||
]
|
||||
)
|
||||
def test_validate_uuid4(value, expected_result):
|
||||
result = utils.validate_uuid4(value)
|
||||
assert result == expected_result
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# 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 file contains utility functions
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
|
||||
def validate_identifier(identifier: str) -> bool:
|
||||
"""
|
||||
Determine if the identifier supplied is valid.
|
||||
:param identifier: the name which needs to to checked
|
||||
:return: bool: if the identifier is valid or not
|
||||
"""
|
||||
if not identifier:
|
||||
return False
|
||||
elif len(identifier) > 64:
|
||||
return False
|
||||
elif not identifier[0].isalpha():
|
||||
return False
|
||||
else:
|
||||
for character in identifier:
|
||||
if not (character.isalnum() or character == '_' or character == '-'):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate_uuid4(uuid_string: str) -> bool:
|
||||
"""
|
||||
Determine if the uuid supplied is valid.
|
||||
:param uuid_string: the uuid which needs to to checked
|
||||
:return: bool: if the uuid is valid or not
|
||||
"""
|
||||
try:
|
||||
val = uuid.UUID(uuid_string, version=4)
|
||||
except ValueError:
|
||||
return False
|
||||
return str(val) == uuid_string
|
||||
Reference in New Issue
Block a user