Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
WIP - TODO - DNM
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed Dec 22, 2022
1 parent 6876fdc commit f2aa015
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
33 changes: 17 additions & 16 deletions gouttelette/cmd/refresh_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ def renderer(self, target_dir: str, next_version: str):

content = jinja2_renderer(
self.template_file,
target_dir=target_dir,
arguments=indent(arguments, 4),
documentation=documentation_to_string,
name=self.name,
Expand Down Expand Up @@ -946,6 +947,7 @@ def renderer(self, target_dir: str, next_version: str):

content = jinja2_renderer(
self.template_file,
target_dir=target_dir,
arguments=indent(arguments, 4),
documentation=documentation,
list_index=self.list_index(),
Expand Down Expand Up @@ -1232,7 +1234,7 @@ def generate_vmware_rest(args: Iterable):
module_list = []
for json_file in ["vcenter.json", "content.json", "appliance.json"]:
print("Generating modules from {}".format(json_file))
api_spec_file = args.target_dir / "api_specifications" / "7.0.2" / json_file
api_spec_file = args.target_dir / "gouttelette" / "api_specifications" / "7.0.2" / json_file
raw_content = api_spec_file.read_text()
swagger_file = SwaggerFile(raw_content)
resources = swagger_file.init_resources(swagger_file.paths.values())
Expand Down Expand Up @@ -1290,43 +1292,42 @@ def generate_vmware_rest(args: Iterable):

def main():
parser = argparse.ArgumentParser(
description=f"Build the {generator['name']} modules."
description=f"Build the modules."
)

parser.add_argument(
"--target-dir",
dest="target_dir",
type=pathlib.Path,
default=pathlib.Path(generator["default_path"]),
help=f"location of the target repository (default: {generator['default_path']})",
default=pathlib.Path("."),
help=f"location of the target repository (default: .)",
)
parser.add_argument(
"--next-version",
type=str,
default="TODO",
help="the next major version",
)
if generator.get("name") == "amazon_cloud_code_generator":
parser.add_argument(
"--schema-dir",
type=pathlib.Path,
default=pathlib.Path("gouttelette/api_specifications/"),
help="location where to store the collected schemas (default: ./gouttelette/api_specifications/amazon_cloud)",
)
parser.add_argument(
"--schema-dir",
type=pathlib.Path,
default=pathlib.Path("gouttelette/api_specifications/"),
help="location where to store the collected schemas (default: ./gouttelette/api_specifications/)",
)
args = parser.parse_args()

gouttelette_config = yaml.safe_load((args.target_dir / "gouttelette.yml").read_text())
print(gouttelette_config["generator"])
func = {"vmware_rest_code_generator": generate_vmware_rest,
"amazon_cloud_code_generator": generate_amazon_cloud}[generator["name"]]
"amazon_cloud_code_generator": generate_amazon_cloud}[gouttelette_config["generator"]]
func(args)

info = VersionInfo(generator["name"])
dev_md = args.target_dir / "dev.md"
dev_md.write_text(
(
"The modules are autogenerated by:\n"
"https://github.com/ansible-collections/gouttelette\n"
""
f"version: {info.version_string()}\n"
f"version: TODO\n"
)
)
dev_md = args.target_dir / "commit_message"
Expand All @@ -1337,7 +1338,7 @@ def main():
"The modules are autogenerated by:\n"
"https://github.com/ansible-collections/gouttelette\n"
""
f"version: {info.version_string()}\n"
f"version: TODO\n"
)
)

Expand Down
4 changes: 1 addition & 3 deletions gouttelette/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from functools import lru_cache


def jinja2_renderer(template_file: str, **kwargs: Dict[str, Any]) -> str:

target_dir = kwargs.get("target_dir", Path("."))
def jinja2_renderer(template_file: str, target_dir: Path, **kwargs: Dict[str, Any]) -> str:

templateLoader = jinja2.FileSystemLoader(str(target_dir / "gouttelette" / "templates"))
templateEnv = jinja2.Environment(loader=templateLoader)
Expand Down

0 comments on commit f2aa015

Please sign in to comment.